mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 02:33:55 +00:00
31 lines
509 B
Rust
31 lines
509 B
Rust
//@ run-pass
|
|
|
|
struct Foo;
|
|
|
|
trait Trait {
|
|
fn bar(&self); //~ WARN method `bar` is never used
|
|
}
|
|
|
|
// Inherent impls should be preferred over trait ones.
|
|
impl Foo {
|
|
fn bar(&self) {}
|
|
}
|
|
|
|
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.
|
|
<dyn Trait>::baz(&Foo);
|
|
}
|