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