-
Notifications
You must be signed in to change notification settings - Fork 122
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 #352 from ehuss/overflow-delimited-expr
2024: Document rustfmt overflow_delimited_expr
- Loading branch information
Showing
1 changed file
with
83 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,90 @@ | ||
# Rustfmt: Combine all delimited exprs as last argument | ||
|
||
This feature is not yet implemented. | ||
More information may be found in <https://github.com/rust-lang/rust/pull/114764>. | ||
|
||
## Summary | ||
|
||
* Some expressions with multi-line final arguments will now format as a single line, with the final expression overflowing. | ||
|
||
## Details | ||
|
||
When structs, slices, arrays, and block/array-like macros are used as the last argument in an expression list, they are now allowed to overflow (like blocks/closures) instead of being indented on a new line. | ||
|
||
```rust,ignore | ||
// Edition 2021 | ||
fn example() { | ||
foo(ctx, |param| { | ||
action(); | ||
foo(param) | ||
}); | ||
foo( | ||
ctx, | ||
Bar { | ||
x: value, | ||
y: value2, | ||
}, | ||
); | ||
foo( | ||
ctx, | ||
&[ | ||
MAROON_TOMATOES, | ||
PURPLE_POTATOES, | ||
ORGANE_ORANGES, | ||
GREEN_PEARS, | ||
RED_APPLES, | ||
], | ||
); | ||
foo( | ||
ctx, | ||
vec![ | ||
MAROON_TOMATOES, | ||
PURPLE_POTATOES, | ||
ORGANE_ORANGES, | ||
GREEN_PEARS, | ||
RED_APPLES, | ||
], | ||
); | ||
} | ||
``` | ||
|
||
This now formats as the following in the 2024 style edition: | ||
|
||
```rust,ignore | ||
// Edition 2024 | ||
fn example() { | ||
foo(ctx, |param| { | ||
action(); | ||
foo(param) | ||
}); | ||
foo(ctx, Bar { | ||
x: value, | ||
y: value2, | ||
}); | ||
foo(ctx, &[ | ||
MAROON_TOMATOES, | ||
PURPLE_POTATOES, | ||
ORGANE_ORANGES, | ||
GREEN_PEARS, | ||
RED_APPLES, | ||
]); | ||
foo(ctx, vec![ | ||
MAROON_TOMATOES, | ||
PURPLE_POTATOES, | ||
ORGANE_ORANGES, | ||
GREEN_PEARS, | ||
RED_APPLES, | ||
]); | ||
} | ||
``` | ||
|
||
## 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 |