Skip to content

Commit 46acb34

Browse files
committed
defer version sorted modules until style-edition 2027
We didn't get this change synced with r-l/rust before the release of the 2024 edition, so trying to do a subtree-sync with this mod sorting logic for `style-edition=2024` would be a breaking change.
1 parent 0332da0 commit 46acb34

File tree

7 files changed

+211
-23
lines changed

7 files changed

+211
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
### Changed
2222
- Stabilize `style_edition=2024` and stabilize the `style_edition` command line option [#6431](https://github.com/rust-lang/rustfmt/pull/6431) [rust-lang/rust#134929](https://github.com/rust-lang/rust/pull/134929)
23-
- Apply version sorting to module declarations when using `style_edition=2024` [#6368](https://github.com/rust-lang/rustfmt/pull/6368)
23+
- Apply version sorting to module declarations when using `style_edition=2027` [#6368](https://github.com/rust-lang/rustfmt/pull/6368) and [#6594](https://github.com/rust-lang/rustfmt/pull/6594)
2424
- When users set the deprecated `version` config, rustfmt now gives a hint about which equivalent `style_edition` they should use [#6361](https://github.com/rust-lang/rustfmt/pull/6361)
2525
- Correct version chunk splitting in the internal version sort algorithm [#6407](https://github.com/rust-lang/rustfmt/pull/6407)
2626
- Extend support for single line let-chain formatting to include cases where the left hand side operand is a literal, in alignment with finalized style rules as part of let-chain stabilization [#6492](https://github.com/rust-lang/rustfmt/pull/6492)

src/reorder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn compare_items(a: &ast::Item, b: &ast::Item, context: &RewriteContext<'_>) ->
2929
let style_edition = context.config.style_edition();
3030
match (&a.kind, &b.kind) {
3131
(&ast::ItemKind::Mod(_, a_ident, _), &ast::ItemKind::Mod(_, b_ident, _)) => {
32-
if style_edition <= StyleEdition::Edition2021 {
32+
if style_edition <= StyleEdition::Edition2024 {
3333
a_ident.as_str().cmp(b_ident.as_str())
3434
} else {
3535
version_sort(a_ident.as_str(), b_ident.as_str())
@@ -43,7 +43,7 @@ fn compare_items(a: &ast::Item, b: &ast::Item, context: &RewriteContext<'_>) ->
4343
// ^^^ Comparing this.
4444
let a_orig_name = a_name.unwrap_or(a_ident.name);
4545
let b_orig_name = b_name.unwrap_or(b_ident.name);
46-
let result = if style_edition <= StyleEdition::Edition2021 {
46+
let result = if style_edition <= StyleEdition::Edition2024 {
4747
a_orig_name.as_str().cmp(b_orig_name.as_str())
4848
} else {
4949
version_sort(a_orig_name.as_str(), b_orig_name.as_str())
@@ -58,7 +58,7 @@ fn compare_items(a: &ast::Item, b: &ast::Item, context: &RewriteContext<'_>) ->
5858
(Some(..), None) => Ordering::Greater,
5959
(None, Some(..)) => Ordering::Less,
6060
(None, None) => Ordering::Equal,
61-
(Some(..), Some(..)) if style_edition <= StyleEdition::Edition2021 => {
61+
(Some(..), Some(..)) if style_edition <= StyleEdition::Edition2024 => {
6262
a_ident.as_str().cmp(b_ident.as_str())
6363
}
6464
(Some(..), Some(..)) => version_sort(a_ident.as_str(), b_ident.as_str()),
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// rustfmt-style_edition: 2027
2+
// rustfmt-reorder_modules: false
3+
4+
mod x86;
5+
mod v0s;
6+
mod v001;
7+
mod x87;
8+
mod zyxw;
9+
mod A2;
10+
mod ZYXW;
11+
mod w5s009t;
12+
mod u8;
13+
mod x86_128;
14+
mod _ZYXW;
15+
mod ZY_XW;
16+
mod a1;
17+
mod v01;
18+
mod v0u;
19+
mod x86_64;
20+
mod ua;
21+
mod x86_32;
22+
mod v9;
23+
mod v010;
24+
mod u_zzz;
25+
mod v0;
26+
mod v00;
27+
mod v009;
28+
mod w005s09t;
29+
mod u32;
30+
mod v1;
31+
mod v00t;
32+
mod v09;
33+
mod u256;
34+
mod ZY_XW;
35+
mod _abcd;
36+
mod ABCD;
37+
mod Z_YXW;
38+
mod u64;
39+
mod abcd;
40+
mod ZYXW_;
41+
mod u16;
42+
mod uz;
43+
mod v10;
44+
mod x64;
45+
mod u128;
46+
mod usize;
47+
mod v000;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// rustfmt-style_edition: 2027
2+
// rustfmt-reorder_modules: true
3+
4+
mod x86;
5+
mod v0s;
6+
mod v001;
7+
mod x87;
8+
mod zyxw;
9+
mod A2;
10+
mod ZYXW;
11+
mod w5s009t;
12+
mod u8;
13+
mod x86_128;
14+
mod _ZYXW;
15+
mod ZY_XW;
16+
mod a1;
17+
mod v01;
18+
mod v0u;
19+
mod x86_64;
20+
mod ua;
21+
mod x86_32;
22+
mod v9;
23+
mod v010;
24+
mod u_zzz;
25+
mod v0;
26+
mod v00;
27+
mod v009;
28+
mod w005s09t;
29+
mod u32;
30+
mod v1;
31+
mod v00t;
32+
mod v09;
33+
mod u256;
34+
mod ZY_XW;
35+
mod _abcd;
36+
mod ABCD;
37+
mod Z_YXW;
38+
mod u64;
39+
mod abcd;
40+
mod ZYXW_;
41+
mod u16;
42+
mod uz;
43+
mod v10;
44+
mod x64;
45+
mod u128;
46+
mod usize;
47+
mod v000;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// rustfmt-style_edition: 2027
2+
// rustfmt-reorder_modules: false
3+
4+
mod x86;
5+
mod v0s;
6+
mod v001;
7+
mod x87;
8+
mod zyxw;
9+
mod A2;
10+
mod ZYXW;
11+
mod w5s009t;
12+
mod u8;
13+
mod x86_128;
14+
mod _ZYXW;
15+
mod ZY_XW;
16+
mod a1;
17+
mod v01;
18+
mod v0u;
19+
mod x86_64;
20+
mod ua;
21+
mod x86_32;
22+
mod v9;
23+
mod v010;
24+
mod u_zzz;
25+
mod v0;
26+
mod v00;
27+
mod v009;
28+
mod w005s09t;
29+
mod u32;
30+
mod v1;
31+
mod v00t;
32+
mod v09;
33+
mod u256;
34+
mod ZY_XW;
35+
mod _abcd;
36+
mod ABCD;
37+
mod Z_YXW;
38+
mod u64;
39+
mod abcd;
40+
mod ZYXW_;
41+
mod u16;
42+
mod uz;
43+
mod v10;
44+
mod x64;
45+
mod u128;
46+
mod usize;
47+
mod v000;
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
// rustfmt-style_edition: 2024
22
// rustfmt-reorder_modules: true
33

4-
mod _ZYXW;
5-
mod _abcd;
64
mod A2;
75
mod ABCD;
8-
mod Z_YXW;
9-
mod ZY_XW;
10-
mod ZY_XW;
116
mod ZYXW;
127
mod ZYXW_;
8+
mod ZY_XW;
9+
mod ZY_XW;
10+
mod Z_YXW;
11+
mod _ZYXW;
12+
mod _abcd;
1313
mod a1;
1414
mod abcd;
15-
mod u_zzz;
16-
mod u8;
15+
mod u128;
1716
mod u16;
17+
mod u256;
1818
mod u32;
1919
mod u64;
20-
mod u128;
21-
mod u256;
20+
mod u8;
21+
mod u_zzz;
2222
mod ua;
2323
mod usize;
2424
mod uz;
25-
mod v000;
26-
mod v00;
2725
mod v0;
28-
mod v0s;
29-
mod v00t;
30-
mod v0u;
26+
mod v00;
27+
mod v000;
3128
mod v001;
32-
mod v01;
33-
mod v1;
3429
mod v009;
35-
mod v09;
36-
mod v9;
30+
mod v00t;
31+
mod v01;
3732
mod v010;
33+
mod v09;
34+
mod v0s;
35+
mod v0u;
36+
mod v1;
3837
mod v10;
38+
mod v9;
3939
mod w005s09t;
4040
mod w5s009t;
4141
mod x64;
4242
mod x86;
43+
mod x86_128;
4344
mod x86_32;
4445
mod x86_64;
45-
mod x86_128;
4646
mod x87;
4747
mod zyxw;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// rustfmt-style_edition: 2027
2+
// rustfmt-reorder_modules: true
3+
4+
mod _ZYXW;
5+
mod _abcd;
6+
mod A2;
7+
mod ABCD;
8+
mod Z_YXW;
9+
mod ZY_XW;
10+
mod ZY_XW;
11+
mod ZYXW;
12+
mod ZYXW_;
13+
mod a1;
14+
mod abcd;
15+
mod u_zzz;
16+
mod u8;
17+
mod u16;
18+
mod u32;
19+
mod u64;
20+
mod u128;
21+
mod u256;
22+
mod ua;
23+
mod usize;
24+
mod uz;
25+
mod v000;
26+
mod v00;
27+
mod v0;
28+
mod v0s;
29+
mod v00t;
30+
mod v0u;
31+
mod v001;
32+
mod v01;
33+
mod v1;
34+
mod v009;
35+
mod v09;
36+
mod v9;
37+
mod v010;
38+
mod v10;
39+
mod w005s09t;
40+
mod w5s009t;
41+
mod x64;
42+
mod x86;
43+
mod x86_32;
44+
mod x86_64;
45+
mod x86_128;
46+
mod x87;
47+
mod zyxw;

0 commit comments

Comments
 (0)