Deduplicate grouped vs individual imports on entity merge (#2947) - #3163
Merged
Conversation
When regenerating entities with --preserve-user-modifications, the merge
deduplicated whole use statements by structural equality. A user-grouped
import (use foo::{A, B}) was therefore not recognised as equivalent to the
freshly generated individual imports (use foo::A; use foo::B;), so both were
emitted, producing duplicate imports.
Dedup at the individual import-leaf level instead: flatten each use tree into
canonical leaf paths and drop a statement only when all of its leaves have
already been imported. Non-overlapping grouped imports are still preserved
verbatim (covered by the existing complex_use test).
tyt2y3
force-pushed
the
fix-2947-dedup-enum-imports
branch
from
August 8, 2026 16:49
e37d646 to
900a777
Compare
🎉 Released In 2.0.2 🎉Huge thanks for the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2947.
Bug
When regenerating entities with
--preserve-user-modifications, the merge deduplicated wholeusestatements by structural equality (HashSet<ItemUse>). If the user had grouped an enum import in the existing file while the freshly generated output uses individual imports, the two were not recognised as equivalent, so both were emitted:Fix
Deduplicate at the individual import-leaf level. Each
usetree is flattened into canonical leaf paths (super::foo::Bar,crate::Baz as Qux,sea_orm::entity::prelude::*), and a statement is dropped only when all of its leaves have already been imported. Grouped and individual imports of the same items now collapse to the same set of leaves and deduplicate against each other.Non-overlapping grouped imports are still preserved verbatim (guarded by the existing
complex_usetest).Tests
duplicate_enum_imports_grouped_vs_individual, which reproduces the report and fails against the old structural dedup.merge::and codegen tests pass.No changelog entry added — leaving the next-version slotting to the release workflow.