]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/associated-types-eq-hr.rs
Update compile fail tests to use isize.
[rust.git] / src / test / compile-fail / associated-types-eq-hr.rs
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 // Check testing of equality constraints in a higher-ranked context.
12
13 pub trait TheTrait<T> {
14     type A;
15
16     fn get(&self, t: T) -> Self::A;
17 }
18
19 struct IntStruct {
20     x: isize
21 }
22
23 impl<'a> TheTrait<&'a isize> for IntStruct {
24     type A = &'a isize;
25
26     fn get(&self, t: &'a isize) -> &'a isize {
27         t
28     }
29 }
30
31 struct UintStruct {
32     x: isize
33 }
34
35 impl<'a> TheTrait<&'a isize> for UintStruct {
36     type A = &'a uint;
37
38     fn get(&self, t: &'a isize) -> &'a uint {
39         panic!()
40     }
41 }
42
43 fn foo<T>()
44     where T : for<'x> TheTrait<&'x isize, A = &'x isize>
45 {
46     // ok for IntStruct, but not UintStruct
47 }
48
49 fn bar<T>()
50     where T : for<'x> TheTrait<&'x isize, A = &'x uint>
51 {
52     // ok for UintStruct, but not IntStruct
53 }
54
55 fn baz<T>()
56     where T : for<'x,'y> TheTrait<&'x isize, A = &'y isize>
57 {
58     // not ok for either struct, due to the use of two lifetimes
59 }
60
61 pub fn main() {
62     foo::<IntStruct>();
63     foo::<UintStruct>(); //~ ERROR type mismatch
64
65     bar::<IntStruct>(); //~ ERROR type mismatch
66     bar::<UintStruct>();
67
68     baz::<IntStruct>(); //~ ERROR type mismatch
69     baz::<UintStruct>(); //~ ERROR type mismatch
70 }