]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/associated-types-eq-hr.rs
Rollup merge of #76468 - SNCPlay42:lifetime-names, r=Mark-Simulacrum
[rust.git] / src / test / ui / associated-types / associated-types-eq-hr.rs
1 // Check testing of equality constraints in a higher-ranked context.
2
3 pub trait TheTrait<T> {
4     type A;
5
6     fn get(&self, t: T) -> Self::A;
7 }
8
9 struct IntStruct {
10     x: isize,
11 }
12
13 impl<'a> TheTrait<&'a isize> for IntStruct {
14     type A = &'a isize;
15
16     fn get(&self, t: &'a isize) -> &'a isize {
17         t
18     }
19 }
20
21 struct UintStruct {
22     x: isize,
23 }
24
25 impl<'a> TheTrait<&'a isize> for UintStruct {
26     type A = &'a usize;
27
28     fn get(&self, t: &'a isize) -> &'a usize {
29         panic!()
30     }
31 }
32
33 struct Tuple {}
34
35 impl<'a> TheTrait<(&'a isize, &'a isize)> for Tuple {
36     type A = &'a isize;
37
38     fn get(&self, t: (&'a isize, &'a isize)) -> &'a isize {
39         t.0
40     }
41 }
42
43 fn foo<T>()
44 where
45     T: for<'x> TheTrait<&'x isize, A = &'x isize>,
46 {
47     // ok for IntStruct, but not UintStruct
48 }
49
50 fn bar<T>()
51 where
52     T: for<'x> TheTrait<&'x isize, A = &'x usize>,
53 {
54     // ok for UintStruct, but not IntStruct
55 }
56
57 fn tuple_one<T>()
58 where
59     T: for<'x, 'y> TheTrait<(&'x isize, &'y isize), A = &'x isize>,
60 {
61     // not ok for tuple, two lifetimes and we pick first
62 }
63
64 fn tuple_two<T>()
65 where
66     T: for<'x, 'y> TheTrait<(&'x isize, &'y isize), A = &'y isize>,
67 {
68     // not ok for tuple, two lifetimes and we pick second
69 }
70
71 fn tuple_three<T>()
72 where
73     T: for<'x> TheTrait<(&'x isize, &'x isize), A = &'x isize>,
74 {
75     // ok for tuple
76 }
77
78 fn tuple_four<T>()
79 where
80     T: for<'x, 'y> TheTrait<(&'x isize, &'y isize)>,
81 {
82     // not ok for tuple, two lifetimes, and lifetime matching is invariant
83 }
84
85 pub fn call_foo() {
86     foo::<IntStruct>();
87     foo::<UintStruct>(); //~ ERROR type mismatch
88 }
89
90 pub fn call_bar() {
91     bar::<IntStruct>(); //~ ERROR type mismatch
92     bar::<UintStruct>();
93 }
94
95 pub fn call_tuple_one() {
96     tuple_one::<Tuple>();
97     //~^ ERROR implementation of `TheTrait` is not general enough
98     //~| ERROR implementation of `TheTrait` is not general enough
99 }
100
101 pub fn call_tuple_two() {
102     tuple_two::<Tuple>();
103     //~^ ERROR implementation of `TheTrait` is not general enough
104     //~| ERROR implementation of `TheTrait` is not general enough
105 }
106
107 pub fn call_tuple_three() {
108     tuple_three::<Tuple>();
109 }
110
111 pub fn call_tuple_four() {
112     tuple_four::<Tuple>();
113     //~^ ERROR implementation of `TheTrait` is not general enough
114 }
115
116 fn main() {}