rust-lang / rust-lang/rustfmt

Deduplication of module/enum self on imports

Open
#6,638 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

needs-triage
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

mod foo {
    mod bar {}
}

enum Foo {
    Bar,
}

use Foo;
use Foo::{self};
use foo;
use foo::{self};
use foo::{
    bar,
    bar::{self},
};

The compiler doesn't like the above for obvious reasons ("foo", "foo::bar", and "Foo" are each imported twice). But the formatter doesn't recognize them as being the same import.

I ran into this using my usual merge conflict resolution process for imports: accept all that let the compiler tell me which ones aren't needed any more. That process normally leads to warnings, not errors, but this is an error condition.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running rustfmt on the Rust snippet in the issue and confirm that self imports are not treated as duplicates. Trace the formatter's import-handling entry point, then add a regression case covering Foo, foo, and foo::bar self imports. Done means the formatter handles these equivalent imports without producing output that leaves duplicate imports.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.