2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2015-02-19 03:37:25 +02:00
|
|
|
struct Foo;
|
|
|
|
|
|
|
|
trait Trait {
|
2024-02-07 10:42:01 +08:00
|
|
|
fn bar(&self); //~ WARN method `bar` is never used
|
2015-02-19 03:37:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Inherent impls should be preferred over trait ones.
|
|
|
|
impl Foo {
|
|
|
|
fn bar(&self) {}
|
|
|
|
}
|
|
|
|
|
2019-05-28 14:47:21 -04:00
|
|
|
impl dyn Trait {
|
2015-02-19 03:37:25 +02:00
|
|
|
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 14:47:21 -04:00
|
|
|
<dyn Trait>::baz(&Foo);
|
2015-02-19 03:37:25 +02:00
|
|
|
}
|