From a6ba04ae6a9f76a0513a3084dfd2a4ebab4b381f Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 31 Dec 2024 08:50:04 -0800 Subject: [PATCH 1/2] Revert "Rollup merge of #132369 - joshtriplett:style-guide-binop-heuristic-assignment-only, r=calebcartwright" This reverts commit 348d28052b1717f152b04725492c256c3409a361, reversing changes made to 526c67f37be44688345aec14f7b1c5926f4a59a7. --- src/doc/style-guide/src/editions.md | 5 ++--- src/doc/style-guide/src/expressions.md | 12 +++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/doc/style-guide/src/editions.md b/src/doc/style-guide/src/editions.md index d9dba641495ab..74e873e35ff38 100644 --- a/src/doc/style-guide/src/editions.md +++ b/src/doc/style-guide/src/editions.md @@ -40,9 +40,8 @@ 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 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. +- When line-breaking a binary operator, if the first operand spans multiple + lines, use the base indentation of the last line. - 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 4f63a632030b4..3bb0ee6d5ff6c 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 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: +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: ```rust impl SomeType { @@ -341,6 +341,12 @@ 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") From 7a46c7b1123fa3643e9bda0c9ffbfc5dee7e4dfb Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 31 Dec 2024 08:50:28 -0800 Subject: [PATCH 2/2] Revert "Rollup merge of #119838 - joshtriplett:style-guide-binop-indent, r=compiler-errors" This reverts commit 36287830a22897fc05f33f615291df7efe8cad20, reversing changes made to 31026b7fe3e510a646eddeda838d1f0859f892e7. --- src/doc/style-guide/src/editions.md | 2 -- src/doc/style-guide/src/expressions.md | 31 -------------------------- 2 files changed, 33 deletions(-) diff --git a/src/doc/style-guide/src/editions.md b/src/doc/style-guide/src/editions.md index 74e873e35ff38..9d593f8081025 100644 --- a/src/doc/style-guide/src/editions.md +++ b/src/doc/style-guide/src/editions.md @@ -40,8 +40,6 @@ 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. - 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..171a24cd89d73 100644 --- a/src/doc/style-guide/src/expressions.md +++ b/src/doc/style-guide/src/expressions.md @@ -328,37 +328,6 @@ 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: - -```rust -impl SomeType { - fn method(&mut self) { - 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") - .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 = Some(ExtraInfo { - parent, - count: count as u16, - children: children.into_boxed_slice(), - }); - } -} -``` - ### Casts (`as`) Format `as` casts like a binary operator. In particular, always include spaces