Closed
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.