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`
This commit is contained in:
parent
2fa9d47dfe
commit
fdc22dc54c
6 changed files with 58 additions and 89 deletions
|
|
@ -36,10 +36,6 @@ For a full history of changes in the Rust 2024 style edition, see the git
|
|||
history of the style guide. Notable changes in the Rust 2024 style edition
|
||||
include:
|
||||
|
||||
- [#114764](https://github.com/rust-lang/rust/pull/114764) As the last member
|
||||
of a delimited expression, delimited expressions are generally combinable,
|
||||
regardless of the number of members. Previously only applied with exactly
|
||||
one member (except for closures with explicit blocks).
|
||||
- Miscellaneous `rustfmt` bugfixes.
|
||||
- Use version-sort (sort `x8`, `x16`, `x32`, `x64`, `x128` in that order).
|
||||
- Change "ASCIIbetical" sort to Unicode-aware "non-lowercase before lowercase".
|
||||
|
|
|
|||
|
|
@ -818,11 +818,11 @@ E.g., `&&Some(foo)` matches, `Foo(4, Bar)` does not.
|
|||
|
||||
## Combinable expressions
|
||||
|
||||
When the last argument in a function call is formatted across
|
||||
multiple-lines, format the outer call as if it were a single-line call,
|
||||
Where a function call has a single argument, and that argument is formatted
|
||||
across multiple-lines, format the outer call as if it were a single-line call,
|
||||
if the result fits. Apply the same combining behaviour to any similar
|
||||
expressions which have multi-line, block-indented lists of sub-expressions
|
||||
delimited by parentheses, brackets, or braces. E.g.,
|
||||
delimited by parentheses (e.g., macros or tuple struct literals). E.g.,
|
||||
|
||||
```rust
|
||||
foo(bar(
|
||||
|
|
@ -848,61 +848,20 @@ let arr = [combinable(
|
|||
an_expr,
|
||||
another_expr,
|
||||
)];
|
||||
|
||||
let x = Thing(an_expr, another_expr, match cond {
|
||||
A => 1,
|
||||
B => 2,
|
||||
});
|
||||
|
||||
let x = format!("Stuff: {}", [
|
||||
an_expr,
|
||||
another_expr,
|
||||
]);
|
||||
|
||||
let x = func(an_expr, another_expr, SomeStruct {
|
||||
field: this_is_long,
|
||||
another_field: 123,
|
||||
});
|
||||
```
|
||||
|
||||
Apply this behavior recursively.
|
||||
|
||||
If the last argument is a multi-line closure with an explicit block,
|
||||
only apply the combining behavior if there are no other closure arguments.
|
||||
For a function with multiple arguments, if the last argument is a multi-line
|
||||
closure with an explicit block, there are no other closure arguments, and all
|
||||
the arguments and the first line of the closure fit on the first line, use the
|
||||
same combining behavior:
|
||||
|
||||
```rust
|
||||
// Combinable
|
||||
foo(first_arg, x, |param| {
|
||||
action();
|
||||
foo(param)
|
||||
})
|
||||
// Not combinable, because the closure is not the last argument
|
||||
foo(
|
||||
first_arg,
|
||||
|param| {
|
||||
action();
|
||||
foo(param)
|
||||
},
|
||||
whatever,
|
||||
)
|
||||
// Not combinable, because the first line of the closure does not fit
|
||||
foo(
|
||||
first_arg,
|
||||
x,
|
||||
move |very_long_param_causing_line_to_overflow| -> Bar {
|
||||
action();
|
||||
foo(param)
|
||||
},
|
||||
)
|
||||
// Not combinable, because there is more than one closure argument
|
||||
foo(
|
||||
first_arg,
|
||||
|x| x.bar(),
|
||||
|param| {
|
||||
action();
|
||||
foo(param)
|
||||
},
|
||||
)
|
||||
```
|
||||
|
||||
## Ranges
|
||||
|
|
|
|||
|
|
@ -817,7 +817,6 @@ mod test {
|
|||
options.inline_config = HashMap::from([("version".to_owned(), "Two".to_owned())]);
|
||||
let config = get_config(None, Some(options));
|
||||
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
|
||||
assert_eq!(config.overflow_delimited_expr(), true);
|
||||
}
|
||||
|
||||
#[nightly_only_test]
|
||||
|
|
@ -827,7 +826,6 @@ mod test {
|
|||
let config_file = Some(Path::new("tests/config/style-edition/just-version"));
|
||||
let config = get_config(config_file, Some(options));
|
||||
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
|
||||
assert_eq!(config.overflow_delimited_expr(), true);
|
||||
}
|
||||
|
||||
#[nightly_only_test]
|
||||
|
|
@ -872,7 +870,6 @@ mod test {
|
|||
]);
|
||||
let config = get_config(None, Some(options));
|
||||
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
|
||||
assert_eq!(config.overflow_delimited_expr(), true);
|
||||
}
|
||||
|
||||
#[nightly_only_test]
|
||||
|
|
@ -938,7 +935,6 @@ mod test {
|
|||
options.style_edition = Some(StyleEdition::Edition2024);
|
||||
let config = get_config(None, Some(options));
|
||||
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
|
||||
assert_eq!(config.overflow_delimited_expr(), true);
|
||||
}
|
||||
|
||||
#[nightly_only_test]
|
||||
|
|
@ -948,6 +944,8 @@ mod test {
|
|||
let config_file = Some(Path::new("tests/config/style-edition/overrides"));
|
||||
let config = get_config(config_file, Some(options));
|
||||
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
|
||||
// FIXME: this test doesn't really exercise anything, since
|
||||
// `overflow_delimited_expr` is disabled by default in edition 2024.
|
||||
assert_eq!(config.overflow_delimited_expr(), false);
|
||||
}
|
||||
|
||||
|
|
@ -959,7 +957,8 @@ mod test {
|
|||
options.inline_config =
|
||||
HashMap::from([("overflow_delimited_expr".to_owned(), "false".to_owned())]);
|
||||
let config = get_config(config_file, Some(options));
|
||||
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
|
||||
// FIXME: this test doesn't really exercise anything, since
|
||||
// `overflow_delimited_expr` is disabled by default in edition 2024.
|
||||
assert_eq!(config.overflow_delimited_expr(), false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -848,7 +848,7 @@ binop_separator = "Front"
|
|||
remove_nested_parens = true
|
||||
combine_control_expr = true
|
||||
short_array_element_width_threshold = 10
|
||||
overflow_delimited_expr = true
|
||||
overflow_delimited_expr = false
|
||||
struct_field_align_threshold = 0
|
||||
enum_discrim_align_threshold = 0
|
||||
match_arm_blocks = true
|
||||
|
|
|
|||
|
|
@ -627,7 +627,7 @@ config_option_with_style_edition_default!(
|
|||
RemoveNestedParens, bool, _ => true;
|
||||
CombineControlExpr, bool, _ => true;
|
||||
ShortArrayElementWidthThreshold, usize, _ => 10;
|
||||
OverflowDelimitedExpr, bool, Edition2024 => true, _ => false;
|
||||
OverflowDelimitedExpr, bool, _ => false;
|
||||
StructFieldAlignThreshold, usize, _ => 0;
|
||||
EnumDiscrimAlignThreshold, usize, _ => 0;
|
||||
MatchArmBlocks, bool, _ => true;
|
||||
|
|
@ -644,7 +644,7 @@ config_option_with_style_edition_default!(
|
|||
BlankLinesLowerBound, usize, _ => 0;
|
||||
EditionConfig, Edition, _ => Edition::Edition2015;
|
||||
StyleEditionConfig, StyleEdition,
|
||||
Edition2024 => StyleEdition::Edition2024, _ => StyleEdition::Edition2015;
|
||||
Edition2024 => StyleEdition::Edition2024, _ => StyleEdition::Edition2015;
|
||||
VersionConfig, Version, Edition2024 => Version::Two, _ => Version::One;
|
||||
InlineAttributeWidth, usize, _ => 0;
|
||||
FormatGeneratedFiles, bool, _ => true;
|
||||
|
|
|
|||
|
|
@ -25,10 +25,13 @@ fn combine_blocklike() {
|
|||
y: value2,
|
||||
});
|
||||
|
||||
do_thing(x, Bar {
|
||||
x: value,
|
||||
y: value2,
|
||||
});
|
||||
do_thing(
|
||||
x,
|
||||
Bar {
|
||||
x: value,
|
||||
y: value2,
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
|
|
@ -46,12 +49,15 @@ fn combine_blocklike() {
|
|||
value4_with_longer_name,
|
||||
]);
|
||||
|
||||
do_thing(x, &[
|
||||
value_with_longer_name,
|
||||
value2_with_longer_name,
|
||||
value3_with_longer_name,
|
||||
value4_with_longer_name,
|
||||
]);
|
||||
do_thing(
|
||||
x,
|
||||
&[
|
||||
value_with_longer_name,
|
||||
value2_with_longer_name,
|
||||
value3_with_longer_name,
|
||||
value4_with_longer_name,
|
||||
],
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
|
|
@ -71,12 +77,15 @@ fn combine_blocklike() {
|
|||
value4_with_longer_name,
|
||||
]);
|
||||
|
||||
do_thing(x, vec![
|
||||
value_with_longer_name,
|
||||
value2_with_longer_name,
|
||||
value3_with_longer_name,
|
||||
value4_with_longer_name,
|
||||
]);
|
||||
do_thing(
|
||||
x,
|
||||
vec![
|
||||
value_with_longer_name,
|
||||
value2_with_longer_name,
|
||||
value3_with_longer_name,
|
||||
value4_with_longer_name,
|
||||
],
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
|
|
@ -99,22 +108,28 @@ fn combine_blocklike() {
|
|||
}
|
||||
|
||||
fn combine_struct_sample() {
|
||||
let identity = verify(&ctx, VerifyLogin {
|
||||
type_: LoginType::Username,
|
||||
username: args.username.clone(),
|
||||
password: Some(args.password.clone()),
|
||||
domain: None,
|
||||
})?;
|
||||
let identity = verify(
|
||||
&ctx,
|
||||
VerifyLogin {
|
||||
type_: LoginType::Username,
|
||||
username: args.username.clone(),
|
||||
password: Some(args.password.clone()),
|
||||
domain: None,
|
||||
},
|
||||
)?;
|
||||
}
|
||||
|
||||
fn combine_macro_sample() {
|
||||
rocket::ignite()
|
||||
.mount("/", routes![
|
||||
http::auth::login,
|
||||
http::auth::logout,
|
||||
http::cors::options,
|
||||
http::action::dance,
|
||||
http::action::sleep,
|
||||
])
|
||||
.mount(
|
||||
"/",
|
||||
routes![
|
||||
http::auth::login,
|
||||
http::auth::logout,
|
||||
http::cors::options,
|
||||
http::action::dance,
|
||||
http::action::sleep,
|
||||
],
|
||||
)
|
||||
.launch();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue