]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | // Test equality constraints on associated types. Check we get type errors | |
12 | // where we should. | |
13 | ||
14 | pub trait Foo { | |
15 | type A; | |
16 | fn boo(&self) -> <Self as Foo>::A; | |
17 | } | |
18 | ||
19 | struct Bar; | |
20 | ||
21 | impl Foo for isize { | |
22 | type A = usize; | |
23 | fn boo(&self) -> usize { | |
24 | 42 | |
25 | } | |
26 | } | |
27 | ||
28 | fn foo1<I: Foo<A=Bar>>(x: I) { | |
29 | let _: Bar = x.boo(); | |
30 | } | |
31 | ||
32 | fn foo2<I: Foo>(x: I) { | |
85aaf69f SL |
33 | let _: Bar = x.boo(); |
34 | //~^ ERROR mismatched types | |
a7813a04 XL |
35 | //~| expected type `Bar` |
36 | //~| found type `<I as Foo>::A` | |
37 | //~| expected struct `Bar`, found associated type | |
1a4d82fc JJ |
38 | } |
39 | ||
40 | ||
41 | pub fn baz(x: &Foo<A=Bar>) { | |
42 | let _: Bar = x.boo(); | |
43 | } | |
44 | ||
45 | ||
46 | pub fn main() { | |
85aaf69f SL |
47 | let a = 42; |
48 | foo1(a); | |
49 | //~^ ERROR type mismatch resolving | |
5bcae85e | 50 | //~| expected usize, found struct `Bar` |
85aaf69f SL |
51 | baz(&a); |
52 | //~^ ERROR type mismatch resolving | |
5bcae85e | 53 | //~| expected usize, found struct `Bar` |
1a4d82fc | 54 | } |