Skip to content

Commit 6df3af5

Browse files
committed
style-guide: When breaking binops handle multi-line first operand better
Use the indentation of the *last* line of the first operand, not the first. Fixes rust-lang/style-team#189
1 parent 0a89233 commit 6df3af5

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/doc/style-guide/src/editions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ For a full history of changes in the Rust 2024 style edition, see the git
3636
history of the style guide. Notable changes in the Rust 2024 style edition
3737
include:
3838

39+
- When line-breaking a binary operator, if the first operand spans multiple
40+
lines, use the base indentation of the last line.
3941
- Miscellaneous `rustfmt` bugfixes.
4042

4143
## Rust 2015/2018/2021 style edition

src/doc/style-guide/src/expressions.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,37 @@ foo_bar
328328
Prefer line-breaking at an assignment operator (either `=` or `+=`, etc.) rather
329329
than at other binary operators.
330330

331+
If line-breaking a binary operator (including assignment operators) where the
332+
first operand spans multiple lines, use the base indentation of the *last*
333+
line of the first , and indent relative to that:
334+
335+
```rust
336+
impl SomeType {
337+
fn method(&mut self) {
338+
self.array[array_index as usize]
339+
.as_mut()
340+
.expect("thing must exist")
341+
.extra_info =
342+
long_long_long_long_long_long_long_long_long_long_long_long_long_long_long;
343+
344+
self.array[array_index as usize]
345+
.as_mut()
346+
.expect("thing must exist")
347+
.extra_info
348+
+ long_long_long_long_long_long_long_long_long_long_long_long_long_long_long;
349+
350+
self.array[array_index as usize]
351+
.as_mut()
352+
.expect("thing must exist")
353+
.extra_info = Some(ExtraInfo {
354+
parent,
355+
count: count as u16,
356+
children: children.into_boxed_slice(),
357+
});
358+
}
359+
}
360+
```
361+
331362
### Casts (`as`)
332363

333364
Format `as` casts like a binary operator. In particular, always include spaces

0 commit comments

Comments
 (0)