Skip to content

Commit ced5993

Browse files
authored
Merge pull request #6677 from tqwewe/fix-import-granularity-dedup
Fix duplicate import removal for imports_granularity="Module"
2 parents ae9e327 + ef349de commit ced5993

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/imports.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ impl UseTree {
631631
if let UseSegmentKind::List(list) = last.kind {
632632
let mut list = list.into_iter().map(UseTree::normalize).collect::<Vec<_>>();
633633
list.sort();
634+
list.dedup();
634635
last = UseSegment {
635636
kind: UseSegmentKind::List(list),
636637
style_edition: last.style_edition,
@@ -827,6 +828,7 @@ fn merge_rest(
827828
UseTree::from_path(b[len..].to_vec(), DUMMY_SP),
828829
];
829830
list.sort();
831+
list.dedup();
830832
let mut new_path = b[..len].to_vec();
831833
let kind = UseSegmentKind::List(list);
832834
let style_edition = a[0].style_edition;
@@ -891,6 +893,7 @@ fn merge_use_trees_inner(trees: &mut Vec<UseTree>, use_tree: UseTree, merge_by:
891893
}
892894
trees.push(use_tree);
893895
trees.sort();
896+
trees.dedup();
894897
}
895898

896899
impl Hash for UseTree {

tests/source/issue-6243.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// rustfmt-imports_granularity: Module
2+
3+
use risingwave_batch::executor::{BoxedExecutor, JoinType};
4+
use risingwave_batch::executor::{BoxedExecutor, JoinType};

tests/target/issue-6243.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// rustfmt-imports_granularity: Module
2+
3+
use risingwave_batch::executor::{BoxedExecutor, JoinType};

tests/target/multiple.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ extern crate foo;
1616
extern crate foo;
1717

1818
use std::cell::*;
19-
use std::{
20-
self, any, ascii, borrow, borrow, borrow, borrow, borrow, borrow, borrow, borrow, borrow,
21-
borrow, borrow, boxed, boxed, boxed, boxed, boxed, boxed, boxed, boxed, boxed, boxed, char,
22-
char, char, char, char, char, char, char, char, char,
23-
};
19+
use std::{self, any, ascii, borrow, boxed, char};
2420

2521
mod doc;
2622
mod other;

0 commit comments

Comments
 (0)