Rollup merge of #132369 - joshtriplett:style-guide-binop-heuristic-assignment-only, r=calebcartwright

style-guide: Only use the new binop heuristic for assignments

This avoids pathological cases where chains of binops get progressively
deeper.
This commit is contained in:
Guillaume Gomez 2024-11-02 03:08:50 +08:00 committed by GitHub
commit 348d28052b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 11 deletions

View File

@ -40,8 +40,9 @@ include:
of a delimited expression, delimited expressions are generally combinable, of a delimited expression, delimited expressions are generally combinable,
regardless of the number of members. Previously only applied with exactly regardless of the number of members. Previously only applied with exactly
one member (except for closures with explicit blocks). one member (except for closures with explicit blocks).
- When line-breaking a binary operator, if the first operand spans multiple - When line-breaking an assignment operator, if the left-hand side spans
lines, use the base indentation of the last line. multiple lines, use the base indentation of the last line of the left-hand
side to indent the right-hand side.
- Miscellaneous `rustfmt` bugfixes. - Miscellaneous `rustfmt` bugfixes.
- Use version-sort (sort `x8`, `x16`, `x32`, `x64`, `x128` in that order). - Use version-sort (sort `x8`, `x16`, `x32`, `x64`, `x128` in that order).
- Change "ASCIIbetical" sort to Unicode-aware "non-lowercase before lowercase". - Change "ASCIIbetical" sort to Unicode-aware "non-lowercase before lowercase".

View File

@ -328,9 +328,9 @@ foo_bar
Prefer line-breaking at an assignment operator (either `=` or `+=`, etc.) rather Prefer line-breaking at an assignment operator (either `=` or `+=`, etc.) rather
than at other binary operators. than at other binary operators.
If line-breaking at a binary operator (including assignment operators) where the If line-breaking an assignment operator where the left-hand side spans multiple
first operand spans multiple lines, use the base indentation of the *last* lines, use the base indentation of the *last* line of the left-hand side, and
line of the first operand, and indent relative to that: indent the right-hand side relative to that:
```rust ```rust
impl SomeType { impl SomeType {
@ -341,12 +341,6 @@ impl SomeType {
.extra_info = .extra_info =
long_long_long_long_long_long_long_long_long_long_long_long_long_long_long; 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] self.array[array_index as usize]
.as_mut() .as_mut()
.expect("thing must exist") .expect("thing must exist")