]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/enum_constructors.rs
Rollup merge of #100022 - joboet:faster_threadid, r=joshtriplett
[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 cfail4 cfail5 cfail6
10 // compile-flags: -Z query-dep-graph -O
11 // [cfail1]compile-flags: -Zincremental-ignore-spans
12 // [cfail2]compile-flags: -Zincremental-ignore-spans
13 // [cfail3]compile-flags: -Zincremental-ignore-spans
14 // [cfail4]compile-flags: -Zincremental-relative-spans
15 // [cfail5]compile-flags: -Zincremental-relative-spans
16 // [cfail6]compile-flags: -Zincremental-relative-spans
17
18 #![allow(warnings)]
19 #![feature(rustc_attrs)]
20 #![crate_type="rlib"]
21
22
23 pub enum Enum {
24     Struct {
25         x: i32,
26         y: i64,
27         z: i16,
28     },
29     Tuple(i32, i64, i16)
30 }
31
32 // Change field value (struct-like) -----------------------------------------
33 #[cfg(any(cfail1,cfail4))]
34 pub fn change_field_value_struct_like() -> Enum {
35     Enum::Struct {
36         x: 0,
37         y: 1,
38         z: 2,
39     }
40 }
41
42 #[cfg(not(any(cfail1,cfail4)))]
43 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
44 #[rustc_clean(cfg="cfail3")]
45 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
46 #[rustc_clean(cfg="cfail6")]
47 pub fn change_field_value_struct_like() -> Enum {
48     Enum::Struct {
49         x: 0,
50         y: 2,
51         z: 2,
52     }
53 }
54
55
56
57 // Change field order (struct-like) -----------------------------------------
58 #[cfg(any(cfail1,cfail4))]
59 pub fn change_field_order_struct_like() -> Enum {
60     Enum::Struct {
61         x: 3,
62         y: 4,
63         z: 5,
64     }
65 }
66
67 #[cfg(not(any(cfail1,cfail4)))]
68 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,typeck")]
69 #[rustc_clean(cfg="cfail3")]
70 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,typeck,optimized_mir")]
71 #[rustc_clean(cfg="cfail6")]
72 // FIXME(michaelwoerister):Interesting. I would have thought that that changes the MIR. And it
73 // would if it were not all constants
74 pub fn change_field_order_struct_like() -> Enum {
75     Enum::Struct {
76         y: 4,
77         x: 3,
78         z: 5,
79     }
80 }
81
82
83 pub enum Enum2 {
84     Struct {
85         x: i8,
86         y: i8,
87         z: i8,
88     },
89     Struct2 {
90         x: i8,
91         y: i8,
92         z: i8,
93     },
94     Tuple(u16, u16, u16),
95     Tuple2(u64, u64, u64),
96 }
97
98 // Change constructor path (struct-like) ------------------------------------
99 #[cfg(any(cfail1,cfail4))]
100 pub fn change_constructor_path_struct_like() {
101     let _ = Enum ::Struct {
102         x: 0,
103         y: 1,
104         z: 2,
105     };
106 }
107
108 #[cfg(not(any(cfail1,cfail4)))]
109 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,typeck")]
110 #[rustc_clean(cfg="cfail3")]
111 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,typeck")]
112 #[rustc_clean(cfg="cfail6")]
113 pub fn change_constructor_path_struct_like() {
114     let _ = Enum2::Struct {
115         x: 0,
116         y: 1,
117         z: 2,
118     };
119 }
120
121
122
123 // Change variant (regular struct) ------------------------------------
124 #[cfg(any(cfail1,cfail4))]
125 pub fn change_constructor_variant_struct_like() {
126     let _ = Enum2::Struct  {
127         x: 0,
128         y: 1,
129         z: 2,
130     };
131 }
132
133 #[cfg(not(any(cfail1,cfail4)))]
134 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
135 #[rustc_clean(cfg="cfail3")]
136 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes")]
137 #[rustc_clean(cfg="cfail6")]
138 pub fn change_constructor_variant_struct_like() {
139     let _ = Enum2::Struct2 {
140         x: 0,
141         y: 1,
142         z: 2,
143     };
144 }
145
146
147 // Change constructor path indirectly (struct-like) -------------------------
148 pub mod change_constructor_path_indirectly_struct_like {
149     #[cfg(any(cfail1,cfail4))]
150     use super::Enum as TheEnum;
151     #[cfg(not(any(cfail1,cfail4)))]
152     use super::Enum2 as TheEnum;
153
154     #[rustc_clean(
155         cfg="cfail2",
156         except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\
157                 typeck"
158     )]
159     #[rustc_clean(cfg="cfail3")]
160     #[rustc_clean(
161         cfg="cfail5",
162         except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\
163                 typeck"
164     )]
165     #[rustc_clean(cfg="cfail6")]
166     pub fn function() -> TheEnum {
167         TheEnum::Struct {
168             x: 0,
169             y: 1,
170             z: 2,
171         }
172     }
173 }
174
175
176 // Change constructor variant indirectly (struct-like) ---------------------------
177 pub mod change_constructor_variant_indirectly_struct_like {
178     use super::Enum2;
179     #[cfg(any(cfail1,cfail4))]
180     use super::Enum2::Struct as Variant;
181     #[cfg(not(any(cfail1,cfail4)))]
182     use super::Enum2::Struct2 as Variant;
183
184     #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
185     #[rustc_clean(cfg="cfail3")]
186     #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
187     #[rustc_clean(cfg="cfail6")]
188     pub fn function() -> Enum2 {
189         Variant {
190             x: 0,
191             y: 1,
192             z: 2,
193         }
194     }
195 }
196
197
198 // Change field value (tuple-like) -------------------------------------------
199 #[cfg(any(cfail1,cfail4))]
200 pub fn change_field_value_tuple_like() -> Enum {
201     Enum::Tuple(0, 1, 2)
202 }
203
204 #[cfg(not(any(cfail1,cfail4)))]
205 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
206 #[rustc_clean(cfg="cfail3")]
207 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
208 #[rustc_clean(cfg="cfail6")]
209 pub fn change_field_value_tuple_like() -> Enum {
210     Enum::Tuple(0, 1, 3)
211 }
212
213
214
215 // Change constructor path (tuple-like) --------------------------------------
216 #[cfg(any(cfail1,cfail4))]
217 pub fn change_constructor_path_tuple_like() {
218     let _ = Enum ::Tuple(0, 1, 2);
219 }
220
221 #[cfg(not(any(cfail1,cfail4)))]
222 #[rustc_clean(
223     cfg="cfail2",
224     except="hir_owner_nodes,typeck"
225 )]
226 #[rustc_clean(cfg="cfail3")]
227 #[rustc_clean(
228     cfg="cfail5",
229     except="hir_owner_nodes,typeck"
230 )]
231 #[rustc_clean(cfg="cfail6")]
232 pub fn change_constructor_path_tuple_like() {
233     let _ = Enum2::Tuple(0, 1, 2);
234 }
235
236
237
238 // Change constructor variant (tuple-like) --------------------------------------
239 #[cfg(any(cfail1,cfail4))]
240 pub fn change_constructor_variant_tuple_like() {
241     let _ = Enum2::Tuple (0, 1, 2);
242 }
243
244 #[cfg(not(any(cfail1,cfail4)))]
245 #[rustc_clean(
246     cfg="cfail2",
247     except="hir_owner_nodes,typeck"
248 )]
249 #[rustc_clean(cfg="cfail3")]
250 #[rustc_clean(
251     cfg="cfail5",
252     except="hir_owner_nodes,typeck"
253 )]
254 #[rustc_clean(cfg="cfail6")]
255 pub fn change_constructor_variant_tuple_like() {
256     let _ = Enum2::Tuple2(0, 1, 2);
257 }
258
259
260 // Change constructor path indirectly (tuple-like) ---------------------------
261 pub mod change_constructor_path_indirectly_tuple_like {
262     #[cfg(any(cfail1,cfail4))]
263     use super::Enum as TheEnum;
264     #[cfg(not(any(cfail1,cfail4)))]
265     use super::Enum2 as TheEnum;
266
267     #[rustc_clean(
268         cfg="cfail2",
269         except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\
270                 typeck"
271     )]
272     #[rustc_clean(cfg="cfail3")]
273     #[rustc_clean(
274         cfg="cfail5",
275         except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\
276                 typeck"
277     )]
278     #[rustc_clean(cfg="cfail6")]
279     pub fn function() -> TheEnum {
280         TheEnum::Tuple(0, 1, 2)
281     }
282 }
283
284
285
286 // Change constructor variant indirectly (tuple-like) ---------------------------
287 pub mod change_constructor_variant_indirectly_tuple_like {
288     use super::Enum2;
289     #[cfg(any(cfail1,cfail4))]
290     use super::Enum2::Tuple as Variant;
291     #[cfg(not(any(cfail1,cfail4)))]
292     use super::Enum2::Tuple2 as Variant;
293
294     #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck")]
295     #[rustc_clean(cfg="cfail3")]
296     #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir,typeck")]
297     #[rustc_clean(cfg="cfail6")]
298     pub fn function() -> Enum2 {
299         Variant(0, 1, 2)
300     }
301 }
302
303
304 pub enum Clike {
305     A,
306     B,
307     C
308 }
309
310 pub enum Clike2 {
311     B,
312     C,
313     D
314 }
315
316 // Change constructor path (C-like) --------------------------------------
317 #[cfg(any(cfail1,cfail4))]
318 pub fn change_constructor_path_c_like() {
319     let _x = Clike ::B;
320 }
321
322 #[cfg(not(any(cfail1,cfail4)))]
323 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck")]
324 #[rustc_clean(cfg="cfail3")]
325 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir,typeck")]
326 #[rustc_clean(cfg="cfail6")]
327 pub fn change_constructor_path_c_like() {
328     let _x = Clike2::B;
329 }
330
331
332
333 // Change constructor variant (C-like) --------------------------------------
334 #[cfg(any(cfail1,cfail4))]
335 pub fn change_constructor_variant_c_like() {
336     let _x = Clike::A;
337 }
338
339 #[cfg(not(any(cfail1,cfail4)))]
340 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
341 #[rustc_clean(cfg="cfail3")]
342 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes")]
343 #[rustc_clean(cfg="cfail6")]
344 pub fn change_constructor_variant_c_like() {
345     let _x = Clike::C;
346 }
347
348
349 // Change constructor path indirectly (C-like) ---------------------------
350 pub mod change_constructor_path_indirectly_c_like {
351     #[cfg(any(cfail1,cfail4))]
352     use super::Clike as TheEnum;
353     #[cfg(not(any(cfail1,cfail4)))]
354     use super::Clike2 as TheEnum;
355
356     #[rustc_clean(
357         cfg="cfail2",
358         except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\
359                 typeck"
360     )]
361     #[rustc_clean(cfg="cfail3")]
362     #[rustc_clean(
363         cfg="cfail5",
364         except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\
365                 typeck"
366     )]
367     #[rustc_clean(cfg="cfail6")]
368     pub fn function() -> TheEnum {
369         TheEnum::B
370     }
371 }
372
373
374
375 // Change constructor variant indirectly (C-like) ---------------------------
376 pub mod change_constructor_variant_indirectly_c_like {
377     use super::Clike;
378     #[cfg(any(cfail1,cfail4))]
379     use super::Clike::A as Variant;
380     #[cfg(not(any(cfail1,cfail4)))]
381     use super::Clike::B as Variant;
382
383     #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
384     #[rustc_clean(cfg="cfail3")]
385     #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
386     #[rustc_clean(cfg="cfail6")]
387     pub fn function() -> Clike {
388         Variant
389     }
390 }