Merge pull request #3810 from calebcartwright/issue-3808

fix erroneous flattening of `{self}` in imports
This commit is contained in:
Stéphane Campinas 2019-09-28 12:32:41 +02:00 committed by GitHub
commit 8df0b6fa23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -543,6 +543,12 @@ impl UseTree {
}
match self.path.clone().last().unwrap() {
UseSegment::List(list) => {
if list.len() == 1 && list[0].path.len() == 1 {
match list[0].path[0] {
UseSegment::Slf(..) => return vec![self],
_ => (),
};
}
let prefix = &self.path[..self.path.len() - 1];
let mut result = vec![];
for nested_use_tree in list {
@ -1018,6 +1024,10 @@ mod test {
["a::{c, d, b}", "a::{d, e, b, a, f}", "a::{f, g, c}"],
["a::{a, b, c, d, e, f, g}"]
);
test_merge!(
["a::{self}", "b::{self as foo}"],
["a::{self}", "b::{self as foo}"]
);
}
#[test]

View File

@ -22,3 +22,13 @@ use a::{b::{c::*}};
use a::{b::{c::{}}};
use a::{b::{c::d}};
use a::{b::{c::{xxx, yyy, zzz}}};
// https://github.com/rust-lang/rustfmt/issues/3808
use d::{self};
use e::{self as foo};
use f::{self, b};
use g::a;
use g::{self, b};
use h::{a};
use i::a::{self};
use j::{a::{self}};

View File

@ -14,3 +14,12 @@ use foo::{a, b, c};
pub use foo::{bar, foobar};
use a::b::c::{d, xxx, yyy, zzz, *};
// https://github.com/rust-lang/rustfmt/issues/3808
use d::{self};
use e::{self as foo};
use f::{self, b};
use g::{self, a, b};
use h::a;
use i::a::{self};
use j::a::{self};