Skip to content

Commit 0652586

Browse files
feat: implement 2024 Style Edition for expr overflows
1 parent 0c6515c commit 0652586

File tree

9 files changed

+602
-2
lines changed

9 files changed

+602
-2
lines changed

Diff for: rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
error_on_line_overflow = true
22
error_on_unformatted = true
33
style_edition = "2024"
4+
overflow_delimited_expr = false

Diff for: src/bin/main.rs

+32
Original file line numberDiff line numberDiff line change
@@ -915,4 +915,36 @@ mod test {
915915
let config = get_config(config_file, Some(options));
916916
assert_eq!(config.style_edition(), StyleEdition::Edition2021);
917917
}
918+
919+
#[nightly_only_test]
920+
#[test]
921+
fn correct_defaults_for_style_edition_loaded() {
922+
let mut options = GetOptsOptions::default();
923+
options.style_edition = Some(StyleEdition::Edition2024);
924+
let config = get_config(None, Some(options));
925+
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
926+
assert_eq!(config.overflow_delimited_expr(), true);
927+
}
928+
929+
#[nightly_only_test]
930+
#[test]
931+
fn style_edition_defaults_overridden_from_config() {
932+
let options = GetOptsOptions::default();
933+
let config_file = Some(Path::new("tests/config/style-edition/overrides"));
934+
let config = get_config(config_file, Some(options));
935+
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
936+
assert_eq!(config.overflow_delimited_expr(), false);
937+
}
938+
939+
#[nightly_only_test]
940+
#[test]
941+
fn style_edition_defaults_overridden_from_cli() {
942+
let mut options = GetOptsOptions::default();
943+
let config_file = Some(Path::new("tests/config/style-edition/just-style-edition"));
944+
options.inline_config =
945+
HashMap::from([("overflow_delimited_expr".to_owned(), "false".to_owned())]);
946+
let config = get_config(config_file, Some(options));
947+
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
948+
assert_eq!(config.overflow_delimited_expr(), false);
949+
}
918950
}

Diff for: src/config/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ binop_separator = "Front"
828828
remove_nested_parens = true
829829
combine_control_expr = true
830830
short_array_element_width_threshold = 10
831-
overflow_delimited_expr = false
831+
overflow_delimited_expr = true
832832
struct_field_align_threshold = 0
833833
enum_discrim_align_threshold = 0
834834
match_arm_blocks = true

Diff for: src/config/options.rs

+1-1
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, _ => false;
630+
OverflowDelimitedExpr, bool, Edition2024 => true, _ => false;
631631
StructFieldAlignThreshold, usize, _ => 0;
632632
EnumDiscrimAlignThreshold, usize, _ => 0;
633633
MatchArmBlocks, bool, _ => true;

