Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fdc22dc

Browse files
jhprattehuss
authored andcommittedFeb 1, 2025
Rollup merge of #136312 - compiler-errors:overflow_delimited_expr-2024, r=ytmimi
Disable `overflow_delimited_expr` in edition 2024 This reverts the style guide changes and sets the default to "false" in rustfmt for style edition 2024. r? `@ytmimi` cc `@rust-lang/style` `@rust-lang/rustfmt`
1 parent 2fa9d47 commit fdc22dc

File tree

6 files changed

+58
-89
lines changed

6 files changed

+58
-89
lines changed
 

‎src/doc/style-guide/src/editions.md

-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ For a full history of changes in the Rust 2024 style edition, see the git
3636
history of the style guide. Notable changes in the Rust 2024 style edition
3737
include:
3838

39-
- [#114764](https://github.com/rust-lang/rust/pull/114764) As the last member
40-
of a delimited expression, delimited expressions are generally combinable,
41-
regardless of the number of members. Previously only applied with exactly
42-
one member (except for closures with explicit blocks).
4339
- Miscellaneous `rustfmt` bugfixes.
4440
- Use version-sort (sort `x8`, `x16`, `x32`, `x64`, `x128` in that order).
4541
- Change "ASCIIbetical" sort to Unicode-aware "non-lowercase before lowercase".

‎src/doc/style-guide/src/expressions.md

+7-48
Original file line numberDiff line numberDiff line change
@@ -818,11 +818,11 @@ E.g., `&&Some(foo)` matches, `Foo(4, Bar)` does not.
818818

819819
## Combinable expressions
820820

821-
When the last argument in a function call is formatted across
822-
multiple-lines, format the outer call as if it were a single-line call,
821+
Where a function call has a single argument, and that argument is formatted
822+
across multiple-lines, format the outer call as if it were a single-line call,
823823
if the result fits. Apply the same combining behaviour to any similar
824824
expressions which have multi-line, block-indented lists of sub-expressions
825-
delimited by parentheses, brackets, or braces. E.g.,
825+
delimited by parentheses (e.g., macros or tuple struct literals). E.g.,
826826

827827
```rust
828828
foo(bar(
@@ -848,61 +848,20 @@ let arr = [combinable(
848848
an_expr,
849849
another_expr,
850850
)];
851-
852-
let x = Thing(an_expr, another_expr, match cond {
853-
A => 1,
854-
B => 2,
855-
});
856-
857-
let x = format!("Stuff: {}", [
858-
an_expr,
859-
another_expr,
860-
]);
861-
862-
let x = func(an_expr, another_expr, SomeStruct {
863-
field: this_is_long,
864-
another_field: 123,
865-
});
866851
```
867852

868853
Apply this behavior recursively.
869854

870-
If the last argument is a multi-line closure with an explicit block,
871-
only apply the combining behavior if there are no other closure arguments.
855+
For a function with multiple arguments, if the last argument is a multi-line
856+
closure with an explicit block, there are no other closure arguments, and all
857+
the arguments and the first line of the closure fit on the first line, use the
858+
same combining behavior:
872859

873860
```rust
874-
// Combinable
875861
foo(first_arg, x, |param| {
876862
action();
877863
foo(param)
878864
})
879-
// Not combinable, because the closure is not the last argument
880-
foo(
881-
first_arg,
882-
|param| {
883-
action();
884-
foo(param)
885-
},
886-
whatever,
887-
)
888-
// Not combinable, because the first line of the closure does not fit
889-
foo(
890-
first_arg,
891-
x,
892-
move |very_long_param_causing_line_to_overflow| -> Bar {
893-
action();
894-
foo(param)
895-
},
896-
)
897-
// Not combinable, because there is more than one closure argument
898-
foo(
899-
first_arg,
900-
|x| x.bar(),
901-
|param| {
902-
action();
903-
foo(param)
904-
},
905-
)
906865
```
907866

908867
## Ranges

‎src/tools/rustfmt/src/bin/main.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,6 @@ mod test {
817817
options.inline_config = HashMap::from([("version".to_owned(), "Two".to_owned())]);
818818
let config = get_config(None, Some(options));
819819
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
820-
assert_eq!(config.overflow_delimited_expr(), true);
821820
}
822821

823822
#[nightly_only_test]
@@ -827,7 +826,6 @@ mod test {
827826
let config_file = Some(Path::new("tests/config/style-edition/just-version"));
828827
let config = get_config(config_file, Some(options));
829828
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
830-
assert_eq!(config.overflow_delimited_expr(), true);
831829
}
832830

833831
#[nightly_only_test]
@@ -872,7 +870,6 @@ mod test {
872870
]);
873871
let config = get_config(None, Some(options));
874872
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
875-
assert_eq!(config.overflow_delimited_expr(), true);
876873
}
877874

878875
#[nightly_only_test]
@@ -938,7 +935,6 @@ mod test {
938935
options.style_edition = Some(StyleEdition::Edition2024);
939936
let config = get_config(None, Some(options));
940937
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
941-
assert_eq!(config.overflow_delimited_expr(), true);
942938
}
943939

