From 46acb3494ab1cf77230390088edd934ce84a5ca9 Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Tue, 1 Jul 2025 23:21:48 -0400 Subject: [PATCH] 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. --- CHANGELOG.md | 2 +- src/reorder.rs | 6 +-- .../disabled_style_edition_2027.rs | 47 +++++++++++++++++++ .../enabled_style_edition_2027.rs | 47 +++++++++++++++++++ .../disabled_style_edition_2027.rs | 47 +++++++++++++++++++ .../enabled_style_edition_2024.rs | 38 +++++++-------- .../enabled_style_edition_2027.rs | 47 +++++++++++++++++++ 7 files changed, 211 insertions(+), 23 deletions(-) create mode 100644 tests/source/reorder_modules/disabled_style_edition_2027.rs create mode 100644 tests/source/reorder_modules/enabled_style_edition_2027.rs create mode 100644 tests/target/reorder_modules/disabled_style_edition_2027.rs create mode 100644 tests/target/reorder_modules/enabled_style_edition_2027.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 69fc38a416d..d0ca09ab1fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ ### Changed - 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) -- Apply version sorting to module declarations when using `style_edition=2024` [#6368](https://github.com/rust-lang/rustfmt/pull/6368) +- 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) - 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) - Correct version chunk splitting in the internal version sort algorithm [#6407](https://github.com/rust-lang/rustfmt/pull/6407) - 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) diff --git a/src/reorder.rs b/src/reorder.rs index e9d0fc059f8..6ef6e0bc969 100644 --- a/src/reorder.rs +++ b/src/reorder.rs @@ -29,7 +29,7 @@ fn compare_items(a: &ast::Item, b: &ast::Item, context: &RewriteContext<'_>) -> let style_edition = context.config.style_edition(); match (&a.kind, &b.kind) { (&ast::ItemKind::Mod(_, a_ident, _), &ast::ItemKind::Mod(_, b_ident, _)) => { - if style_edition <= StyleEdition::Edition2021 { + if style_edition <= StyleEdition::Edition2024 { a_ident.as_str().cmp(b_ident.as_str()) } else { 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<'_>) -> // ^^^ Comparing this. let a_orig_name = a_name.unwrap_or(a_ident.name); let b_orig_name = b_name.unwrap_or(b_ident.name); - let result = if style_edition <= StyleEdition::Edition2021 { + let result = if style_edition <= StyleEdition::Edition2024 { a_orig_name.as_str().cmp(b_orig_name.as_str()) } else { 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<'_>) -> (Some(..), None) => Ordering::Greater, (None, Some(..)) => Ordering::Less, (None, None) => Ordering::Equal, - (Some(..), Some(..)) if style_edition <= StyleEdition::Edition2021 => { + (Some(..), Some(..)) if style_edition <= StyleEdition::Edition2024 => { a_ident.as_str().cmp(b_ident.as_str()) } (Some(..), Some(..)) => version_sort(a_ident.as_str(), b_ident.as_str()), diff --git a/tests/source/reorder_modules/disabled_style_edition_2027.rs b/tests/source/reorder_modules/disabled_style_edition_2027.rs new file mode 100644 index 00000000000..f5f0cb6357f --- /dev/null +++ b/tests/source/reorder_modules/disabled_style_edition_2027.rs @@ -0,0 +1,47 @@ +// rustfmt-style_edition: 2027 +// rustfmt-reorder_modules: false + +mod x86; +mod v0s; +mod v001; +mod x87; +mod zyxw; +mod A2; +mod ZYXW; +mod w5s009t; +mod u8; +mod x86_128; +mod _ZYXW; +mod ZY_XW; +mod a1; +mod v01; +mod v0u; +mod x86_64; +mod ua; +mod x86_32; +mod v9; +mod v010; +mod u_zzz; +mod v0; +mod v00; +mod v009; +mod w005s09t; +mod u32; +mod v1; +mod v00t; +mod v09; +mod u256; +mod ZY_XW; +mod _abcd; +mod ABCD; +mod Z_YXW; +mod u64; +mod abcd; +mod ZYXW_; +mod u16; +mod uz; +mod v10; +mod x64; +mod u128; +mod usize; +mod v000; diff --git a/tests/source/reorder_modules/enabled_style_edition_2027.rs b/tests/source/reorder_modules/enabled_style_edition_2027.rs new file mode 100644 index 00000000000..46f6abe9312 --- /dev/null +++ b/tests/source/reorder_modules/enabled_style_edition_2027.rs @@ -0,0 +1,47 @@ +// rustfmt-style_edition: 2027 +// rustfmt-reorder_modules: true + +mod x86; +mod v0s; +mod v001; +mod x87; +mod zyxw; +mod A2; +mod ZYXW; +mod w5s009t; +mod u8; +mod x86_128; +mod _ZYXW; +mod ZY_XW; +mod a1; +mod v01; +mod v0u; +mod x86_64; +mod ua; +mod x86_32; +mod v9; +mod v010; +mod u_zzz; +mod v0; +mod v00; +mod v009; +mod w005s09t; +mod u32; +mod v1; +mod v00t; +mod v09; +mod u256; +mod ZY_XW; +mod _abcd; +mod ABCD; +mod Z_YXW; +mod u64; +mod abcd; +mod ZYXW_; +mod u16; +mod uz; +mod v10; +mod x64; +mod u128; +mod usize; +mod v000; diff --git a/tests/target/reorder_modules/disabled_style_edition_2027.rs b/tests/target/reorder_modules/disabled_style_edition_2027.rs new file mode 100644 index 00000000000..f5f0cb6357f --- /dev/null +++ b/tests/target/reorder_modules/disabled_style_edition_2027.rs @@ -0,0 +1,47 @@ +// rustfmt-style_edition: 2027 +// rustfmt-reorder_modules: false + +mod x86; +mod v0s; +mod v001; +mod x87; +mod zyxw; +mod A2; +mod ZYXW; +mod w5s009t; +mod u8; +mod x86_128; +mod _ZYXW; +mod ZY_XW; +mod a1; +mod v01; +mod v0u; +mod x86_64; +mod ua; +mod x86_32; +mod v9; +mod v010; +mod u_zzz; +mod v0; +mod v00; +mod v009; +mod w005s09t; +mod u32; +mod v1; +mod v00t; +mod v09; +mod u256; +mod ZY_XW; +mod _abcd; +mod ABCD; +mod Z_YXW; +mod u64; +mod abcd; +mod ZYXW_; +mod u16; +mod uz; +mod v10; +mod x64; +mod u128; +mod usize; +mod v000; diff --git a/tests/target/reorder_modules/enabled_style_edition_2024.rs b/tests/target/reorder_modules/enabled_style_edition_2024.rs index ad78762aa01..addc555aa0e 100644 --- a/tests/target/reorder_modules/enabled_style_edition_2024.rs +++ b/tests/target/reorder_modules/enabled_style_edition_2024.rs @@ -1,47 +1,47 @@ // rustfmt-style_edition: 2024 // rustfmt-reorder_modules: true -mod _ZYXW; -mod _abcd; mod A2; mod ABCD; -mod Z_YXW; -mod ZY_XW; -mod ZY_XW; mod ZYXW; mod ZYXW_; +mod ZY_XW; +mod ZY_XW; +mod Z_YXW; +mod _ZYXW; +mod _abcd; mod a1; mod abcd; -mod u_zzz; -mod u8; +mod u128; mod u16; +mod u256; mod u32; mod u64; -mod u128; -mod u256; +mod u8; +mod u_zzz; mod ua; mod usize; mod uz; -mod v000; -mod v00; mod v0; -mod v0s; -mod v00t; -mod v0u; +mod v00; +mod v000; mod v001; -mod v01; -mod v1; mod v009; -mod v09; -mod v9; +mod v00t; +mod v01; mod v010; +mod v09; +mod v0s; +mod v0u; +mod v1; mod v10; +mod v9; mod w005s09t; mod w5s009t; mod x64; mod x86; +mod x86_128; mod x86_32; mod x86_64; -mod x86_128; mod x87; mod zyxw; diff --git a/tests/target/reorder_modules/enabled_style_edition_2027.rs b/tests/target/reorder_modules/enabled_style_edition_2027.rs new file mode 100644 index 00000000000..44acabd75f5 --- /dev/null +++ b/tests/target/reorder_modules/enabled_style_edition_2027.rs @@ -0,0 +1,47 @@ +// rustfmt-style_edition: 2027 +// rustfmt-reorder_modules: true + +mod _ZYXW; +mod _abcd; +mod A2; +mod ABCD; +mod Z_YXW; +mod ZY_XW; +mod ZY_XW; +mod ZYXW; +mod ZYXW_; +mod a1; +mod abcd; +mod u_zzz; +mod u8; +mod u16; +mod u32; +mod u64; +mod u128; +mod u256; +mod ua; +mod usize; +mod uz; +mod v000; +mod v00; +mod v0; +mod v0s; +mod v00t; +mod v0u; +mod v001; +mod v01; +mod v1; +mod v009; +mod v09; +mod v9; +mod v010; +mod v10; +mod w005s09t; +mod w5s009t; +mod x64; +mod x86; +mod x86_32; +mod x86_64; +mod x86_128; +mod x87; +mod zyxw;