]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/enum_constructors.rs
Auto merge of #61224 - aloucks:drain_filter, r=Gankro
[rust.git] / src / test / incremental / hashes / enum_constructors.rs
1 // This test case tests the incremental compilation hash (ICH) implementation
2 // for struct constructor expressions.
3
4 // The general pattern followed here is: Change one thing between rev1 and rev2
5 // and make sure that the hash has changed, then change nothing between rev2 and
6 // rev3 and make sure that the hash has not changed.
7
8 // build-pass (FIXME(62277): could be check-pass?)
9 // revisions: cfail1 cfail2 cfail3
10 // compile-flags: -Z query-dep-graph -Zincremental-ignore-spans
11
12 #![allow(warnings)]
13 #![feature(rustc_attrs)]
14 #![crate_type="rlib"]
15
16
17 pub enum Enum {
18     Struct {
19         x: i32,
20         y: i64,
21         z: i16,
22     },
23     Tuple(i32, i64, i16)
24 }
25
26 // Change field value (struct-like) -----------------------------------------
27 #[cfg(cfail1)]
28 pub fn change_field_value_struct_like() -> Enum {
29     Enum::Struct {
30         x: 0,
31         y: 1,
32         z: 2,
33     }
34 }
35
36 #[cfg(not(cfail1))]
37 #[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built")]
38 #[rustc_clean(cfg="cfail3")]
39 pub fn change_field_value_struct_like() -> Enum {
40     Enum::Struct {
41         x: 0,
42         y: 2,
43         z: 2,
44     }
45 }
46
47
48
49 // Change field order (struct-like) -----------------------------------------
50 #[cfg(cfail1)]
51 pub fn change_field_order_struct_like() -> Enum {
52     Enum::Struct {
53         x: 3,
54         y: 4,
55         z: 5,
56     }
57 }
58
59 #[cfg(not(cfail1))]
60 #[rustc_clean(cfg="cfail2", except="HirBody,typeck_tables_of")]
61 #[rustc_clean(cfg="cfail3")]
62 // FIXME(michaelwoerister):Interesting. I would have thought that that changes the MIR. And it
63 // would if it were not all constants
64 pub fn change_field_order_struct_like() -> Enum {
65     Enum::Struct {
66         y: 4,
67         x: 3,
68         z: 5,
69     }
70 }
71
72
73 pub enum Enum2 {
74     Struct {
75         x: i8,
76         y: i8,
77         z: i8,
78     },
79     Struct2 {
80         x: i8,
81         y: i8,
82         z: i8,
83     },
84     Tuple(u16, u16, u16),
85     Tuple2(u64, u64, u64),
86 }
87
88 // Change constructor path (struct-like) ------------------------------------
89 #[cfg(cfail1)]
90 pub fn change_constructor_path_struct_like() {
91     let _ = Enum::Struct {
92         x: 0,
93         y: 1,
94         z: 2,
95     };
96 }
97
98 #[cfg(not(cfail1))]
99 #[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built,typeck_tables_of")]
100 #[rustc_clean(cfg="cfail3")]
101 pub fn change_constructor_path_struct_like() {
102     let _ = Enum2::Struct {
103         x: 0,
104         y: 1,
105         z: 2,
106     };
107 }
108
109
110
111 // Change variant (regular struct) ------------------------------------
112 #[cfg(cfail1)]
113 pub fn change_constructor_variant_struct_like() {
114     let _ = Enum2::Struct {
115         x: 0,
116         y: 1,
117         z: 2,
118     };
119 }
120
121 #[cfg(not(cfail1))]
122 #[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built")]
123 #[rustc_clean(cfg="cfail3")]
124 pub fn change_constructor_variant_struct_like() {
125     let _ = Enum2::Struct2 {
126         x: 0,
127         y: 1,
128         z: 2,
129     };
130 }
131
132
133 // Change constructor path indirectly (struct-like) -------------------------
134 pub mod change_constructor_path_indirectly_struct_like {
135     #[cfg(cfail1)]
136     use super::Enum as TheEnum;
137     #[cfg(not(cfail1))]
138     use super::Enum2 as TheEnum;
139
140     #[rustc_clean(
141         cfg="cfail2",
142         except="fn_sig,Hir,HirBody,optimized_mir,mir_built,\
143                 typeck_tables_of"
144     )]
145     #[rustc_clean(cfg="cfail3")]
146     pub fn function() -> TheEnum {
147         TheEnum::Struct {
148             x: 0,
149             y: 1,
150             z: 2,
151         }
152     }
153 }
154
155
156 // Change constructor variant indirectly (struct-like) ---------------------------
157 pub mod change_constructor_variant_indirectly_struct_like {
158     use super::Enum2;
159     #[cfg(cfail1)]
160     use super::Enum2::Struct as Variant;
161     #[cfg(not(cfail1))]
162     use super::Enum2::Struct2 as Variant;
163
164     #[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built")]
165     #[rustc_clean(cfg="cfail3")]
166     pub fn function() -> Enum2 {
167         Variant {
168             x: 0,
169             y: 1,
170             z: 2,
171         }
172     }
173 }
174
175
176 // Change field value (tuple-like) -------------------------------------------
177 #[cfg(cfail1)]
178 pub fn change_field_value_tuple_like() -> Enum {
179     Enum::Tuple(0, 1, 2)
180 }
181
182 #[cfg(not(cfail1))]
183 #[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built")]
184 #[rustc_clean(cfg="cfail3")]
185 pub fn change_field_value_tuple_like() -> Enum {
186     Enum::Tuple(0, 1, 3)
187 }
188
189
190
191 // Change constructor path (tuple-like) --------------------------------------
192 #[cfg(cfail1)]
193 pub fn change_constructor_path_tuple_like() {
194     let _ = Enum::Tuple(0, 1, 2);
195 }
196
197 #[cfg(not(cfail1))]
198 #[rustc_clean(
199     cfg="cfail2",
200     except="HirBody,optimized_mir,mir_built,typeck_tables_of"
201 )]
202 #[rustc_clean(cfg="cfail3")]
203 pub fn change_constructor_path_tuple_like() {
204     let _ = Enum2::Tuple(0, 1, 2);
205 }
206
207
208
209 // Change constructor variant (tuple-like) --------------------------------------
210 #[cfg(cfail1)]
211 pub fn change_constructor_variant_tuple_like() {
212     let _ = Enum2::Tuple(0, 1, 2);
213 }
214
215 #[cfg(not(cfail1))]
216 #[rustc_clean(
217     cfg="cfail2",
218     except="HirBody,optimized_mir,mir_built,typeck_tables_of"
219 )]
220 #[rustc_clean(cfg="cfail3")]
221 pub fn change_constructor_variant_tuple_like() {
222     let _ = Enum2::Tuple2(0, 1, 2);
223 }
224
225
226 // Change constructor path indirectly (tuple-like) ---------------------------
227 pub mod change_constructor_path_indirectly_tuple_like {
228     #[cfg(cfail1)]
229     use super::Enum as TheEnum;
230     #[cfg(not(cfail1))]
231     use super::Enum2 as TheEnum;
232
233     #[rustc_clean(
234         cfg="cfail2",
235         except="fn_sig,Hir,HirBody,optimized_mir,mir_built,\
236                 typeck_tables_of"
237     )]
238     #[rustc_clean(cfg="cfail3")]
239     pub fn function() -> TheEnum {
240         TheEnum::Tuple(0, 1, 2)
241     }
242 }
243
244
245
246 // Change constructor variant indirectly (tuple-like) ---------------------------
247 pub mod change_constructor_variant_indirectly_tuple_like {
248     use super::Enum2;
249     #[cfg(cfail1)]
250     use super::Enum2::Tuple as Variant;
251     #[cfg(not(cfail1))]
252     use super::Enum2::Tuple2 as Variant;
253
254     #[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built,typeck_tables_of")]
255     #[rustc_clean(cfg="cfail3")]
256     pub fn function() -> Enum2 {
257         Variant(0, 1, 2)
258     }
259 }
260
261
262 pub enum Clike {
263     A,
264     B,
265     C
266 }
267
268 pub enum Clike2 {
269     B,
270     C,
271     D
272 }
273
274 // Change constructor path (C-like) --------------------------------------
275 #[cfg(cfail1)]
276 pub fn change_constructor_path_c_like() {
277     let _ = Clike::B;
278 }
279
280 #[cfg(not(cfail1))]
281 #[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built,typeck_tables_of")]
282 #[rustc_clean(cfg="cfail3")]
283 pub fn change_constructor_path_c_like() {
284     let _ = Clike2::B;
285 }
286
287
288
289 // Change constructor variant (C-like) --------------------------------------
290 #[cfg(cfail1)]
291 pub fn change_constructor_variant_c_like() {
292     let _ = Clike::A;
293 }
294
295 #[cfg(not(cfail1))]
296 #[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built")]
297 #[rustc_clean(cfg="cfail3")]
298 pub fn change_constructor_variant_c_like() {
299     let _ = Clike::C;
300 }
301
302
303 // Change constructor path indirectly (C-like) ---------------------------
304 pub mod change_constructor_path_indirectly_c_like {
305     #[cfg(cfail1)]
306     use super::Clike as TheEnum;
307     #[cfg(not(cfail1))]
308     use super::Clike2 as TheEnum;
309
310     #[rustc_clean(
311         cfg="cfail2",
312         except="fn_sig,Hir,HirBody,optimized_mir,mir_built,\
313                 typeck_tables_of"
314     )]
315     #[rustc_clean(cfg="cfail3")]
316     pub fn function() -> TheEnum {
317         TheEnum::B
318     }
319 }
320
321
322
323 // Change constructor variant indirectly (C-like) ---------------------------
324 pub mod change_constructor_variant_indirectly_c_like {
325     use super::Clike;
326     #[cfg(cfail1)]
327     use super::Clike::A as Variant;
328     #[cfg(not(cfail1))]
329     use super::Clike::B as Variant;
330
331     #[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built")]
332     #[rustc_clean(cfg="cfail3")]
333     pub fn function() -> Clike {
334         Variant
335     }
336 }