]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/impl-inherent-prefer-over-trait.rs
:arrow_up: rust-analyzer
[rust.git] / src / test / ui / traits / impl-inherent-prefer-over-trait.rs
1 // run-pass
2
3 struct Foo;
4
5 trait Trait {
6     fn bar(&self);
7 }
8
9 // Inherent impls should be preferred over trait ones.
10 impl Foo {
11     fn bar(&self) {}
12 }
13
14 impl dyn Trait {
15     fn baz(_: &Foo) {}
16 }
17
18 impl Trait for Foo {
19     fn bar(&self) { panic!("wrong method called!") }
20 }
21
22 fn main() {
23     Foo.bar();
24     Foo::bar(&Foo);
25     <Foo>::bar(&Foo);
26
27     // Should work even if Trait::baz doesn't exist.
28     // N.B: `<Trait>::bar` would be ambiguous.
29     <dyn Trait>::baz(&Foo);
30 }