Skip to content

Commit 07d8cca

Browse files
committed
Fix for issue 4725 - dedup Item imports_granularity
1 parent 87e9602 commit 07d8cca

32 files changed

+63
-3
lines changed

src/formatting/imports.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub(crate) fn merge_use_trees(use_trees: Vec<UseTree>, merge_by: SharedPrefix) -
183183
}
184184

185185
pub(crate) fn flatten_use_trees(use_trees: Vec<UseTree>) -> Vec<UseTree> {
186-
use_trees
186+
let mut ut: Vec<UseTree> = use_trees
187187
.into_iter()
188188
.flat_map(UseTree::flatten)
189189
.map(|mut tree| {
@@ -197,7 +197,9 @@ pub(crate) fn flatten_use_trees(use_trees: Vec<UseTree>) -> Vec<UseTree> {
197197
}
198198
tree
199199
})
200-
.collect()
200+
.collect();
201+
ut.dedup();
202+
return ut;
201203
}
202204

203205
impl fmt::Debug for UseTree {

src/formatting/reorder.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,15 @@ fn rewrite_reorderable_or_regroupable_items(
243243
};
244244

245245
if context.config.reorder_imports() {
246-
regrouped_items.iter_mut().for_each(|items| items.sort())
246+
regrouped_items.iter_mut().for_each(|items| {
247+
items.sort();
248+
match context.config.imports_granularity() {
249+
ImportGranularity::Crate
250+
| ImportGranularity::Module
251+
| ImportGranularity::Item => items.dedup(),
252+
ImportGranularity::Preserve => {}
253+
}
254+
})
247255
}
248256

249257
// 4 = "use ", 1 = ";"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)