feat: implement 2024 Style Edition for expr overflows
This commit is contained in:
parent
0c6515cacc
commit
065258659d
@ -1,3 +1,4 @@
|
||||
error_on_line_overflow = true
|
||||
error_on_unformatted = true
|
||||
style_edition = "2024"
|
||||
overflow_delimited_expr = false
|
||||
|
@ -915,4 +915,36 @@ fn style_edition_config_file_trumps_edition_version_config() {
|
||||
let config = get_config(config_file, Some(options));
|
||||
assert_eq!(config.style_edition(), StyleEdition::Edition2021);
|
||||
}
|
||||
|
||||
#[nightly_only_test]
|
||||
#[test]
|
||||
fn correct_defaults_for_style_edition_loaded() {
|
||||
let mut options = GetOptsOptions::default();
|
||||
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]
|
||||
#[test]
|
||||
fn style_edition_defaults_overridden_from_config() {
|
||||
let options = GetOptsOptions::default();
|
||||
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);
|
||||
assert_eq!(config.overflow_delimited_expr(), false);
|
||||
}
|
||||
|
||||
#[nightly_only_test]
|
||||
#[test]
|
||||
fn style_edition_defaults_overridden_from_cli() {
|
||||
let mut options = GetOptsOptions::default();
|
||||
let config_file = Some(Path::new("tests/config/style-edition/just-style-edition"));
|
||||
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);
|
||||
assert_eq!(config.overflow_delimited_expr(), false);
|
||||
}
|
||||
}
|
||||
|
@ -828,7 +828,7 @@ fn test_dump_style_edition_2024_config() {
|
||||
remove_nested_parens = true
|
||||
combine_control_expr = true
|
||||
short_array_element_width_threshold = 10
|
||||
overflow_delimited_expr = false
|
||||
overflow_delimited_expr = true
|
||||
struct_field_align_threshold = 0
|
||||
enum_discrim_align_threshold = 0
|
||||
match_arm_blocks = true
|
||||
|
@ -627,7 +627,7 @@ macro_rules! config_option_with_style_edition_default {
|
||||
RemoveNestedParens, bool, _ => true;
|
||||
CombineControlExpr, bool, _ => true;
|
||||
ShortArrayElementWidthThreshold, usize, _ => 10;
|
||||
OverflowDelimitedExpr, bool, _ => false;
|
||||
OverflowDelimitedExpr, bool, Edition2024 => true, _ => false;
|
||||
StructFieldAlignThreshold, usize, _ => 0;
|
||||
EnumDiscrimAlignThreshold, usize, _ => 0;
|
||||
MatchArmBlocks, bool, _ => true;
|
||||
|
2
tests/config/style-edition/overrides/rustfmt.toml
Normal file
2
tests/config/style-edition/overrides/rustfmt.toml
Normal file
@ -0,0 +1,2 @@
|
||||
style_edition = "2024"
|
||||
overflow_delimited_expr = false
|
155
tests/source/configs/style_edition/overflow_delim_expr_2015.rs
Normal file
155
tests/source/configs/style_edition/overflow_delim_expr_2015.rs
Normal file
@ -0,0 +1,155 @@
|
||||
// rustfmt-style_edition: 2015
|
||||
|
||||
fn combine_blocklike() {
|
||||
do_thing(
|
||||
|param| {
|
||||
action();
|
||||
foo(param)
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
|param| {
|
||||
action();
|
||||
foo(param)
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
|
||||
// I'll be discussing the `action` with your para(m)legal counsel
|
||||
|param| {
|
||||
action();
|
||||
foo(param)
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(
|
||||
Bar {
|
||||
x: value,
|
||||
y: value2,
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
Bar {
|
||||
x: value,
|
||||
y: value2,
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
|
||||
// Let me tell you about that one time at the `Bar`
|
||||
Bar {
|
||||
x: value,
|
||||
y: value2,
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(
|
||||
&[
|
||||
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,
|
||||
|
||||
// Just admit it; my list is longer than can be folded on to one line
|
||||
&[
|
||||
value_with_longer_name,
|
||||
value2_with_longer_name,
|
||||
value3_with_longer_name,
|
||||
value4_with_longer_name,
|
||||
],
|
||||
);
|
||||
|
||||
do_thing(
|
||||
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,
|
||||
|
||||
// Just admit it; my list is longer than can be folded on to one line
|
||||
vec![
|
||||
value_with_longer_name,
|
||||
value2_with_longer_name,
|
||||
value3_with_longer_name,
|
||||
value4_with_longer_name,
|
||||
],
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
(
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
|param| {
|
||||
action();
|
||||
foo(param)
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
fn combine_struct_sample() {
|
||||
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,
|
||||
],
|
||||
)
|
||||
.launch();
|
||||
}
|
155
tests/source/configs/style_edition/overflow_delim_expr_2024.rs
Normal file
155
tests/source/configs/style_edition/overflow_delim_expr_2024.rs
Normal file
@ -0,0 +1,155 @@
|
||||
// rustfmt-style_edition: 2024
|
||||
|
||||
fn combine_blocklike() {
|
||||
do_thing(
|
||||
|param| {
|
||||
action();
|
||||
foo(param)
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
|param| {
|
||||
action();
|
||||
foo(param)
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
|
||||
// I'll be discussing the `action` with your para(m)legal counsel
|
||||
|param| {
|
||||
action();
|
||||
foo(param)
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(
|
||||
Bar {
|
||||
x: value,
|
||||
y: value2,
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
Bar {
|
||||
x: value,
|
||||
y: value2,
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
|
||||
// Let me tell you about that one time at the `Bar`
|
||||
Bar {
|
||||
x: value,
|
||||
y: value2,
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(
|
||||
&[
|
||||
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,
|
||||
|
||||
// Just admit it; my list is longer than can be folded on to one line
|
||||
&[
|
||||
value_with_longer_name,
|
||||
value2_with_longer_name,
|
||||
value3_with_longer_name,
|
||||
value4_with_longer_name,
|
||||
],
|
||||
);
|
||||
|
||||
do_thing(
|
||||
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,
|
||||
|
||||
// Just admit it; my list is longer than can be folded on to one line
|
||||
vec![
|
||||
value_with_longer_name,
|
||||
value2_with_longer_name,
|
||||
value3_with_longer_name,
|
||||
value4_with_longer_name,
|
||||
],
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
(
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
|param| {
|
||||
action();
|
||||
foo(param)
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
fn combine_struct_sample() {
|
||||
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,
|
||||
],
|
||||
)
|
||||
.launch();
|
||||
}
|
135
tests/target/configs/style_edition/overflow_delim_expr_2015.rs
Normal file
135
tests/target/configs/style_edition/overflow_delim_expr_2015.rs
Normal file
@ -0,0 +1,135 @@
|
||||
// rustfmt-style_edition: 2015
|
||||
|
||||
fn combine_blocklike() {
|
||||
do_thing(|param| {
|
||||
action();
|
||||
foo(param)
|
||||
});
|
||||
|
||||
do_thing(x, |param| {
|
||||
action();
|
||||
foo(param)
|
||||
});
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
// I'll be discussing the `action` with your para(m)legal counsel
|
||||
|param| {
|
||||
action();
|
||||
foo(param)
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(Bar {
|
||||
x: value,
|
||||
y: value2,
|
||||
});
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
Bar {
|
||||
x: value,
|
||||
y: value2,
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
// Let me tell you about that one time at the `Bar`
|
||||
Bar {
|
||||
x: value,
|
||||
y: value2,
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(&[
|
||||
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,
|
||||
// Just admit it; my list is longer than can be folded on to one line
|
||||
&[
|
||||
value_with_longer_name,
|
||||
value2_with_longer_name,
|
||||
value3_with_longer_name,
|
||||
value4_with_longer_name,
|
||||
],
|
||||
);
|
||||
|
||||
do_thing(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,
|
||||
// Just admit it; my list is longer than can be folded on to one line
|
||||
vec![
|
||||
value_with_longer_name,
|
||||
value2_with_longer_name,
|
||||
value3_with_longer_name,
|
||||
value4_with_longer_name,
|
||||
],
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
(1, 2, 3, |param| {
|
||||
action();
|
||||
foo(param)
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
fn combine_struct_sample() {
|
||||
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,
|
||||
],
|
||||
)
|
||||
.launch();
|
||||
}
|
120
tests/target/configs/style_edition/overflow_delim_expr_2024.rs
Normal file
120
tests/target/configs/style_edition/overflow_delim_expr_2024.rs
Normal file
@ -0,0 +1,120 @@
|
||||
// rustfmt-style_edition: 2024
|
||||
|
||||
fn combine_blocklike() {
|
||||
do_thing(|param| {
|
||||
action();
|
||||
foo(param)
|
||||
});
|
||||
|
||||
do_thing(x, |param| {
|
||||
action();
|
||||
foo(param)
|
||||
});
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
// I'll be discussing the `action` with your para(m)legal counsel
|
||||
|param| {
|
||||
action();
|
||||
foo(param)
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(Bar {
|
||||
x: value,
|
||||
y: value2,
|
||||
});
|
||||
|
||||
do_thing(x, Bar {
|
||||
x: value,
|
||||
y: value2,
|
||||
});
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
// Let me tell you about that one time at the `Bar`
|
||||
Bar {
|
||||
x: value,
|
||||
y: value2,
|
||||
},
|
||||
);
|
||||
|
||||
do_thing(&[
|
||||
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,
|
||||
// Just admit it; my list is longer than can be folded on to one line
|
||||
&[
|
||||
value_with_longer_name,
|
||||
value2_with_longer_name,
|
||||
value3_with_longer_name,
|
||||
value4_with_longer_name,
|
||||
],
|
||||
);
|
||||
|
||||
do_thing(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,
|
||||
// Just admit it; my list is longer than can be folded on to one line
|
||||
vec![
|
||||
value_with_longer_name,
|
||||
value2_with_longer_name,
|
||||
value3_with_longer_name,
|
||||
value4_with_longer_name,
|
||||
],
|
||||
);
|
||||
|
||||
do_thing(
|
||||
x,
|
||||
(1, 2, 3, |param| {
|
||||
action();
|
||||
foo(param)
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
fn combine_struct_sample() {
|
||||
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,
|
||||
])
|
||||
.launch();
|
||||
}
|
Loading…
Reference in New Issue
Block a user