Skip to content

Commit 1e7f259

Browse files
calebcartwrighttopecongiro
authored andcommitted
fix: sorting of use statements with raw identifiers (#3795)
1 parent ee38d02 commit 1e7f259

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
@@ -656,9 +656,16 @@ impl Ord for UseSegment {
656656
match (self, other) {
657657
(&Slf(ref a), &Slf(ref b))
658658
| (&Super(ref a), &Super(ref b))
659-
| (&Crate(ref a), &Crate(ref b)) => a.cmp(b),
659+
| (&Crate(ref a), &Crate(ref b)) => match (a, b) {
660+
(Some(sa), Some(sb)) => {
661+
sa.trim_start_matches("r#").cmp(sb.trim_start_matches("r#"))
662+
}
663+
(_, _) => a.cmp(b),
664+
},
660665
(&Glob, &Glob) => Ordering::Equal,
661-
(&Ident(ref ia, ref aa), &Ident(ref ib, ref ab)) => {
666+
(&Ident(ref pia, ref aa), &Ident(ref pib, ref ab)) => {
667+
let ia = pia.trim_start_matches("r#");
668+
let ib = pib.trim_start_matches("r#");
662669
// snake_case < CamelCase < UPPER_SNAKE_CASE
663670
if ia.starts_with(char::is_uppercase) && ib.starts_with(char::is_lowercase) {
664671
return Ordering::Greater;
@@ -676,13 +683,14 @@ impl Ord for UseSegment {
676683
if ident_ord != Ordering::Equal {
677684
return ident_ord;
678685
}
679-
if aa.is_none() && ab.is_some() {
680-
return Ordering::Less;
681-
}
682-
if aa.is_some() && ab.is_none() {
683-
return Ordering::Greater;
686+
match (aa, ab) {
687+
(None, Some(_)) => Ordering::Less,
688+
(Some(_), None) => Ordering::Greater,
689+
(Some(aas), Some(abs)) => aas
690+
.trim_start_matches("r#")
691+
.cmp(abs.trim_start_matches("r#")),
692+
(None, None) => Ordering::Equal,
684693
}
685-
aa.cmp(ab)
686694
}
687695
(&List(ref a), &List(ref b)) => {
688696
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)