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