From 494e5949f7e94bc1fdfe3ba460852ec2307225f4 Mon Sep 17 00:00:00 2001 From: Ari Seyhun Date: Mon, 6 Oct 2025 15:24:59 +1100 Subject: [PATCH] Fix duplicate import removal for imports_granularity="Module" --- src/imports.rs | 3 +++ tests/source/issue-6243.rs | 4 ++++ tests/target/issue-6243.rs | 3 +++ tests/target/multiple.rs | 6 +----- 4 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 tests/source/issue-6243.rs create mode 100644 tests/target/issue-6243.rs diff --git a/src/imports.rs b/src/imports.rs index 2e42861d1dc..f0797516b15 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -631,6 +631,7 @@ impl UseTree { if let UseSegmentKind::List(list) = last.kind { let mut list = list.into_iter().map(UseTree::normalize).collect::>(); list.sort(); + list.dedup(); last = UseSegment { kind: UseSegmentKind::List(list), style_edition: last.style_edition, @@ -827,6 +828,7 @@ fn merge_rest( UseTree::from_path(b[len..].to_vec(), DUMMY_SP), ]; list.sort(); + list.dedup(); let mut new_path = b[..len].to_vec(); let kind = UseSegmentKind::List(list); let style_edition = a[0].style_edition; @@ -891,6 +893,7 @@ fn merge_use_trees_inner(trees: &mut Vec, use_tree: UseTree, merge_by: } trees.push(use_tree); trees.sort(); + trees.dedup(); } impl Hash for UseTree { diff --git a/tests/source/issue-6243.rs b/tests/source/issue-6243.rs new file mode 100644 index 00000000000..d883f2bb239 --- /dev/null +++ b/tests/source/issue-6243.rs @@ -0,0 +1,4 @@ +// rustfmt-imports_granularity: Module + +use risingwave_batch::executor::{BoxedExecutor, JoinType}; +use risingwave_batch::executor::{BoxedExecutor, JoinType}; diff --git a/tests/target/issue-6243.rs b/tests/target/issue-6243.rs new file mode 100644 index 00000000000..e538794c9ba --- /dev/null +++ b/tests/target/issue-6243.rs @@ -0,0 +1,3 @@ +// rustfmt-imports_granularity: Module + +use risingwave_batch::executor::{BoxedExecutor, JoinType}; diff --git a/tests/target/multiple.rs b/tests/target/multiple.rs index ee6ef220c4b..d2b9789930b 100644 --- a/tests/target/multiple.rs +++ b/tests/target/multiple.rs @@ -16,11 +16,7 @@ extern crate foo; extern crate foo; use std::cell::*; -use std::{ - self, any, ascii, borrow, borrow, borrow, borrow, borrow, borrow, borrow, borrow, borrow, - borrow, borrow, boxed, boxed, boxed, boxed, boxed, boxed, boxed, boxed, boxed, boxed, char, - char, char, char, char, char, char, char, char, char, -}; +use std::{self, any, ascii, borrow, boxed, char}; mod doc; mod other;