rust-lang / rust-lang/rust

False negative lint for `unused_imports`

Open
#126,122 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-lints L-unused_imports T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
mod a {
  pub(crate) use crate::s;
}
mod b {
  pub mod s {}
}
use self::b::*;
use self::a::s;

fn main() {}
Current output
nothing
Desired output
Report `use self::a::s` as `unused_import`
Rationale and extra context

If you make a slight modification:

mod a {
  pub(crate) use crate::s;
}
mod b {
  pub mod s {}
}
use self::b::*;
- use self::a::s;
+ use self::a::s as other_s;

fn main() {}

It will report use self::a::s as other_s as an unused import.

Other cases

No response

Rust Version
rustc 1.80.0-nightly (72fdf913c 2024-06-05)
binary: rustc
commit-hash: 72fdf913c53dd0e75313ba83e4aa80df3f6e2871
commit-date: 2024-06-05
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6
Anything else?

No response

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 compiling the provided Rust reproducer with the reported rustc version and confirm that the direct use self::a::s import is not reported while the aliased form is. Trace the unused_imports lint entry point and compare how glob and re-export resolution are handled. Done means the original form is reported as an unused import without regressing the aliased case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.