]> git.lizzy.rs Git - rust.git/blob - tests/ui/deriving/deriving-associated-types.rs
Rollup merge of #107551 - fee1-dead-contrib:rm_const_fnmut_helper, r=oli-obk
[rust.git] / tests / ui / deriving / deriving-associated-types.rs
1 // run-pass
2 pub trait DeclaredTrait {
3     type Type;
4 }
5
6 impl DeclaredTrait for i32 {
7     type Type = i32;
8 }
9
10 pub trait WhereTrait {
11     type Type;
12 }
13
14 impl WhereTrait for i32 {
15     type Type = i32;
16 }
17
18 // Make sure we don't add a bound that just shares a name with an associated
19 // type.
20 pub mod module {
21     pub type Type = i32;
22 }
23
24 #[derive(PartialEq, Debug)]
25 struct PrivateStruct<T>(T);
26
27 #[derive(PartialEq, Debug)]
28 struct TupleStruct<A, B: DeclaredTrait, C>(
29     module::Type,
30     Option<module::Type>,
31     A,
32     PrivateStruct<A>,
33     B,
34     B::Type,
35     Option<B::Type>,
36     <B as DeclaredTrait>::Type,
37     Option<<B as DeclaredTrait>::Type>,
38     C,
39     C::Type,
40     Option<C::Type>,
41     <C as WhereTrait>::Type,
42     Option<<C as WhereTrait>::Type>,
43     <i32 as DeclaredTrait>::Type,
44 ) where C: WhereTrait;
45
46 #[derive(PartialEq, Debug)]
47 pub struct Struct<A, B: DeclaredTrait, C> where C: WhereTrait {
48     m1: module::Type,
49     m2: Option<module::Type>,
50     a1: A,
51     a2: PrivateStruct<A>,
52     b: B,
53     b1: B::Type,
54     b2: Option<B::Type>,
55     b3: <B as DeclaredTrait>::Type,
56     b4: Option<<B as DeclaredTrait>::Type>,
57     c: C,
58     c1: C::Type,
59     c2: Option<C::Type>,
60     c3: <C as WhereTrait>::Type,
61     c4: Option<<C as WhereTrait>::Type>,
62     d: <i32 as DeclaredTrait>::Type,
63 }
64
65 #[derive(PartialEq, Debug)]
66 enum Enum<A, B: DeclaredTrait, C> where C: WhereTrait {
67     Unit,
68     Seq(
69         module::Type,
70         Option<module::Type>,
71         A,
72         PrivateStruct<A>,
73         B,
74         B::Type,
75         Option<B::Type>,
76         <B as DeclaredTrait>::Type,
77         Option<<B as DeclaredTrait>::Type>,
78         C,
79         C::Type,
80         Option<C::Type>,
81         <C as WhereTrait>::Type,
82         Option<<C as WhereTrait>::Type>,
83         <i32 as DeclaredTrait>::Type,
84     ),
85     Map {
86         m1: module::Type,
87         m2: Option<module::Type>,
88         a1: A,
89         a2: PrivateStruct<A>,
90         b: B,
91         b1: B::Type,
92         b2: Option<B::Type>,
93         b3: <B as DeclaredTrait>::Type,
94         b4: Option<<B as DeclaredTrait>::Type>,
95         c: C,
96         c1: C::Type,
97         c2: Option<C::Type>,
98         c3: <C as WhereTrait>::Type,
99         c4: Option<<C as WhereTrait>::Type>,
100         d: <i32 as DeclaredTrait>::Type,
101     },
102 }
103
104 fn main() {
105     let e: TupleStruct<
106         i32,
107         i32,
108         i32,
109     > = TupleStruct(
110         0,
111         None,
112         0,
113         PrivateStruct(0),
114         0,
115         0,
116         None,
117         0,
118         None,
119         0,
120         0,
121         None,
122         0,
123         None,
124         0,
125     );
126     assert_eq!(e, e);
127
128     let e: Struct<
129         i32,
130         i32,
131         i32,
132     > = Struct {
133         m1: 0,
134         m2: None,
135         a1: 0,
136         a2: PrivateStruct(0),
137         b: 0,
138         b1: 0,
139         b2: None,
140         b3: 0,
141         b4: None,
142         c: 0,
143         c1: 0,
144         c2: None,
145         c3: 0,
146         c4: None,
147         d: 0,
148     };
149     assert_eq!(e, e);
150
151     let e = Enum::Unit::<i32, i32, i32>;
152     assert_eq!(e, e);
153
154     let e: Enum<
155         i32,
156         i32,
157         i32,
158     > = Enum::Seq(
159         0,
160         None,
161         0,
162         PrivateStruct(0),
163         0,
164         0,
165         None,
166         0,
167         None,
168         0,
169         0,
170         None,
171         0,
172         None,
173         0,
174     );
175     assert_eq!(e, e);
176
177     let e: Enum<
178         i32,
179         i32,
180         i32,
181     > = Enum::Map {
182         m1: 0,
183         m2: None,
184         a1: 0,
185         a2: PrivateStruct(0),
186         b: 0,
187         b1: 0,
188         b2: None,
189         b3: 0,
190         b4: None,
191         c: 0,
192         c1: 0,
193         c2: None,
194         c3: 0,
195         c4: None,
196         d: 0,
197     };
198     assert_eq!(e, e);
199 }