diff --git a/src/imports.rs b/src/imports.rs index efe4e9498c9..7653f6d1bbb 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -610,13 +610,13 @@ 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(import_granularity) { + for mut flattend in nested_use_tree.clone().flatten(import_granularity) { let mut new_path = prefix.to_vec(); new_path.append(&mut flattend.path); result.push(UseTree { path: new_path, span: self.span, - list_item: None, + list_item: flattend.list_item, visibility: self.visibility.clone(), // only retain attributes for `ImportGranularity::Item` attrs: match import_granularity { diff --git a/tests/source/imports_granularity_item.rs b/tests/source/imports_granularity_item.rs index d0e94df66ae..3fa63045806 100644 --- a/tests/source/imports_granularity_item.rs +++ b/tests/source/imports_granularity_item.rs @@ -1,6 +1,14 @@ // rustfmt-imports_granularity: Item -use a::{b, c, d}; +use a::{ + b, + c, + // Comment before a::d + d, + e, // Comment after a::e +}; use a::{f::g, h::{i, j}}; use a::{l::{self, m, n::o, p::*}}; use a::q::{self}; +// Comment before a::r +use a::r; diff --git a/tests/target/imports_granularity_item.rs b/tests/target/imports_granularity_item.rs index eace785e670..22146531e39 100644 --- a/tests/target/imports_granularity_item.rs +++ b/tests/target/imports_granularity_item.rs @@ -2,7 +2,9 @@ use a::b; use a::c; +// Comment before a::d use a::d; +use a::e; // Comment after a::e use a::f::g; use a::h::i; use a::h::j; @@ -11,3 +13,5 @@ use a::l::n::o; use a::l::p::*; use a::l::{self}; use a::q::{self}; +// Comment before a::r +use a::r; diff --git a/tests/target/imports_granularity_module.rs b/tests/target/imports_granularity_module.rs index e4e1a299e58..7b72a545b05 100644 --- a/tests/target/imports_granularity_module.rs +++ b/tests/target/imports_granularity_module.rs @@ -17,6 +17,8 @@ use foo::e; #[cfg(test)] use foo::{a::b, c::d}; +// comment use bar::a::b; +// more comment use bar::c::d; use bar::e::f;