From 3cbd94eff53fab0938b7b1bb54661e9e27e53f05 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 31 Dec 2024 11:50:02 -0800 Subject: [PATCH 1/2] 2024: Document rustfmt overflow_delimited_expr --- .../rustfmt-overflow-delimited-expr.md | 86 ++++++++++++++++++- 1 file changed, 83 insertions(+), 3 deletions(-) diff --git a/src/rust-2024/rustfmt-overflow-delimited-expr.md b/src/rust-2024/rustfmt-overflow-delimited-expr.md index b428c275..0758450b 100644 --- a/src/rust-2024/rustfmt-overflow-delimited-expr.md +++ b/src/rust-2024/rustfmt-overflow-delimited-expr.md @@ -1,10 +1,90 @@ # Rustfmt: Combine all delimited exprs as last argument -This feature is not yet implemented. -More information may be found in . - ## Summary +* Some expressions as the last argument in a list will now overflow instead of indent. + ## 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 From a5ad897b3bd7feddf793de497cc048105e73668d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 31 Dec 2024 12:03:19 -0800 Subject: [PATCH 2/2] Reword overflow-delimited-expr summary --- src/rust-2024/rustfmt-overflow-delimited-expr.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rust-2024/rustfmt-overflow-delimited-expr.md b/src/rust-2024/rustfmt-overflow-delimited-expr.md index 0758450b..1d12e857 100644 --- a/src/rust-2024/rustfmt-overflow-delimited-expr.md +++ b/src/rust-2024/rustfmt-overflow-delimited-expr.md @@ -2,7 +2,7 @@ ## Summary -* Some expressions as the last argument in a list will now overflow instead of indent. +* Some expressions with multi-line final arguments will now format as a single line, with the final expression overflowing. ## Details