Skip to content

Commit d56e0f3

Browse files
authored
Merge pull request #352 from ehuss/overflow-delimited-expr
2024: Document rustfmt overflow_delimited_expr
2 parents 7e0a7cc + a5ad897 commit d56e0f3

File tree

1 file changed

+83
-3
lines changed

1 file changed

+83
-3
lines changed
Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,90 @@
11
# Rustfmt: Combine all delimited exprs as last argument
22

3-
This feature is not yet implemented.
4-
More information may be found in <https://github.com/rust-lang/rust/pull/114764>.
5-
63
## Summary
74

5+
* Some expressions with multi-line final arguments will now format as a single line, with the final expression overflowing.
6+
87
## Details
98

9+
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.
10+
11+
```rust,ignore
12+
// Edition 2021
13+
14+
fn example() {
15+
foo(ctx, |param| {
16+
action();
17+
foo(param)
18+
});
19+
20+
foo(
21+
ctx,
22+
Bar {
23+
x: value,
24+
y: value2,
25+
},
26+
);
27+
28+
foo(
29+
ctx,
30+
&[
31+
MAROON_TOMATOES,
32+
PURPLE_POTATOES,
33+
ORGANE_ORANGES,
34+
GREEN_PEARS,
35+
RED_APPLES,
36+
],
37+
);
38+
39+
foo(
40+
ctx,
41+
vec![
42+
MAROON_TOMATOES,
43+
PURPLE_POTATOES,
44+
ORGANE_ORANGES,
45+
GREEN_PEARS,
46+
RED_APPLES,
47+
],
48+
);
49+
}
50+
```
51+
52+
This now formats as the following in the 2024 style edition:
53+
54+
```rust,ignore
55+
// Edition 2024
56+
57+
fn example() {
58+
foo(ctx, |param| {
59+
action();
60+
foo(param)
61+
});
62+
63+
foo(ctx, Bar {
64+
x: value,
65+
y: value2,
66+
});
67+
68+
foo(ctx, &[
69+
MAROON_TOMATOES,
70+
PURPLE_POTATOES,
71+
ORGANE_ORANGES,
72+
GREEN_PEARS,
73+
RED_APPLES,
74+
]);
75+
76+
foo(ctx, vec![
77+
MAROON_TOMATOES,
78+
PURPLE_POTATOES,
79+
ORGANE_ORANGES,
80+
GREEN_PEARS,
81+
RED_APPLES,
82+
]);
83+
}
84+
```
85+
1086
## Migration
87+
88+
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.
89+
90+
[Style edition]: rustfmt-style-edition.md

0 commit comments

Comments
 (0)