Skip to content

Unused imports are too conservative #10178

Closed
@alexcrichton

Description

@alexcrichton
use foo::Bar;

mod foo {
    pub type Bar = i32;
}

fn baz() -> Bar { 3 }

fn main() {
    use foo::Bar; // this should trigger an unused import warning
    let _a: Bar = 3;
    baz();
}

Right now that program has no unused import warnings, but the second one can be considered an unused import. The reason it's not unused is because it brings a name into the current scope, which is indeed then used. The catch is that the name it brings into scope is the exact same as what it was before.

It'd be nice if resolve caught this and basically didn't bring in any metadata about the inner use foo::Bar import (only because it's already in scope by a previous import).

Not critical, but it would help us cut down on imports!

Metadata

Metadata

Assignees

Labels

A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions