]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/associated-types-eq-3.rs
Rollup merge of #76468 - SNCPlay42:lifetime-names, r=Mark-Simulacrum
[rust.git] / src / test / ui / associated-types / associated-types-eq-3.rs
1 // Test equality constraints on associated types. Check we get type errors
2 // where we should.
3
4 pub trait Foo {
5     type A;
6     fn boo(&self) -> <Self as Foo>::A;
7 }
8
9 struct Bar;
10
11 impl Foo for isize {
12     type A = usize;
13     fn boo(&self) -> usize {
14         42
15     }
16 }
17
18 fn foo1<I: Foo<A=Bar>>(x: I) {
19     let _: Bar = x.boo();
20 }
21
22 fn foo2<I: Foo>(x: I) {
23     let _: Bar = x.boo();
24     //~^ ERROR mismatched types
25     //~| found associated type `<I as Foo>::A`
26     //~| expected struct `Bar`, found associated type
27     //~| expected struct `Bar`
28 }
29
30
31 pub fn baz(x: &dyn Foo<A=Bar>) {
32     let _: Bar = x.boo();
33 }
34
35
36 pub fn main() {
37     let a = 42;
38     foo1(a);
39     //~^ ERROR type mismatch resolving
40     //~| expected struct `Bar`, found `usize`
41     baz(&a);
42     //~^ ERROR type mismatch resolving
43     //~| expected struct `Bar`, found `usize`
44 }