Version gate raw identifier use statement sorting
When useing `version=One` rustfmt will treat the leading `r#` as part of the `UseSegment` used for sorting. When using `version=Two` rustfmt will ignore the leading `r#` and only consider the name of the identifier when sorting the `UseSegment`.
This commit is contained in:
parent
795efb2068
commit
e44380b341
@ -890,14 +890,21 @@ impl Ord for UseSegment {
|
|||||||
| (Super(ref a), Super(ref b))
|
| (Super(ref a), Super(ref b))
|
||||||
| (Crate(ref a), Crate(ref b)) => match (a, b) {
|
| (Crate(ref a), Crate(ref b)) => match (a, b) {
|
||||||
(Some(sa), Some(sb)) => {
|
(Some(sa), Some(sb)) => {
|
||||||
sa.trim_start_matches("r#").cmp(sb.trim_start_matches("r#"))
|
if self.version == Version::Two {
|
||||||
|
sa.trim_start_matches("r#").cmp(sb.trim_start_matches("r#"))
|
||||||
|
} else {
|
||||||
|
a.cmp(b)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(_, _) => a.cmp(b),
|
(_, _) => a.cmp(b),
|
||||||
},
|
},
|
||||||
(Glob, Glob) => Ordering::Equal,
|
(Glob, Glob) => Ordering::Equal,
|
||||||
(Ident(ref pia, ref aa), Ident(ref pib, ref ab)) => {
|
(Ident(ref pia, ref aa), Ident(ref pib, ref ab)) => {
|
||||||
let ia = pia.trim_start_matches("r#");
|
let (ia, ib) = if self.version == Version::Two {
|
||||||
let ib = pib.trim_start_matches("r#");
|
(pia.trim_start_matches("r#"), pib.trim_start_matches("r#"))
|
||||||
|
} else {
|
||||||
|
(pia.as_str(), pib.as_str())
|
||||||
|
};
|
||||||
// snake_case < CamelCase < UPPER_SNAKE_CASE
|
// snake_case < CamelCase < UPPER_SNAKE_CASE
|
||||||
if ia.starts_with(char::is_uppercase) && ib.starts_with(char::is_lowercase) {
|
if ia.starts_with(char::is_uppercase) && ib.starts_with(char::is_lowercase) {
|
||||||
return Ordering::Greater;
|
return Ordering::Greater;
|
||||||
@ -918,9 +925,14 @@ impl Ord for UseSegment {
|
|||||||
match (aa, ab) {
|
match (aa, ab) {
|
||||||
(None, Some(_)) => Ordering::Less,
|
(None, Some(_)) => Ordering::Less,
|
||||||
(Some(_), None) => Ordering::Greater,
|
(Some(_), None) => Ordering::Greater,
|
||||||
(Some(aas), Some(abs)) => aas
|
(Some(aas), Some(abs)) => {
|
||||||
.trim_start_matches("r#")
|
if self.version == Version::Two {
|
||||||
.cmp(abs.trim_start_matches("r#")),
|
aas.trim_start_matches("r#")
|
||||||
|
.cmp(abs.trim_start_matches("r#"))
|
||||||
|
} else {
|
||||||
|
aas.cmp(abs)
|
||||||
|
}
|
||||||
|
}
|
||||||
(None, None) => Ordering::Equal,
|
(None, None) => Ordering::Equal,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// rustfmt-version:One
|
||||||
|
|
||||||
use websocket::client::ClientBuilder;
|
use websocket::client::ClientBuilder;
|
||||||
use websocket::r#async::futures::Stream;
|
use websocket::r#async::futures::Stream;
|
||||||
use websocket::result::WebSocketError;
|
use websocket::result::WebSocketError;
|
@ -1,3 +1,5 @@
|
|||||||
use websocket::r#async::futures::Stream;
|
// rustfmt-version:Two
|
||||||
|
|
||||||
use websocket::client::ClientBuilder;
|
use websocket::client::ClientBuilder;
|
||||||
|
use websocket::r#async::futures::Stream;
|
||||||
use websocket::result::WebSocketError;
|
use websocket::result::WebSocketError;
|
5
tests/target/imports_raw_identifiers/version_One.rs
Normal file
5
tests/target/imports_raw_identifiers/version_One.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// rustfmt-version:One
|
||||||
|
|
||||||
|
use websocket::client::ClientBuilder;
|
||||||
|
use websocket::r#async::futures::Stream;
|
||||||
|
use websocket::result::WebSocketError;
|
5
tests/target/imports_raw_identifiers/version_Two.rs
Normal file
5
tests/target/imports_raw_identifiers/version_Two.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// rustfmt-version:Two
|
||||||
|
|
||||||
|
use websocket::r#async::futures::Stream;
|
||||||
|
use websocket::client::ClientBuilder;
|
||||||
|
use websocket::result::WebSocketError;
|
Loading…
x
Reference in New Issue
Block a user