Skip to content

Commit 91d4240

Browse files
committed
reorder: use versionsort for mod and extern crate
1 parent 0c2fe71 commit 91d4240

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/reorder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ where
132132
fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
133133
match (&a.node, &b.node) {
134134
(&ast::ItemKind::Mod(..), &ast::ItemKind::Mod(..)) => {
135-
a.ident.as_str().cmp(&b.ident.as_str())
135+
compare_as_versions(&a.ident.as_str(), &b.ident.as_str())
136136
}
137137
(&ast::ItemKind::ExternCrate(ref a_name), &ast::ItemKind::ExternCrate(ref b_name)) => {
138138
// `extern crate foo as bar;`
@@ -141,7 +141,7 @@ fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
141141
a_name.map_or_else(|| a.ident.as_str(), syntax_pos::symbol::Symbol::as_str);
142142
let b_orig_name =
143143
b_name.map_or_else(|| b.ident.as_str(), syntax_pos::symbol::Symbol::as_str);
144-
let result = a_orig_name.cmp(&b_orig_name);
144+
let result = compare_as_versions(&a_orig_name, &b_orig_name);
145145
if result != Ordering::Equal {
146146
return result;
147147
}
@@ -152,7 +152,7 @@ fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
152152
(Some(..), None) => Ordering::Greater,
153153
(None, Some(..)) => Ordering::Less,
154154
(None, None) => Ordering::Equal,
155-
(Some(..), Some(..)) => a.ident.as_str().cmp(&b.ident.as_str()),
155+
(Some(..), Some(..)) => compare_as_versions(&a.ident.as_str(), &b.ident.as_str()),
156156
}
157157
}
158158
_ => unreachable!(),

tests/source/imports-reorder-lines.rs

Lines changed: 11 additions & 0 deletions
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;

tests/target/imports-reorder-lines.rs

Lines changed: 11 additions & 0 deletions
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)