Skip to content

Commit 5ae94cc

Browse files
ytmimicalebcartwright
authored andcommitted
Backport 3795
fix sorting of use statements with raw identifiers
1 parent 1a6146e commit 5ae94cc

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/imports.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -815,9 +815,16 @@ impl Ord for UseSegment {
815815
match (self, other) {
816816
(&Slf(ref a), &Slf(ref b))
817817
| (&Super(ref a), &Super(ref b))
818-
| (&Crate(ref a), &Crate(ref b)) => a.cmp(b),
818+
| (&Crate(ref a), &Crate(ref b)) => match (a, b) {
819+
(Some(sa), Some(sb)) => {
820+
sa.trim_start_matches("r#").cmp(sb.trim_start_matches("r#"))
821+
}
822+
(_, _) => a.cmp(b),
823+
},
819824
(&Glob, &Glob) => Ordering::Equal,
820-
(&Ident(ref ia, ref aa), &Ident(ref ib, ref ab)) => {
825+
(&Ident(ref pia, ref aa), &Ident(ref pib, ref ab)) => {
826+
let ia = pia.trim_start_matches("r#");
827+
let ib = pib.trim_start_matches("r#");
821828
// snake_case < CamelCase < UPPER_SNAKE_CASE
822829
if ia.starts_with(char::is_uppercase) && ib.starts_with(char::is_lowercase) {
823830
return Ordering::Greater;
@@ -835,13 +842,14 @@ impl Ord for UseSegment {
835842
if ident_ord != Ordering::Equal {
836843
return ident_ord;
837844
}
838-
if aa.is_none() && ab.is_some() {
839-
return Ordering::Less;
840-
}
841-
if aa.is_some() && ab.is_none() {
842-
return Ordering::Greater;
845+
match (aa, ab) {
846+
(None, Some(_)) => Ordering::Less,
847+
(Some(_), None) => Ordering::Greater,
848+
(Some(aas), Some(abs)) => aas
849+
.trim_start_matches("r#")
850+
.cmp(abs.trim_start_matches("r#")),
851+
(None, None) => Ordering::Equal,
843852
}
844-
aa.cmp(ab)
845853
}
846854
(&List(ref a), &List(ref b)) => {
847855
for (a, b) in a.iter().zip(b.iter()) {
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use websocket::client::ClientBuilder;
2+
use websocket::r#async::futures::Stream;
3+
use websocket::result::WebSocketError;
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use websocket::r#async::futures::Stream;
2+
use websocket::client::ClientBuilder;
3+
use websocket::result::WebSocketError;

0 commit comments

Comments
 (0)