Skip to content

unused macros fails some obvious cases due to prelude #51177

Open
@nikomatsakis

Description

@nikomatsakis

This example does not warn, even in Rust 2018 edition:

// compile-flags: --edition 2018
extern crate foo; 
fn main() { foo::bar(); }

The reason is that we resolve foo against the extern crate, when in fact it could also be resolved by the extern prelude fallback. But that's tricky! Something like this could also happen:

// compile-flags: --edition 2018
mod bar { mod foo { } }
use bar::*; // `foo` here is shadowed by `foo` below
extern crate foo; 
fn main() { foo::bar(); }

In which case, removing foo would result in importing the module, since (I believe) that would shadow the implicit prelude imports.

Therefore: we can do better here, but with caution -- for example, we could suggest removing an extern crate in a scenario like this, but only if there are no glob imports in the current module. Not sure it's worth it though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-epochWorking group: Epoch (2018) management

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions