rust/tests/ui/traits/impl-inherent-prefer-over-trait.rs

31 lines
472 B
Rust
Raw Normal View History

// run-pass
struct Foo;
trait Trait {
fn bar(&self);
}
// Inherent impls should be preferred over trait ones.
impl Foo {
fn bar(&self) {}
}
2019-05-28 18:47:21 +00:00
impl dyn Trait {
fn baz(_: &Foo) {}
}
impl Trait for Foo {
fn bar(&self) { panic!("wrong method called!") }
}
fn main() {
Foo.bar();
Foo::bar(&Foo);
<Foo>::bar(&Foo);
// Should work even if Trait::baz doesn't exist.
// N.B: `<Trait>::bar` would be ambiguous.
2019-05-28 18:47:21 +00:00
<dyn Trait>::baz(&Foo);
}