Skip to content

Tracking Issue for future-incompatibility lint ambiguous_glob_imported_traits #152822

@LorrensP-2158466

Description

@LorrensP-2158466

The ambiguous_glob_imported_traits lint reports uses of traits that are
imported ambiguously via glob imports

Example

mod m1 {
    pub trait Trait {
        fn method1(&self) {}
    }
    impl Trait for u8 {}
}
mod m2 {
    pub trait Trait {
        fn method2(&self) {}
    }
    impl Trait for u8 {}
}

fn main() {
    use m1::*; // Imports `m1::Trait`
    use m2::*; // imports `m2::Trait`
    0u8.method1();
    0u8.method2();
}

Explanation

When multiple traits with the same name are brought into scope through glob imports, one trait becomes the "primary" one while the others are shadowed. Methods from the shadowed traits (e.g. method2) become inaccessible, while methods from the "primary" trait (e.g. method1) still resolve. Ideally, none of the ambiguous traits would be in scope, but we have to allow this for now because of backwards compatibility. This lint reports uses of these "primary" traits that are ambiguous.

Implementation history

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-future-incompatibilityCategory: Future-incompatibility lintsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions