From b5f1657768679e40a3a1df08762c7d8fdbb786de Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Mon, 21 Feb 2022 13:46:29 -0500 Subject: [PATCH] Preserve attrs with imports_granularity=Item --- src/imports.rs | 2 +- tests/source/issue-5030.rs | 3 +++ tests/target/issue-5030.rs | 5 +++++ 3 files changed, 9 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 c60bec6d4a2..8b574e2e707 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -609,7 +609,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..7079bc7af92 --- /dev/null +++ b/tests/source/issue-5030.rs @@ -0,0 +1,3 @@ +// 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..87264fbfa49 --- /dev/null +++ b/tests/target/issue-5030.rs @@ -0,0 +1,5 @@ +// rustfmt-imports_granularity: Item +#[cfg(feature = "foo")] +use std::collections::HashMap; +#[cfg(feature = "foo")] +use std::collections::HashSet;