Skip to content

Commit 8df0b6f

Browse files
authored
Merge pull request rust-lang#3810 from calebcartwright/issue-3808
fix erroneous flattening of `{self}` in imports
2 parents ee38d02 + 634e244 commit 8df0b6f

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/imports.rs

+10
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,12 @@ impl UseTree {
543543
}
544544
match self.path.clone().last().unwrap() {
545545
UseSegment::List(list) => {
546+
if list.len() == 1 && list[0].path.len() == 1 {
547+
match list[0].path[0] {
548+
UseSegment::Slf(..) => return vec![self],
549+
_ => (),
550+
};
551+
}
546552
let prefix = &self.path[..self.path.len() - 1];
547553
let mut result = vec![];
548554
for nested_use_tree in list {
@@ -1018,6 +1024,10 @@ mod test {
10181024
["a::{c, d, b}", "a::{d, e, b, a, f}", "a::{f, g, c}"],
10191025
["a::{a, b, c, d, e, f, g}"]
10201026
);
1027+
test_merge!(
1028+
["a::{self}", "b::{self as foo}"],
1029+
["a::{self}", "b::{self as foo}"]
1030+
);
10211031
}
10221032

10231033
#[test]

tests/source/merge_imports.rs

+10
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,13 @@ use a::{b::{c::*}};
2222
use a::{b::{c::{}}};
2323
use a::{b::{c::d}};
2424
use a::{b::{c::{xxx, yyy, zzz}}};
25+
26+
// https://github.com/rust-lang/rustfmt/issues/3808
27+
use d::{self};
28+
use e::{self as foo};
29+
use f::{self, b};
30+
use g::a;
31+
use g::{self, b};
32+
use h::{a};
33+
use i::a::{self};
34+
use j::{a::{self}};

tests/target/merge_imports.rs

+9
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@ use foo::{a, b, c};
1414
pub use foo::{bar, foobar};
1515

1616
use a::b::c::{d, xxx, yyy, zzz, *};
17+
18+
// https://github.com/rust-lang/rustfmt/issues/3808
19+
use d::{self};
20+
use e::{self as foo};
21+
use f::{self, b};
22+
use g::{self, a, b};
23+
use h::a;
24+
use i::a::{self};
25+
use j::a::{self};

0 commit comments

Comments
 (0)