Skip to content

Commit e0f1b01

Browse files
committed
reorder: use versionsort for mod and extern crate
1 parent 02f30f3 commit e0f1b01

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ where
141141
fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
142142
match (&a.kind, &b.kind) {
143143
(&ast::ItemKind::Mod(..), &ast::ItemKind::Mod(..)) => {
144-
a.ident.as_str().cmp(&b.ident.as_str())
144+
compare_as_versions(&a.ident.as_str(), &b.ident.as_str())
145145
}
146146
(&ast::ItemKind::ExternCrate(ref a_name), &ast::ItemKind::ExternCrate(ref b_name)) => {
147147
// `extern crate foo as bar;`
148148
// ^^^ Comparing this.
149149
let a_orig_name = a_name.map_or_else(|| a.ident.as_str(), rustc_span::Symbol::as_str);
150150
let b_orig_name = b_name.map_or_else(|| b.ident.as_str(), rustc_span::Symbol::as_str);
151-
let result = a_orig_name.cmp(&b_orig_name);
151+
let result = compare_as_versions(&a_orig_name, &b_orig_name);
152152
if result != Ordering::Equal {
153153
return result;
154154
}
@@ -159,7 +159,7 @@ fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
159159
(Some(..), None) => Ordering::Greater,
160160
(None, Some(..)) => Ordering::Less,
161161
(None, None) => Ordering::Equal,
162-
(Some(..), Some(..)) => a.ident.as_str().cmp(&b.ident.as_str()),
162+
(Some(..), Some(..)) => compare_as_versions(&a.ident.as_str(), &b.ident.as_str()),
163163
}
164164
}
165165
_ => unreachable!(),

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

+11
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,14 @@ mod test {}
3030

3131
use test::{a as aa, c};
3232
use test::{self as bb, b};
33+
34+
#[path = "empty_file.rs"]
35+
mod v10;
36+
#[path = "empty_file.rs"]
37+
mod v2;
38+
39+
extern crate crate10;
40+
extern crate crate2;
41+
42+
extern crate my as c10;
43+
extern crate my as c2;

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

+11
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,14 @@ mod test {}
2929

3030
use test::{self as bb, b};
3131
use test::{a as aa, c};
32+
33+
#[path = "empty_file.rs"]
34+
mod v2;
35+
#[path = "empty_file.rs"]
36+
mod v10;
37+
38+
extern crate crate2;
39+
extern crate crate10;
40+
41+
extern crate my as c2;
42+
extern crate my as c10;

0 commit comments

Comments
 (0)