diff --git a/src/imports.rs b/src/imports.rs index 5ac79936689..9be55a8f9c2 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -608,7 +608,7 @@ impl UseTree { span: self.span, list_item: None, visibility: self.visibility.clone(), - attrs: None, + attrs: self.attrs.clone(), }); } } diff --git a/tests/source/issue-5030.rs b/tests/source/issue-5030.rs new file mode 100644 index 00000000000..f367e79f01f --- /dev/null +++ b/tests/source/issue-5030.rs @@ -0,0 +1,7 @@ +// rustfmt-imports_granularity: Item + +#[cfg(feature = "foo")] +use std::collections::{ + HashMap, + HashSet, +}; diff --git a/tests/target/issue-5030.rs b/tests/target/issue-5030.rs new file mode 100644 index 00000000000..b371331ed00 --- /dev/null +++ b/tests/target/issue-5030.rs @@ -0,0 +1,6 @@ +// rustfmt-imports_granularity: Item + +#[cfg(feature = "foo")] +use std::collections::HashMap; +#[cfg(feature = "foo")] +use std::collections::HashSet;