]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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) { | |
85aaf69f SL |
23 | let _: Bar = x.boo(); |
24 | //~^ ERROR mismatched types | |
60c5eb7d | 25 | //~| found associated type `<I as Foo>::A` |
a7813a04 | 26 | //~| expected struct `Bar`, found associated type |
60c5eb7d | 27 | //~| expected struct `Bar` |
1a4d82fc JJ |
28 | } |
29 | ||
30 | ||
dc9dc135 | 31 | pub fn baz(x: &dyn Foo<A=Bar>) { |
1a4d82fc JJ |
32 | let _: Bar = x.boo(); |
33 | } | |
34 | ||
35 | ||
36 | pub fn main() { | |
85aaf69f SL |
37 | let a = 42; |
38 | foo1(a); | |
39 | //~^ ERROR type mismatch resolving | |
85aaf69f SL |
40 | baz(&a); |
41 | //~^ ERROR type mismatch resolving | |
1a4d82fc | 42 | } |