From 35a4edc94d544b00d4752ae8075080434fcf7511 Mon Sep 17 00:00:00 2001 From: Paul Gey Date: Sun, 17 Oct 2021 16:21:53 +0200 Subject: [PATCH] Preserve attributes for `imports_granularity=Item` Fixes #5030 --- src/imports.rs | 2 +- tests/source/issue-5030.rs | 7 +++++++ tests/target/issue-5030.rs | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/source/issue-5030.rs create mode 100644 tests/target/issue-5030.rs 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;