-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #341 from joshtriplett/rustfmt-assignment-operator…
…-rhs-indentation 2024: Assignment operator RHS indentation
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/rust-2024/rustfmt-assignment-operator-rhs-indentation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Rustfmt: Assignment operator RHS indentation | ||
|
||
## Summary | ||
|
||
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. | ||
|
||
## Details | ||
|
||
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: | ||
|
||
```rust,ignore | ||
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 = Some(ExtraInfo { | ||
parent, | ||
count: count as u16, | ||
children: children.into_boxed_slice(), | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
In the 2024 Edition, `rustfmt` now indents the right-hand side relative to the last line of the left-hand side: | ||
|
||
```rust,ignore | ||
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 = Some(ExtraInfo { | ||
parent, | ||
count: count as u16, | ||
children: children.into_boxed_slice(), | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
## Migration | ||
|
||
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. | ||
|
||
[Style edition]: rustfmt-style-edition.md |