]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/struct_defs.rs
Merge pull request #2 from rust-lang/master
[rust.git] / src / test / incremental / hashes / struct_defs.rs
1 // This test case tests the incremental compilation hash (ICH) implementation
2 // for struct definitions.
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 // We also test the ICH for struct definitions exported in metadata. Same as
9 // above, we want to make sure that the change between rev1 and rev2 also
10 // results in a change of the ICH for the struct's metadata, and that it stays
11 // the same between rev2 and rev3.
12
13 // build-pass (FIXME(62277): could be check-pass?)
14 // revisions: cfail1 cfail2 cfail3
15 // compile-flags: -Z query-dep-graph -Zincremental-ignore-spans
16
17
18 #![allow(warnings)]
19 #![feature(rustc_attrs)]
20 #![crate_type="rlib"]
21
22 // Layout ----------------------------------------------------------------------
23 #[cfg(cfail1)]
24 pub struct LayoutPacked;
25
26 #[cfg(not(cfail1))]
27 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
28 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
29 #[rustc_dirty(label="type_of", cfg="cfail2")]
30 #[rustc_clean(label="generics_of", cfg="cfail2")]
31 #[rustc_clean(label="predicates_of", cfg="cfail2")]
32 #[rustc_clean(label="hir_owner", cfg="cfail3")]
33 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
34 #[rustc_clean(label="type_of", cfg="cfail3")]
35 #[rustc_clean(label="generics_of", cfg="cfail3")]
36 #[rustc_clean(label="predicates_of", cfg="cfail3")]
37 #[repr(packed)]
38 pub struct LayoutPacked;
39
40 #[cfg(cfail1)]
41 struct LayoutC;
42
43 #[cfg(not(cfail1))]
44 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
45 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
46 #[rustc_dirty(label="type_of", cfg="cfail2")]
47 #[rustc_clean(label="generics_of", cfg="cfail2")]
48 #[rustc_clean(label="predicates_of", cfg="cfail2")]
49 #[rustc_clean(label="hir_owner", cfg="cfail3")]
50 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
51 #[rustc_clean(label="type_of", cfg="cfail3")]
52 #[rustc_clean(label="generics_of", cfg="cfail3")]
53 #[rustc_clean(label="predicates_of", cfg="cfail3")]
54 #[repr(C)]
55 struct LayoutC;
56
57
58 // Tuple Struct Change Field Type ----------------------------------------------
59
60 #[cfg(cfail1)]
61 struct TupleStructFieldType(i32);
62
63 #[cfg(not(cfail1))]
64 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
65 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
66 #[rustc_clean(label="type_of", cfg="cfail2")]
67 #[rustc_clean(label="generics_of", cfg="cfail2")]
68 #[rustc_clean(label="predicates_of", cfg="cfail2")]
69 #[rustc_clean(label="hir_owner", cfg="cfail3")]
70 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
71 #[rustc_clean(label="type_of", cfg="cfail3")]
72 #[rustc_clean(label="generics_of", cfg="cfail3")]
73 #[rustc_clean(label="predicates_of", cfg="cfail3")]
74 // Note that changing the type of a field does not change the type of the struct or enum, but
75 // adding/removing fields or changing a fields name or visibility does.
76 struct TupleStructFieldType(
77     u32
78 );
79
80
81 // Tuple Struct Add Field ------------------------------------------------------
82
83 #[cfg(cfail1)]
84 struct TupleStructAddField(i32);
85
86 #[cfg(not(cfail1))]
87 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
88 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
89 #[rustc_dirty(label="type_of", cfg="cfail2")]
90 #[rustc_clean(label="generics_of", cfg="cfail2")]
91 #[rustc_clean(label="predicates_of", cfg="cfail2")]
92 #[rustc_clean(label="hir_owner", cfg="cfail3")]
93 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
94 #[rustc_clean(label="type_of", cfg="cfail3")]
95 #[rustc_clean(label="generics_of", cfg="cfail3")]
96 #[rustc_clean(label="predicates_of", cfg="cfail3")]
97 struct TupleStructAddField(
98     i32,
99     u32
100 );
101
102
103 // Tuple Struct Field Visibility -----------------------------------------------
104
105 #[cfg(cfail1)]
106 struct TupleStructFieldVisibility(char);
107
108 #[cfg(not(cfail1))]
109 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
110 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
111 #[rustc_dirty(label="type_of", cfg="cfail2")]
112 #[rustc_clean(label="generics_of", cfg="cfail2")]
113 #[rustc_clean(label="predicates_of", cfg="cfail2")]
114 #[rustc_clean(label="hir_owner", cfg="cfail3")]
115 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
116 #[rustc_clean(label="type_of", cfg="cfail3")]
117 #[rustc_clean(label="generics_of", cfg="cfail3")]
118 #[rustc_clean(label="predicates_of", cfg="cfail3")]
119 struct TupleStructFieldVisibility(pub char);
120
121
122 // Record Struct Field Type ----------------------------------------------------
123
124 #[cfg(cfail1)]
125 struct RecordStructFieldType { x: f32 }
126
127 #[cfg(not(cfail1))]
128 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
129 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
130 #[rustc_clean(label="type_of", cfg="cfail2")]
131 #[rustc_clean(label="generics_of", cfg="cfail2")]
132 #[rustc_clean(label="predicates_of", cfg="cfail2")]
133 #[rustc_clean(label="hir_owner", cfg="cfail3")]
134 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
135 #[rustc_clean(label="type_of", cfg="cfail3")]
136 #[rustc_clean(label="generics_of", cfg="cfail3")]
137 #[rustc_clean(label="predicates_of", cfg="cfail3")]
138 // Note that changing the type of a field does not change the type of the struct or enum, but
139 // adding/removing fields or changing a fields name or visibility does.
140 struct RecordStructFieldType {
141     x: u64
142 }
143
144
145 // Record Struct Field Name ----------------------------------------------------
146
147 #[cfg(cfail1)]
148 struct RecordStructFieldName { x: f32 }
149
150 #[cfg(not(cfail1))]
151 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
152 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
153 #[rustc_dirty(label="type_of", cfg="cfail2")]
154 #[rustc_clean(label="generics_of", cfg="cfail2")]
155 #[rustc_clean(label="predicates_of", cfg="cfail2")]
156 #[rustc_clean(label="hir_owner", cfg="cfail3")]
157 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
158 #[rustc_clean(label="type_of", cfg="cfail3")]
159 #[rustc_clean(label="generics_of", cfg="cfail3")]
160 #[rustc_clean(label="predicates_of", cfg="cfail3")]
161 struct RecordStructFieldName { y: f32 }
162
163
164 // Record Struct Add Field -----------------------------------------------------
165
166 #[cfg(cfail1)]
167 struct RecordStructAddField { x: f32 }
168
169 #[cfg(not(cfail1))]
170 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
171 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
172 #[rustc_dirty(label="type_of", cfg="cfail2")]
173 #[rustc_clean(label="generics_of", cfg="cfail2")]
174 #[rustc_clean(label="predicates_of", cfg="cfail2")]
175 #[rustc_clean(label="hir_owner", cfg="cfail3")]
176 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
177 #[rustc_clean(label="type_of", cfg="cfail3")]
178 #[rustc_clean(label="generics_of", cfg="cfail3")]
179 #[rustc_clean(label="predicates_of", cfg="cfail3")]
180 struct RecordStructAddField {
181     x: f32,
182     y: () }
183
184
185 // Record Struct Field Visibility ----------------------------------------------
186
187 #[cfg(cfail1)]
188 struct RecordStructFieldVisibility { x: f32 }
189
190 #[cfg(not(cfail1))]
191 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
192 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
193 #[rustc_dirty(label="type_of", cfg="cfail2")]
194 #[rustc_clean(label="generics_of", cfg="cfail2")]
195 #[rustc_clean(label="predicates_of", cfg="cfail2")]
196 #[rustc_clean(label="hir_owner", cfg="cfail3")]
197 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
198 #[rustc_clean(label="type_of", cfg="cfail3")]
199 #[rustc_clean(label="generics_of", cfg="cfail3")]
200 #[rustc_clean(label="predicates_of", cfg="cfail3")]
201 struct RecordStructFieldVisibility {
202     pub x: f32
203 }
204
205
206 // Add Lifetime Parameter ------------------------------------------------------
207
208 #[cfg(cfail1)]
209 struct AddLifetimeParameter<'a>(&'a f32, &'a f64);
210
211 #[cfg(not(cfail1))]
212 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
213 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
214 #[rustc_dirty(label="type_of", cfg="cfail2")]
215 #[rustc_dirty(label="generics_of", cfg="cfail2")]
216 #[rustc_clean(label="predicates_of", cfg="cfail2")]
217 #[rustc_clean(label="hir_owner", cfg="cfail3")]
218 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
219 #[rustc_clean(label="type_of", cfg="cfail3")]
220 #[rustc_clean(label="generics_of", cfg="cfail3")]
221 #[rustc_clean(label="predicates_of", cfg="cfail3")]
222 struct AddLifetimeParameter<'a, 'b>(&'a f32, &'b f64);
223
224
225 // Add Lifetime Parameter Bound ------------------------------------------------
226
227 #[cfg(cfail1)]
228 struct AddLifetimeParameterBound<'a, 'b>(&'a f32, &'b f64);
229
230 #[cfg(not(cfail1))]
231 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
232 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
233 #[rustc_clean(label="type_of", cfg="cfail2")]
234 #[rustc_clean(label="generics_of", cfg="cfail2")]
235 #[rustc_dirty(label="predicates_of", cfg="cfail2")]
236 #[rustc_clean(label="hir_owner", cfg="cfail3")]
237 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
238 #[rustc_clean(label="type_of", cfg="cfail3")]
239 #[rustc_clean(label="generics_of", cfg="cfail3")]
240 #[rustc_clean(label="predicates_of", cfg="cfail3")]
241 struct AddLifetimeParameterBound<'a, 'b: 'a>(
242     &'a f32,
243     &'b f64
244 );
245
246 #[cfg(cfail1)]
247 struct AddLifetimeParameterBoundWhereClause<'a, 'b>(&'a f32, &'b f64);
248
249 #[cfg(not(cfail1))]
250 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
251 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
252 #[rustc_clean(label="type_of", cfg="cfail2")]
253 #[rustc_clean(label="generics_of", cfg="cfail2")]
254 #[rustc_dirty(label="predicates_of", cfg="cfail2")]
255 #[rustc_clean(label="hir_owner", cfg="cfail3")]
256 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
257 #[rustc_clean(label="type_of", cfg="cfail3")]
258 #[rustc_clean(label="generics_of", cfg="cfail3")]
259 #[rustc_clean(label="predicates_of", cfg="cfail3")]
260 struct AddLifetimeParameterBoundWhereClause<'a, 'b>(
261     &'a f32,
262     &'b f64)
263     where 'b: 'a;
264
265
266 // Add Type Parameter ----------------------------------------------------------
267
268 #[cfg(cfail1)]
269 struct AddTypeParameter<T1>(T1, T1);
270
271 #[cfg(not(cfail1))]
272 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
273 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
274 #[rustc_dirty(label="type_of", cfg="cfail2")]
275 #[rustc_dirty(label="generics_of", cfg="cfail2")]
276 #[rustc_dirty(label="predicates_of", cfg="cfail2")]
277 #[rustc_clean(label="hir_owner", cfg="cfail3")]
278 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
279 #[rustc_clean(label="type_of", cfg="cfail3")]
280 #[rustc_clean(label="generics_of", cfg="cfail3")]
281 #[rustc_clean(label="predicates_of", cfg="cfail3")]
282 struct AddTypeParameter<T1, T2>(
283      // The field contains the parent's Generics, so it's dirty even though its
284      // type hasn't changed.
285     T1,
286     T2
287 );
288
289
290 // Add Type Parameter Bound ----------------------------------------------------
291
292 #[cfg(cfail1)]
293 struct AddTypeParameterBound<T>(T);
294
295 #[cfg(not(cfail1))]
296 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
297 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
298 #[rustc_clean(label="type_of", cfg="cfail2")]
299 #[rustc_clean(label="generics_of", cfg="cfail2")]
300 #[rustc_dirty(label="predicates_of", cfg="cfail2")]
301 #[rustc_clean(label="hir_owner", cfg="cfail3")]
302 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
303 #[rustc_clean(label="type_of", cfg="cfail3")]
304 #[rustc_clean(label="generics_of", cfg="cfail3")]
305 #[rustc_clean(label="predicates_of", cfg="cfail3")]
306 struct AddTypeParameterBound<T: Send>(
307     T
308 );
309
310
311 #[cfg(cfail1)]
312 struct AddTypeParameterBoundWhereClause<T>(T);
313
314 #[cfg(not(cfail1))]
315 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
316 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
317 #[rustc_clean(label="type_of", cfg="cfail2")]
318 #[rustc_clean(label="generics_of", cfg="cfail2")]
319 #[rustc_dirty(label="predicates_of", cfg="cfail2")]
320 #[rustc_clean(label="hir_owner", cfg="cfail3")]
321 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
322 #[rustc_clean(label="type_of", cfg="cfail3")]
323 #[rustc_clean(label="generics_of", cfg="cfail3")]
324 #[rustc_clean(label="predicates_of", cfg="cfail3")]
325 struct AddTypeParameterBoundWhereClause<T>(
326     T
327 ) where T: Sync;
328
329
330 // Empty struct ----------------------------------------------------------------
331 // Since we cannot change anything in this case, we just make sure that the
332 // fingerprint is stable (i.e., that there are no random influences like memory
333 // addresses taken into account by the hashing algorithm).
334 // Note: there is no #[cfg(...)], so this is ALWAYS compiled
335 #[rustc_clean(label="hir_owner", cfg="cfail2")]
336 #[rustc_clean(label="hir_owner_nodes", cfg="cfail2")]
337 #[rustc_clean(label="type_of", cfg="cfail2")]
338 #[rustc_clean(label="generics_of", cfg="cfail2")]
339 #[rustc_clean(label="predicates_of", cfg="cfail2")]
340 #[rustc_clean(label="hir_owner", cfg="cfail3")]
341 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
342 #[rustc_clean(label="type_of", cfg="cfail3")]
343 #[rustc_clean(label="generics_of", cfg="cfail3")]
344 #[rustc_clean(label="predicates_of", cfg="cfail3")]
345 pub struct EmptyStruct;
346
347
348 // Visibility ------------------------------------------------------------------
349
350 #[cfg(cfail1)]
351 struct Visibility;
352
353 #[cfg(not(cfail1))]
354 #[rustc_dirty(label="hir_owner", cfg="cfail2")]
355 #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
356 #[rustc_clean(label="type_of", cfg="cfail2")]
357 #[rustc_clean(label="generics_of", cfg="cfail2")]
358 #[rustc_clean(label="predicates_of", cfg="cfail2")]
359 #[rustc_clean(label="hir_owner", cfg="cfail3")]
360 #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
361 #[rustc_clean(label="type_of", cfg="cfail3")]
362 #[rustc_clean(label="generics_of", cfg="cfail3")]
363 #[rustc_clean(label="predicates_of", cfg="cfail3")]
364 pub struct Visibility;
365
366 struct ReferencedType1;
367 struct ReferencedType2;
368
369 // Tuple Struct Change Field Type Indirectly -----------------------------------
370 mod tuple_struct_change_field_type_indirectly {
371     #[cfg(cfail1)]
372     use super::ReferencedType1 as FieldType;
373     #[cfg(not(cfail1))]
374     use super::ReferencedType2 as FieldType;
375
376     #[rustc_dirty(label="hir_owner", cfg="cfail2")]
377     #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
378     #[rustc_clean(label="type_of", cfg="cfail2")]
379     #[rustc_clean(label="generics_of", cfg="cfail2")]
380     #[rustc_clean(label="predicates_of", cfg="cfail2")]
381     #[rustc_clean(label="hir_owner", cfg="cfail3")]
382     #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
383     #[rustc_clean(label="type_of", cfg="cfail3")]
384     #[rustc_clean(label="generics_of", cfg="cfail3")]
385     #[rustc_clean(label="predicates_of", cfg="cfail3")]
386     struct TupleStruct(
387         FieldType
388     );
389 }
390
391
392 // Record Struct Change Field Type Indirectly -----------------------------------
393 mod record_struct_change_field_type_indirectly {
394     #[cfg(cfail1)]
395     use super::ReferencedType1 as FieldType;
396     #[cfg(not(cfail1))]
397     use super::ReferencedType2 as FieldType;
398
399     #[rustc_dirty(label="hir_owner", cfg="cfail2")]
400     #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
401     #[rustc_clean(label="type_of", cfg="cfail2")]
402     #[rustc_clean(label="generics_of", cfg="cfail2")]
403     #[rustc_clean(label="predicates_of", cfg="cfail2")]
404     #[rustc_clean(label="hir_owner", cfg="cfail3")]
405     #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
406     #[rustc_clean(label="type_of", cfg="cfail3")]
407     #[rustc_clean(label="generics_of", cfg="cfail3")]
408     #[rustc_clean(label="predicates_of", cfg="cfail3")]
409     struct RecordStruct {
410         _x: FieldType
411     }
412 }
413
414
415
416
417 trait ReferencedTrait1 {}
418 trait ReferencedTrait2 {}
419
420 // Change Trait Bound Indirectly -----------------------------------------------
421 mod change_trait_bound_indirectly {
422     #[cfg(cfail1)]
423     use super::ReferencedTrait1 as Trait;
424     #[cfg(not(cfail1))]
425     use super::ReferencedTrait2 as Trait;
426
427     #[rustc_dirty(label="hir_owner", cfg="cfail2")]
428     #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
429     #[rustc_clean(label="type_of", cfg="cfail2")]
430     #[rustc_clean(label="generics_of", cfg="cfail2")]
431     #[rustc_dirty(label="predicates_of", cfg="cfail2")]
432     #[rustc_clean(label="hir_owner", cfg="cfail3")]
433     #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
434     #[rustc_clean(label="type_of", cfg="cfail3")]
435     #[rustc_clean(label="generics_of", cfg="cfail3")]
436     #[rustc_clean(label="predicates_of", cfg="cfail3")]
437     struct Struct<T: Trait>(T);
438 }
439
440 // Change Trait Bound Indirectly In Where Clause -------------------------------
441 mod change_trait_bound_indirectly_in_where_clause {
442     #[cfg(cfail1)]
443     use super::ReferencedTrait1 as Trait;
444     #[cfg(not(cfail1))]
445     use super::ReferencedTrait2 as Trait;
446
447     #[rustc_dirty(label="hir_owner", cfg="cfail2")]
448     #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")]
449     #[rustc_clean(label="type_of", cfg="cfail2")]
450     #[rustc_clean(label="generics_of", cfg="cfail2")]
451     #[rustc_dirty(label="predicates_of", cfg="cfail2")]
452     #[rustc_clean(label="hir_owner", cfg="cfail3")]
453     #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")]
454     #[rustc_clean(label="type_of", cfg="cfail3")]
455     #[rustc_clean(label="generics_of", cfg="cfail3")]
456     #[rustc_clean(label="predicates_of", cfg="cfail3")]
457     struct Struct<T>(T) where T : Trait;
458 }