-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-trait-systemArea: Trait systemArea: Trait systemT-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.T-langRelevant to the language teamRelevant to the language team
Description
I was very surprised when I found the following outputs "trait method" (playground):
struct Struct;
impl Struct {
fn foo(&self) {
println!("inherent method")
}
}
pub trait Foo {
fn foo(self);
}
impl Foo for Struct {
fn foo(self) {
println!("trait method")
}
}
fn main() {
Struct.foo();
}
Up until now I always thought that an inherent method always takes precedence over a trait method of the same name. Is that not true in this case / is this behaviour intended?
This came up in yew, which defined an inherent try_into
(now renamed) with a type parameter that would start producing errors about unexpected type parameters when TryInto
(or stdweb::unstable::TryInto
) was brought into scope.
HeyZoos
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemT-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.T-langRelevant to the language teamRelevant to the language team