944940
#[nightly_only_test]
@@ -948,6 +944,8 @@ mod test {
948944
let config_file = Some(Path::new("tests/config/style-edition/overrides"));
949945
let config = get_config(config_file, Some(options));
950946
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
947+
// FIXME: this test doesn't really exercise anything, since
948+
// `overflow_delimited_expr` is disabled by default in edition 2024.
951949
assert_eq!(config.overflow_delimited_expr(), false);
952950
}
953951

@@ -959,7 +957,8 @@ mod test {
959957
options.inline_config =
960958
HashMap::from([("overflow_delimited_expr".to_owned(), "false".to_owned())]);
961959
let config = get_config(config_file, Some(options));
962-
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
960+
// FIXME: this test doesn't really exercise anything, since
961+
// `overflow_delimited_expr` is disabled by default in edition 2024.
963962
assert_eq!(config.overflow_delimited_expr(), false);
964963
}
965964
}

‎src/tools/rustfmt/src/config/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ binop_separator = "Front"
848848
remove_nested_parens = true
849849
combine_control_expr = true
850850
short_array_element_width_threshold = 10
851-
overflow_delimited_expr = true
851+
overflow_delimited_expr = false
852852
struct_field_align_threshold = 0
853853
enum_discrim_align_threshold = 0
854854
match_arm_blocks = true

‎src/tools/rustfmt/src/config/options.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ config_option_with_style_edition_default!(
627627
RemoveNestedParens, bool, _ => true;
628628
CombineControlExpr, bool, _ => true;
629629
ShortArrayElementWidthThreshold, usize, _ => 10;
630-
OverflowDelimitedExpr, bool, Edition2024 => true, _ => false;
630+
OverflowDelimitedExpr, bool, _ => false;
631631
StructFieldAlignThreshold, usize, _ => 0;
632632
EnumDiscrimAlignThreshold, usize, _ => 0;
633633
MatchArmBlocks, bool, _ => true;
@@ -644,7 +644,7 @@ config_option_with_style_edition_default!(
644644
BlankLinesLowerBound, usize, _ => 0;
645645
EditionConfig, Edition, _ => Edition::Edition2015;
646646
StyleEditionConfig, StyleEdition,
647-
Edition2024 => StyleEdition::Edition2024, _ => StyleEdition::Edition2015;
647+
Edition2024 => StyleEdition::Edition2024, _ => StyleEdition::Edition2015;
648648
VersionConfig, Version, Edition2024 => Version::Two, _ => Version::One;
649649
InlineAttributeWidth, usize, _ => 0;
650650
FormatGeneratedFiles, bool, _ => true;

‎src/tools/rustfmt/tests/target/configs/style_edition/overflow_delim_expr_2024.rs

+44-29
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ fn combine_blocklike() {
2525
y: value2,
2626
});
2727

28-
do_thing(x, Bar {
29-
x: value,
30-
y: value2,
31-
});
28+
do_thing(
29+
x,
30+
Bar {
31+
x: value,
32+
y: value2,
33+
},
34+
);
3235

3336
do_thing(
3437
x,
@@ -46,12 +49,15 @@ fn combine_blocklike() {
4649
value4_with_longer_name,
4750
]);
4851

49-
do_thing(x, &[
50-
value_with_longer_name,
51-
value2_with_longer_name,
52-
value3_with_longer_name,
53-
value4_with_longer_name,
54-
]);
52+
do_thing(
53+
x,
54+
&[
55+
value_with_longer_name,
56+
value2_with_longer_name,
57+
value3_with_longer_name,
58+
value4_with_longer_name,
59+
],
60+
);
5561

5662
do_thing(
5763
x,
@@ -71,12 +77,15 @@ fn combine_blocklike() {
7177
value4_with_longer_name,
7278
]);
7379

74-
do_thing(x, vec![
75-
value_with_longer_name,
76-
value2_with_longer_name,
77-
value3_with_longer_name,
78-
value4_with_longer_name,
79-
]);
80+
do_thing(
81+
x,
82+
vec![
83+
value_with_longer_name,
84+
value2_with_longer_name,
85+
value3_with_longer_name,
86+
value4_with_longer_name,
87+
],
88+
);
8089

8190
do_thing(
8291
x,
@@ -99,22 +108,28 @@ fn combine_blocklike() {
99108
}
100109

101110
fn combine_struct_sample() {
102-
let identity = verify(&ctx, VerifyLogin {
103-
type_: LoginType::Username,
104-
username: args.username.clone(),
105-
password: Some(args.password.clone()),
106-
domain: None,
107-
})?;
111+
let identity = verify(
112+
&ctx,
113+
VerifyLogin {
114+
type_: LoginType::Username,
115+
username: args.username.clone(),
116+
password: Some(args.password.clone()),
117+
domain: None,
118+
},
119+
)?;
108120
}
109121

110122
fn combine_macro_sample() {
111123
rocket::ignite()
112-
.mount("/", routes![
113-
http::auth::login,
114-
http::auth::logout,
115-
http::cors::options,
116-
http::action::dance,
117-
http::action::sleep,
118-
])
124+
.mount(
125+
"/",
126+
routes![
127+
http::auth::login,
128+
http::auth::logout,
129+
http::cors::options,
130+
http::action::dance,
131+
http::action::sleep,
132+
],
133+
)
119134
.launch();
120135
}

0 commit comments

Comments
 (0)
Failed to load comments.