-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Open
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: 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.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I'd like rustc to warn me when I use a trait method on a std (or liballoc, core, ...) type without using the full trait path.
That is, if I implement my own trait for a std
library type:
trait Foo { fn bar(&self); }
impl Foo for Vec<u32> {
fn bar(&self) { }
}
fn main() {
let v = Vec::new();
v.bar(); // Warning
Foo::bar(&v); // OK
}
The motivation is that:
- if the
std
library adds a new trait with a method calledfoo
and implements it forVec<u32>
my code stops compiling due to an ambiguity error - if the
std
library adds an inherent method toVec<u32>
calledfoo
that has the same signature asFoo::foo
, my code continues to compile but might silently change behavior
I don't know whether this warning should apply exclusively to the std library or to types defined in external crates as well.
est31
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: 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.Relevant to the compiler team, which will review and decide on the PR/issue.