Skip to content

Commit 82abbe2

Browse files
fix: sorting of use statements with raw identifiers (rust-lang#3795)
1 parent e4a50da commit 82abbe2

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

src/imports.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,16 @@ impl Ord for UseSegment {
662662
match (self, other) {
663663
(&Slf(ref a), &Slf(ref b))
664664
| (&Super(ref a), &Super(ref b))
665-
| (&Crate(ref a), &Crate(ref b)) => a.cmp(b),
665+
| (&Crate(ref a), &Crate(ref b)) => match (a, b) {
666+
(Some(sa), Some(sb)) => {
667+
sa.trim_start_matches("r#").cmp(sb.trim_start_matches("r#"))
668+
}
669+
(_, _) => a.cmp(b),
670+
},
666671
(&Glob, &Glob) => Ordering::Equal,
667-
(&Ident(ref ia, ref aa), &Ident(ref ib, ref ab)) => {
672+
(&Ident(ref pia, ref aa), &Ident(ref pib, ref ab)) => {
673+
let ia = pia.trim_start_matches("r#");
674+
let ib = pib.trim_start_matches("r#");
668675
// snake_case < CamelCase < UPPER_SNAKE_CASE
669676
if ia.starts_with(char::is_uppercase) && ib.starts_with(char::is_lowercase) {
670677
return Ordering::Greater;
@@ -682,13 +689,14 @@ impl Ord for UseSegment {
682689
if ident_ord != Ordering::Equal {
683690
return ident_ord;
684691
}
685-
if aa.is_none() && ab.is_some() {
686-
return Ordering::Less;
687-
}
688-
if aa.is_some() && ab.is_none() {
689-
return Ordering::Greater;
692+
match (aa, ab) {
693+
(None, Some(_)) => Ordering::Less,
694+
(Some(_), None) => Ordering::Greater,
695+
(Some(aas), Some(abs)) => aas
696+
.trim_start_matches("r#")
697+
.cmp(abs.trim_start_matches("r#")),
698+
(None, None) => Ordering::Equal,
690699
}
691-
aa.cmp(ab)
692700
}
693701
(&List(ref a), &List(ref b)) => {
694702
for (a, b) in a.iter().zip(b.iter()) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use websocket::client::ClientBuilder;
2+
use websocket::r#async::futures::Stream;
3+
use websocket::result::WebSocketError;
4+
5+
fn main() {
6+
println!("Hello, world!");
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use websocket::r#async::futures::Stream;
2+
use websocket::client::ClientBuilder;
3+
use websocket::result::WebSocketError;
4+
5+
fn main() {
6+
println!("Hello, world!");
7+
}

0 commit comments

Comments
 (0)