-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Open
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyArea: Name/path resolution done by `rustc_resolve` specificallyC-future-incompatibilityCategory: Future-incompatibility lintsCategory: Future-incompatibility lintsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: 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.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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
- FCW Lint when using an ambiguously glob imported trait #149058 introduced the lint
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyArea: Name/path resolution done by `rustc_resolve` specificallyC-future-incompatibilityCategory: Future-incompatibility lintsCategory: Future-incompatibility lintsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: 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.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.