Diff for: tests/config/style-edition/overrides/rustfmt.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
style_edition = "2024"
2+
overflow_delimited_expr = false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// rustfmt-style_edition: 2015
2+
3+
fn combine_blocklike() {
4+
do_thing(
5+
|param| {
6+
action();
7+
foo(param)
8+
},
9+
);
10+
11+
do_thing(
12+
x,
13+
|param| {
14+
action();
15+
foo(param)
16+
},
17+
);
18+
19+
do_thing(
20+
x,
21+
22+
// I'll be discussing the `action` with your para(m)legal counsel
23+
|param| {
24+
action();
25+
foo(param)
26+
},
27+
);
28+
29+
do_thing(
30+
Bar {
31+
x: value,
32+
y: value2,
33+
},
34+
);
35+
36+
do_thing(
37+
x,
38+
Bar {
39+
x: value,
40+
y: value2,
41+
},
42+
);
43+
44+
do_thing(
45+
x,
46+
47+
// Let me tell you about that one time at the `Bar`
48+
Bar {
49+
x: value,
50+
y: value2,
51+
},
52+
);
53+
54+
do_thing(
55+
&[
56+
value_with_longer_name,
57+
value2_with_longer_name,
58+
value3_with_longer_name,
59+
value4_with_longer_name,
60+
],
61+
);
62+
63+
do_thing(
64+
x,
65+
&[
66+
value_with_longer_name,
67+
value2_with_longer_name,
68+
value3_with_longer_name,
69+
value4_with_longer_name,
70+
],
71+
);
72+
73+
do_thing(
74+
x,
75+
76+
// Just admit it; my list is longer than can be folded on to one line
77+
&[
78+
value_with_longer_name,
79+
value2_with_longer_name,
80+
value3_with_longer_name,
81+
value4_with_longer_name,
82+
],
83+
);
84+
85+
do_thing(
86+
vec![
87+
value_with_longer_name,
88+
value2_with_longer_name,
89+
value3_with_longer_name,
90+
value4_with_longer_name,
91+
],
92+
);
93+
94+
do_thing(
95+
x,
96+
vec![
97+
value_with_longer_name,
98+
value2_with_longer_name,
99+
value3_with_longer_name,
100+
value4_with_longer_name,
101+
],
102+
);
103+
104+
do_thing(
105+
x,
106+
107+
// Just admit it; my list is longer than can be folded on to one line
108+
vec![
109+
value_with_longer_name,
110+
value2_with_longer_name,
111+
value3_with_longer_name,
112+
value4_with_longer_name,
113+
],
114+
);
115+
116+
do_thing(
117+
x,
118+
(
119+
1,
120+
2,
121+
3,
122+
|param| {
123+
action();
124+
foo(param)
125+
},
126+
),
127+
);
128+
}
129+
130+
fn combine_struct_sample() {
131+
let identity = verify(
132+
&ctx,
133+
VerifyLogin {
134+
type_: LoginType::Username,
135+
username: args.username.clone(),
136+
password: Some(args.password.clone()),
137+
domain: None,
138+
},
139+
)?;
140+
}
141+
142+
fn combine_macro_sample() {
143+
rocket::ignite()
144+
.mount(
145+
"/",
146+
routes![
147+
http::auth::login,
148+
http::auth::logout,
149+
http::cors::options,
150+
http::action::dance,
151+
http::action::sleep,
152+
],
153+
)
154+
.launch();
155+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// rustfmt-style_edition: 2024
2+
3+
fn combine_blocklike() {
4+
do_thing(
5+
|param| {
6+
action();
7+
foo(param)
8+
},
9+
);
10+
11+
do_thing(
12+
x,
13+
|param| {
14+
action();
15+
foo(param)
16+
},
17+
);
18+
19+
do_thing(
20+
x,
21+
22+
// I'll be discussing the `action` with your para(m)legal counsel
23+
|param| {
24+
action();
25+
foo(param)
26+
},
27+
);
28+
29+
do_thing(
30+
Bar {
31+
x: value,
32+
y: value2,
33+
},
34+
);
35+
36+
do_thing(
37+
x,
38+
Bar {
39+
x: value,
40+
y: value2,
41+
},
42+
);
43+
44+
do_thing(
45+
x,
46+
47+
// Let me tell you about that one time at the `Bar`
48+
Bar {
49+
x: value,
50+
y: value2,
51+
},
52+
);
53+
54+
do_thing(
55+
&[
56+
value_with_longer_name,
57+
value2_with_longer_name,
58+
value3_with_longer_name,
59+
value4_with_longer_name,
60+
],
61+
);
62+
63+
do_thing(
64+
x,
65+
&[
66+
value_with_longer_name,
67+
value2_with_longer_name,
68+
value3_with_longer_name,
69+
value4_with_longer_name,
70+
],
71+
);
72+
73+
do_thing(
74+
x,
75+
76+
// Just admit it; my list is longer than can be folded on to one line
77+
&[
78+
value_with_longer_name,
79+
value2_with_longer_name,
80+
value3_with_longer_name,
81+
value4_with_longer_name,
82+
],
83+
);
84+
85+
do_thing(
86+
vec![
87+
value_with_longer_name,
88+
value2_with_longer_name,
89+
value3_with_longer_name,
90+
value4_with_longer_name,
91+
],
92+
);
93+
94+
do_thing(
95+
x,
96+
vec![
97+
value_with_longer_name,
98+
value2_with_longer_name,
99+
value3_with_longer_name,
100+
value4_with_longer_name,
101+
],
102+
);
103+
104+
do_thing(
105+
x,
106+
107+
// Just admit it; my list is longer than can be folded on to one line
108+
vec![
109+
value_with_longer_name,
110+
value2_with_longer_name,
111+
value3_with_longer_name,
112+
value4_with_longer_name,
113+
],
114+
);
115+
116+
do_thing(
117+
x,
118+
(
119+
1,
120+
2,
121+
3,
122+
|param| {
123+
action();
124+
foo(param)
125+
},
126+
),
127+
);
128+
}
129+
130+
fn combine_struct_sample() {
131+
let identity = verify(
132+
&ctx,
133+
VerifyLogin {
134+
type_: LoginType::Username,
135+
username: args.username.clone(),
136+
password: Some(args.password.clone()),
137+
domain: None,
138+
},
139+
)?;
140+
}
141+
142+
fn combine_macro_sample() {
143+
rocket::ignite()
144+
.mount(
145+
"/",
146+
routes![
147+
http::auth::login,
148+
http::auth::logout,
149+
http::cors::options,
150+
http::action::dance,
151+
http::action::sleep,
152+
],
153+
)
154+
.launch();
155+
}

0 commit comments

Comments
 (0)