Skip to content

Commit

Permalink
Merge pull request #352 from ehuss/overflow-delimited-expr
Browse files Browse the repository at this point in the history
2024: Document rustfmt overflow_delimited_expr
  • Loading branch information
traviscross authored Dec 31, 2024
2 parents 7e0a7cc + a5ad897 commit d56e0f3
Showing 1 changed file with 83 additions and 3 deletions.
86 changes: 83 additions & 3 deletions src/rust-2024/rustfmt-overflow-delimited-expr.md
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

0 comments on commit d56e0f3

Please sign in to comment.