Skip to content

Commit 02f30f3

Browse files
committed
reorder: use versionsort for self/super/crate as name
Just for consistency with other use-statement parts.
1 parent f20f44d commit 02f30f3

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

rustfmt-core/rustfmt-lib/src/imports.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,7 @@ impl Ord for UseSegment {
655655
match (self, other) {
656656
(&Slf(ref a), &Slf(ref b))
657657
| (&Super(ref a), &Super(ref b))
658-
| (&Crate(ref a), &Crate(ref b)) => match (a, b) {
659-
(Some(sa), Some(sb)) => {
660-
sa.trim_start_matches("r#").cmp(sb.trim_start_matches("r#"))
661-
}
662-
(_, _) => a.cmp(b),
663-
},
658+
| (&Crate(ref a), &Crate(ref b)) => compare_opt_ident_as_versions(&a, &b),
664659
(&Glob, &Glob) => Ordering::Equal,
665660
(&Ident(ref pia, ref aa), &Ident(ref pib, ref ab)) => {
666661
let ia = pia.trim_start_matches("r#");

rustfmt-core/rustfmt-lib/tests/source/imports-reorder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ use {ab, ac, aa, Z, b};
77
// The sort order shall follow versionsort
88
use {u8, u128, u64, u16, u32};
99
use {v1, v0200, v0030, v0002, v02000, v02001};
10+
// Order by alias should use versionsort too
11+
use {crate as crate10, crate as crate2, crate as crate1};

rustfmt-core/rustfmt-lib/tests/target/imports-reorder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ use {aa, ab, ac, b, Z};
77
// The sort order shall follow versionsort
88
use {u8, u16, u32, u64, u128};
99
use {v0002, v0030, v0200, v02000, v02001, v1};
10+
// Order by alias should use versionsort too
11+
use {crate as crate1, crate as crate2, crate as crate10};

0 commit comments

Comments
 (0)