We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 606894e commit b2c7a52Copy full SHA for b2c7a52
src/imports.rs
@@ -238,7 +238,8 @@ impl fmt::Display for UseSegment {
238
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
239
match *self {
240
UseSegment::Glob => write!(f, "*"),
241
- UseSegment::Ident(ref s, _) => write!(f, "{}", s),
+ UseSegment::Ident(ref s, Some(ref alias)) => write!(f, "{} as {}", s, alias),
242
+ UseSegment::Ident(ref s, None) => write!(f, "{}", s),
243
UseSegment::Slf(..) => write!(f, "self"),
244
UseSegment::Super(..) => write!(f, "super"),
245
UseSegment::Crate(..) => write!(f, "crate"),
@@ -622,7 +623,8 @@ impl UseTree {
622
623
fn merge(&mut self, other: &UseTree, merge_by: SharedPrefix) {
624
let mut prefix = 0;
625
for (a, b) in self.path.iter().zip(other.path.iter()) {
- if a.equal_except_alias(b) {
626
+ // only discard the alias at the root of the tree
627
+ if (prefix == 0 && a.equal_except_alias(b)) || a == b {
628
prefix += 1;
629
} else {
630
break;
tests/source/5131.rs
@@ -0,0 +1,33 @@
1
+// rustfmt-imports_granularity: Module
2
+
3
+#![allow(dead_code)]
4
5
+mod a {
6
+ pub mod b {
7
+ pub struct Data {
8
+ pub a: i32,
9
+ }
10
11
12
+ use crate::a::b::Data;
13
+ use crate::a::b::Data as Data2;
14
15
+ pub fn data(a: i32) -> Data {
16
+ Data { a }
17
18
19
+ pub fn data2(a: i32) -> Data2 {
20
+ Data2 { a }
21
22
23
+ #[cfg(test)]
24
+ mod tests {
25
+ use super::*;
26
27
+ #[test]
28
+ pub fn test() {
29
+ data(1);
30
+ data2(1);
31
32
33
+}
tests/target/5131.rs
@@ -0,0 +1,32 @@
+ use crate::a::b::{Data, Data as Data2};
0 commit comments