Skip to content

defer version sorted modules until style-edition 2027 #6594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/reorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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()),
Expand Down
47 changes: 47 additions & 0 deletions tests/source/reorder_modules/disabled_style_edition_2027.rs
Original file line number Diff line number Diff line change
@@ -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;
47 changes: 47 additions & 0 deletions tests/source/reorder_modules/enabled_style_edition_2027.rs
Original file line number Diff line number Diff line change
@@ -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;
47 changes: 47 additions & 0 deletions tests/target/reorder_modules/disabled_style_edition_2027.rs
Original file line number Diff line number Diff line change
@@ -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;
38 changes: 19 additions & 19 deletions tests/target/reorder_modules/enabled_style_edition_2024.rs
Original file line number Diff line number Diff line change
@@ -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;
47 changes: 47 additions & 0 deletions tests/target/reorder_modules/enabled_style_edition_2027.rs
Original file line number Diff line number Diff line change
@@ -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;
Loading