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