Skip to content

Commit 4efbefa

Browse files
authored
Merge pull request #341 from joshtriplett/rustfmt-assignment-operator-rhs-indentation
2024: Assignment operator RHS indentation
2 parents 7a957fa + fe5d589 commit 4efbefa

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
- [Rustdoc nested `include!` change](rust-2024/rustdoc-nested-includes.md)
6767
- [Rustfmt](rust-2024/rustfmt.md)
6868
- [Rustfmt: Style edition](rust-2024/rustfmt-style-edition.md)
69+
- [Rustfmt: Assignment operator RHS indentation](rust-2024/rustfmt-assignment-operator-rhs-indentation.md)
6970
- [Rustfmt: Combine all delimited exprs as last argument](rust-2024/rustfmt-overflow-delimited-expr.md)
7071
- [Rustfmt: Single-line `where` clauses](rust-2024/rustfmt-single-line-where-clauses.md)
7172
- [Rustfmt: Raw identifier sorting](rust-2024/rustfmt-raw-identifier-sorting.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Rustfmt: Assignment operator RHS indentation
2+
3+
## Summary
4+
5+
In the 2024 Edition, `rustfmt` now indents the right-hand side of an assignment operator relative to the last line of the left-hand side, providing a clearer delineation and making it easier to notice the assignment operator.
6+
7+
## Details
8+
9+
In Rust 2021 and before, if an assignment operator has a multi-line left-hand side, the indentation of the right-hand side will visually run together with the left-hand side:
10+
11+
```rust,ignore
12+
impl SomeType {
13+
fn method(&mut self) {
14+
self.array[array_index as usize]
15+
.as_mut()
16+
.expect("thing must exist")
17+
.extra_info =
18+
long_long_long_long_long_long_long_long_long_long_long_long_long_long_long;
19+
20+
self.array[array_index as usize]
21+
.as_mut()
22+
.expect("thing must exist")
23+
.extra_info = Some(ExtraInfo {
24+
parent,
25+
count: count as u16,
26+
children: children.into_boxed_slice(),
27+
});
28+
}
29+
}
30+
```
31+
32+
In the 2024 Edition, `rustfmt` now indents the right-hand side relative to the last line of the left-hand side:
33+
34+
```rust,ignore
35+
impl SomeType {
36+
fn method(&mut self) {
37+
self.array[array_index as usize]
38+
.as_mut()
39+
.expect("thing must exist")
40+
.extra_info =
41+
long_long_long_long_long_long_long_long_long_long_long_long_long_long_long;
42+
43+
self.array[array_index as usize]
44+
.as_mut()
45+
.expect("thing must exist")
46+
.extra_info = Some(ExtraInfo {
47+
parent,
48+
count: count as u16,
49+
children: children.into_boxed_slice(),
50+
});
51+
}
52+
}
53+
```
54+
55+
## Migration
56+
57+
The change can be applied automatically by running `cargo fmt` or `rustfmt` with the 2024 Edition. See the [Style edition] chapter for more information on migrating and how style editions work.
58+
59+
[Style edition]: rustfmt-style-edition.md

0 commit comments

Comments
 (0)