From d7e6074083231aa8ccf7f299626fc83d59f78ee4 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 30 Oct 2024 13:16:43 -0700 Subject: [PATCH] style-guide: Only use the new binop heuristic for assignments This avoids pathological cases where chains of binops get progressively deeper. --- src/doc/style-guide/src/editions.md | 5 +++-- src/doc/style-guide/src/expressions.md | 12 +++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/doc/style-guide/src/editions.md b/src/doc/style-guide/src/editions.md index 74e873e35ff38..d9dba641495ab 100644 --- a/src/doc/style-guide/src/editions.md +++ b/src/doc/style-guide/src/editions.md @@ -40,8 +40,9 @@ include: of a delimited expression, delimited expressions are generally combinable, regardless of the number of members. Previously only applied with exactly one member (except for closures with explicit blocks). -- When line-breaking a binary operator, if the first operand spans multiple - lines, use the base indentation of the last line. +- When line-breaking an assignment operator, if the left-hand side spans + multiple lines, use the base indentation of the last line of the left-hand + side to indent the right-hand side. - Miscellaneous `rustfmt` bugfixes. - Use version-sort (sort `x8`, `x16`, `x32`, `x64`, `x128` in that order). - Change "ASCIIbetical" sort to Unicode-aware "non-lowercase before lowercase". diff --git a/src/doc/style-guide/src/expressions.md b/src/doc/style-guide/src/expressions.md index 3bb0ee6d5ff6c..4f63a632030b4 100644 --- a/src/doc/style-guide/src/expressions.md +++ b/src/doc/style-guide/src/expressions.md @@ -328,9 +328,9 @@ foo_bar Prefer line-breaking at an assignment operator (either `=` or `+=`, etc.) rather than at other binary operators. -If line-breaking at a binary operator (including assignment operators) where the -first operand spans multiple lines, use the base indentation of the *last* -line of the first operand, and indent relative to that: +If line-breaking an assignment operator where the left-hand side spans multiple +lines, use the base indentation of the *last* line of the left-hand side, and +indent the right-hand side relative to that: ```rust impl SomeType { @@ -341,12 +341,6 @@ impl SomeType { .extra_info = long_long_long_long_long_long_long_long_long_long_long_long_long_long_long; - self.array[array_index as usize] - .as_mut() - .expect("thing must exist") - .extra_info - + long_long_long_long_long_long_long_long_long_long_long_long_long_long_long; - self.array[array_index as usize] .as_mut() .expect("thing must exist")