]> git.proxmox.com Git - rustc.git/blob - tests/ui/associated-type-bounds/enum-bounds.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / associated-type-bounds / enum-bounds.rs
1 // run-pass
2
3 #![feature(associated_type_bounds)]
4 #![allow(dead_code)]
5
6 trait Tr1 { type As1; }
7 trait Tr2 { type As2; }
8 trait Tr3 { type As3; }
9 trait Tr4<'a> { type As4; }
10 trait Tr5 { type As5; }
11
12 impl Tr1 for &str { type As1 = bool; }
13 impl Tr2 for bool { type As2 = u8; }
14 impl Tr3 for u8 { type As3 = fn() -> u8; }
15 impl Tr1 for () { type As1 = (usize,); }
16 impl<'a> Tr4<'a> for (usize,) { type As4 = u8; }
17 impl Tr5 for bool { type As5 = u16; }
18
19 enum En1<T: Tr1<As1: Tr2>> {
20 Outest(T),
21 Outer(T::As1),
22 Inner(<T::As1 as Tr2>::As2),
23 }
24
25 fn wrap_en1_1<T>(x: T) -> En1<T> where T: Tr1, T::As1: Tr2 {
26 En1::Outest(x)
27 }
28
29 fn wrap_en1_2<T>(x: T::As1) -> En1<T> where T: Tr1, T::As1: Tr2 {
30 En1::Outer(x)
31 }
32
33 fn wrap_en1_3<T>(x: <T::As1 as Tr2>::As2) -> En1<T> where T: Tr1, T::As1: Tr2 {
34 En1::Inner(x)
35 }
36
37 enum En2<T: Tr1<As1: Tr2<As2: Tr3>>> {
38 V0(T),
39 V1(T::As1),
40 V2(<T::As1 as Tr2>::As2),
41 V3(<<T::As1 as Tr2>::As2 as Tr3>::As3),
42 }
43
44 enum En3<T: Tr1<As1: 'static>> {
45 V0(T),
46 V1(&'static T::As1),
47 }
48
49 enum En4<'x1, 'x2, T: Tr1<As1: for<'l> Tr4<'l>>> {
50 V0(&'x1 <T::As1 as Tr4<'x1>>::As4),
51 V1(&'x2 <T::As1 as Tr4<'x2>>::As4),
52 }
53
54 enum _En5<'x1, 'x2, T: Tr1<As1: for<'l> Tr4<'l, As4: Copy>>> {
55 _V0(&'x1 <T::As1 as Tr4<'x1>>::As4),
56 _V1(&'x2 <T::As1 as Tr4<'x2>>::As4),
57 }
58
59 enum En6<T>
60 where
61 T: Tr1<As1: Tr2 + 'static + Tr5>,
62 {
63 V0(T),
64 V1(<T::As1 as Tr2>::As2),
65 V2(&'static T::As1),
66 V3(<T::As1 as Tr5>::As5),
67 }
68
69 enum _En7<'a, 'b, T> // `<T::As1 as Tr2>::As2: 'a` is implied.
70 where
71 T: Tr1<As1: Tr2>,
72 {
73 V0(&'a T),
74 V1(&'b <T::As1 as Tr2>::As2),
75 }
76
77 fn _make_en7<'a, 'b, T>(x: _En7<'a, 'b, T>)
78 where
79 T: Tr1<As1: Tr2>,
80 {
81 match x {
82 _En7::V0(x) => {
83 let _: &'a T = &x;
84 },
85 _En7::V1(_) => {},
86 }
87 }
88
89 enum EnSelf<T> where Self: Tr1<As1: Tr2> {
90 V0(T),
91 V1(<Self as Tr1>::As1),
92 V2(<<Self as Tr1>::As1 as Tr2>::As2),
93 }
94
95 impl Tr1 for EnSelf<&'static str> { type As1 = bool; }
96
97 fn main() {
98 if let En1::Outest("foo") = wrap_en1_1::<_>("foo") {} else { panic!() };
99 if let En1::Outer(true) = wrap_en1_2::<&str>(true) {} else { panic!() };
100 if let En1::Inner(24u8) = wrap_en1_3::<&str>(24u8) {} else { panic!() };
101
102 let _ = En2::<_>::V0("151571");
103 let _ = En2::<&str>::V1(false);
104 let _ = En2::<&str>::V2(42u8);
105 let _ = En2::<&str>::V3(|| 12u8);
106
107 let _ = En3::<_>::V0("deadbeef");
108 let _ = En3::<&str>::V1(&true);
109
110 let f1 = (1,);
111 let f2 = (2,);
112 let _ = En4::<()>::V0(&f1.0);
113 let _ = En4::<()>::V1(&f2.0);
114
115 let _ = En6::<_>::V0("bar");
116 let _ = En6::<&str>::V1(24u8);
117 let _ = En6::<&str>::V2(&false);
118 let _ = En6::<&str>::V3(12u16);
119
120 let _ = EnSelf::<_>::V0("foo");
121 let _ = EnSelf::<&'static str>::V1(true);
122 let _ = EnSelf::<&'static str>::V2(24u8);
123 }