diff --git a/src/imports.rs b/src/imports.rs index 02319809486..aaf7811ec72 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -509,7 +509,7 @@ impl UseTree { // Normalise foo::{bar} -> foo::bar if let UseSegment::List(ref list) = last { - if list.len() == 1 && list[0].to_string() != "self" { + if list.len() == 1 && !list[0].has_comment() && list[0].to_string() != "self" { normalize_sole_list = true; } } @@ -582,11 +582,8 @@ impl UseTree { } fn flatten(self) -> Vec { - if self.path.is_empty() { - return vec![self]; - } - match self.path.clone().last().unwrap() { - UseSegment::List(list) => { + match self.path.clone().last() { + Some(UseSegment::List(list)) => { if list.len() == 1 && list[0].path.len() == 1 { if let UseSegment::Slf(..) = list[0].path[0] { return vec![self]; @@ -595,9 +592,9 @@ impl UseTree { let prefix = &self.path[..self.path.len() - 1]; let mut result = vec![]; for nested_use_tree in list { - for flattend in &mut nested_use_tree.clone().flatten() { + for flattened in &mut nested_use_tree.clone().flatten() { let mut new_path = prefix.to_vec(); - new_path.append(&mut flattend.path); + new_path.append(&mut flattened.path); result.push(UseTree { path: new_path, span: self.span, diff --git a/tests/source/imports.rs b/tests/source/imports.rs index 4dfc6ed94e3..1df83f9a646 100644 --- a/tests/source/imports.rs +++ b/tests/source/imports.rs @@ -27,6 +27,9 @@ use self; use std::io::{self}; use std::io::self; +use a::{/* comment */ item}; +use a::{item /* comment */}; + mod Foo { pub use rustc_ast::ast::{ ItemForeignMod, diff --git a/tests/target/imports.rs b/tests/target/imports.rs index 87584d89f66..12a958a78ad 100644 --- a/tests/target/imports.rs +++ b/tests/target/imports.rs @@ -30,6 +30,9 @@ use {Bar /* comment */, /* Pre-comment! */ Foo}; use std::io; use std::io::{self}; +use a::{/* comment */ item}; +use a::{item /* comment */}; + mod Foo { pub use rustc_ast::ast::{ ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic,