]> git.proxmox.com Git - rustc.git/blob - src/test/ui/associated-type-bounds/implied-region-constraints.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / ui / associated-type-bounds / implied-region-constraints.rs
1 #![feature(associated_type_bounds)]
2
3 trait Tr1 { type As1; }
4 trait Tr2 { type As2; }
5
6 struct St<'a, 'b, T: Tr1<As1: Tr2>> { // `T: 'b` is *not* implied!
7 f0: &'a T, // `T: 'a` is implied.
8 f1: &'b <T::As1 as Tr2>::As2, // `<T::As1 as Tr2>::As2: 'a` is implied.
9 }
10
11 fn _bad_st<'a, 'b, T>(x: St<'a, 'b, T>)
12 where
13 T: Tr1,
14 T::As1: Tr2,
15 {
16 // This should fail because `T: 'b` is not implied from `WF(St<'a, 'b, T>)`.
17 let _failure_proves_not_implied_outlives_region_b: &'b T = &x.f0;
18 //~^ ERROR lifetime may not live long enough
19 }
20
21 enum En7<'a, 'b, T> // `<T::As1 as Tr2>::As2: 'a` is implied.
22 where
23 T: Tr1,
24 T::As1: Tr2,
25 {
26 V0(&'a T),
27 V1(&'b <T::As1 as Tr2>::As2),
28 }
29
30 fn _bad_en7<'a, 'b, T>(x: En7<'a, 'b, T>)
31 where
32 T: Tr1,
33 T::As1: Tr2,
34 {
35 match x {
36 En7::V0(x) => {
37 // Also fails for the same reason as above:
38 let _failure_proves_not_implied_outlives_region_b: &'b T = &x;
39 //~^ ERROR lifetime may not live long enough
40 },
41 En7::V1(_) => {},
42 }
43 }
44
45 fn main() {}