1 // This test case tests the incremental compilation hash (ICH) implementation
2 // for struct definitions.
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.
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.
13 // build-pass (FIXME(62277): could be check-pass?)
14 // revisions: cfail1 cfail2 cfail3 cfail4 cfail5 cfail6
15 // compile-flags: -Z query-dep-graph
16 // [cfail1]compile-flags: -Zincremental-ignore-spans
17 // [cfail2]compile-flags: -Zincremental-ignore-spans
18 // [cfail3]compile-flags: -Zincremental-ignore-spans
19 // [cfail4]compile-flags: -Zincremental-relative-spans
20 // [cfail5]compile-flags: -Zincremental-relative-spans
21 // [cfail6]compile-flags: -Zincremental-relative-spans
24 #![feature(rustc_attrs)]
27 // Layout ----------------------------------------------------------------------
28 #[cfg(any(cfail1,cfail4))]
29 pub struct LayoutPacked;
31 #[cfg(not(any(cfail1,cfail4)))]
32 #[rustc_clean(except="type_of", cfg="cfail2")]
33 #[rustc_clean(cfg="cfail3")]
34 #[rustc_clean(except="type_of", cfg="cfail5")]
35 #[rustc_clean(cfg="cfail6")]
37 pub struct LayoutPacked;
39 #[cfg(any(cfail1,cfail4))]
42 #[cfg(not(any(cfail1,cfail4)))]
43 #[rustc_clean(except="type_of", cfg="cfail2")]
44 #[rustc_clean(cfg="cfail3")]
45 #[rustc_clean(except="type_of", cfg="cfail5")]
46 #[rustc_clean(cfg="cfail6")]
51 // Tuple Struct Change Field Type ----------------------------------------------
53 #[cfg(any(cfail1,cfail4))]
54 struct TupleStructFieldType(i32);
56 #[cfg(not(any(cfail1,cfail4)))]
57 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail2")]
58 #[rustc_clean(cfg="cfail3")]
59 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail5")]
60 #[rustc_clean(cfg="cfail6")]
61 // Note that changing the type of a field does not change the type of the struct or enum, but
62 // adding/removing fields or changing a fields name or visibility does.
63 struct TupleStructFieldType(
68 // Tuple Struct Add Field ------------------------------------------------------
70 #[cfg(any(cfail1,cfail4))]
71 struct TupleStructAddField(i32);
73 #[cfg(not(any(cfail1,cfail4)))]
74 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail2")]
75 #[rustc_clean(cfg="cfail3")]
76 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail5")]
77 #[rustc_clean(cfg="cfail6")]
78 struct TupleStructAddField(
84 // Tuple Struct Field Visibility -----------------------------------------------
86 #[cfg(any(cfail1,cfail4))]
87 struct TupleStructFieldVisibility(char);
89 #[cfg(not(any(cfail1,cfail4)))]
90 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail2")]
91 #[rustc_clean(cfg="cfail3")]
92 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail5")]
93 #[rustc_clean(cfg="cfail6")]
94 struct TupleStructFieldVisibility(pub char);
97 // Record Struct Field Type ----------------------------------------------------
99 #[cfg(any(cfail1,cfail4))]
100 struct RecordStructFieldType { x: f32 }
102 #[cfg(not(any(cfail1,cfail4)))]
103 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail2")]
104 #[rustc_clean(cfg="cfail3")]
105 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail5")]
106 #[rustc_clean(cfg="cfail6")]
107 // Note that changing the type of a field does not change the type of the struct or enum, but
108 // adding/removing fields or changing a fields name or visibility does.
109 struct RecordStructFieldType {
114 // Record Struct Field Name ----------------------------------------------------
116 #[cfg(any(cfail1,cfail4))]
117 struct RecordStructFieldName { x: f32 }
119 #[cfg(not(any(cfail1,cfail4)))]
120 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail2")]
121 #[rustc_clean(cfg="cfail3")]
122 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail5")]
123 #[rustc_clean(cfg="cfail6")]
124 struct RecordStructFieldName { y: f32 }
127 // Record Struct Add Field -----------------------------------------------------
129 #[cfg(any(cfail1,cfail4))]
130 struct RecordStructAddField { x: f32 }
132 #[cfg(not(any(cfail1,cfail4)))]
133 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail2")]
134 #[rustc_clean(cfg="cfail3")]
135 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail5")]
136 #[rustc_clean(cfg="cfail6")]
137 struct RecordStructAddField {
142 // Record Struct Field Visibility ----------------------------------------------
144 #[cfg(any(cfail1,cfail4))]
145 struct RecordStructFieldVisibility { x: f32 }
147 #[cfg(not(any(cfail1,cfail4)))]
148 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail2")]
149 #[rustc_clean(cfg="cfail3")]
150 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail5")]
151 #[rustc_clean(cfg="cfail6")]
152 struct RecordStructFieldVisibility {
157 // Add Lifetime Parameter ------------------------------------------------------
159 #[cfg(any(cfail1,cfail4))]
160 struct AddLifetimeParameter<'a>(&'a f32, &'a f64);
162 #[cfg(not(any(cfail1,cfail4)))]
163 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of,generics_of", cfg="cfail2")]
164 #[rustc_clean(cfg="cfail3")]
165 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of,generics_of", cfg="cfail5")]
166 #[rustc_clean(cfg="cfail6")]
167 struct AddLifetimeParameter<'a, 'b>(&'a f32, &'b f64);
170 // Add Lifetime Parameter Bound ------------------------------------------------
172 #[cfg(any(cfail1,cfail4))]
173 struct AddLifetimeParameterBound<'a, 'b>(&'a f32, &'b f64);
175 #[cfg(not(any(cfail1,cfail4)))]
176 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
177 #[rustc_clean(cfg="cfail3")]
178 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
179 #[rustc_clean(cfg="cfail6")]
180 struct AddLifetimeParameterBound<'a, 'b: 'a>(
185 #[cfg(any(cfail1,cfail4))]
186 struct AddLifetimeParameterBoundWhereClause<'a, 'b>(&'a f32, &'b f64);
188 #[cfg(not(any(cfail1,cfail4)))]
189 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
190 #[rustc_clean(cfg="cfail3")]
191 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
192 #[rustc_clean(cfg="cfail6")]
193 struct AddLifetimeParameterBoundWhereClause<'a, 'b>(
199 // Add Type Parameter ----------------------------------------------------------
201 #[cfg(any(cfail1,cfail4))]
202 struct AddTypeParameter<T1>(T1, T1);
204 #[cfg(not(any(cfail1,cfail4)))]
205 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of,generics_of,predicates_of", cfg="cfail2")]
206 #[rustc_clean(cfg="cfail3")]
207 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of,generics_of,predicates_of", cfg="cfail5")]
208 #[rustc_clean(cfg="cfail6")]
209 struct AddTypeParameter<T1, T2>(
210 // The field contains the parent's Generics, so it's dirty even though its
211 // type hasn't changed.
217 // Add Type Parameter Bound ----------------------------------------------------
219 #[cfg(any(cfail1,cfail4))]
220 struct AddTypeParameterBound<T>(T);
222 #[cfg(not(any(cfail1,cfail4)))]
223 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
224 #[rustc_clean(cfg="cfail3")]
225 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
226 #[rustc_clean(cfg="cfail6")]
227 struct AddTypeParameterBound<T: Send>(
232 #[cfg(any(cfail1,cfail4))]
233 struct AddTypeParameterBoundWhereClause<T>(T);
235 #[cfg(not(any(cfail1,cfail4)))]
236 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
237 #[rustc_clean(cfg="cfail3")]
238 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
239 #[rustc_clean(cfg="cfail6")]
240 struct AddTypeParameterBoundWhereClause<T>(
245 // Empty struct ----------------------------------------------------------------
246 // Since we cannot change anything in this case, we just make sure that the
247 // fingerprint is stable (i.e., that there are no random influences like memory
248 // addresses taken into account by the hashing algorithm).
249 // Note: there is no #[cfg(...)], so this is ALWAYS compiled
250 #[rustc_clean(cfg="cfail2")]
251 #[rustc_clean(cfg="cfail3")]
252 #[rustc_clean(cfg="cfail5")]
253 #[rustc_clean(cfg="cfail6")]
254 pub struct EmptyStruct;
257 // Visibility ------------------------------------------------------------------
259 #[cfg(any(cfail1,cfail4))]
262 #[cfg(not(any(cfail1,cfail4)))]
263 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail2")]
264 #[rustc_clean(cfg="cfail3")]
265 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail5")]
266 #[rustc_clean(cfg="cfail6")]
267 pub struct Visibility;
269 struct ReferencedType1;
270 struct ReferencedType2;
272 // Tuple Struct Change Field Type Indirectly -----------------------------------
273 mod tuple_struct_change_field_type_indirectly {
274 #[cfg(any(cfail1,cfail4))]
275 use super::ReferencedType1 as FieldType;
276 #[cfg(not(any(cfail1,cfail4)))]
277 use super::ReferencedType2 as FieldType;
279 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail2")]
280 #[rustc_clean(cfg="cfail3")]
281 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail5")]
282 #[rustc_clean(cfg="cfail6")]
289 // Record Struct Change Field Type Indirectly -----------------------------------
290 mod record_struct_change_field_type_indirectly {
291 #[cfg(any(cfail1,cfail4))]
292 use super::ReferencedType1 as FieldType;
293 #[cfg(not(any(cfail1,cfail4)))]
294 use super::ReferencedType2 as FieldType;
296 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail2")]
297 #[rustc_clean(cfg="cfail3")]
298 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail5")]
299 #[rustc_clean(cfg="cfail6")]
300 struct RecordStruct {
308 trait ReferencedTrait1 {}
309 trait ReferencedTrait2 {}
311 // Change Trait Bound Indirectly -----------------------------------------------
312 mod change_trait_bound_indirectly {
313 #[cfg(any(cfail1,cfail4))]
314 use super::ReferencedTrait1 as Trait;
315 #[cfg(not(any(cfail1,cfail4)))]
316 use super::ReferencedTrait2 as Trait;
318 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
319 #[rustc_clean(cfg="cfail3")]
320 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
321 #[rustc_clean(cfg="cfail6")]
322 struct Struct<T: Trait>(T);
325 // Change Trait Bound Indirectly In Where Clause -------------------------------
326 mod change_trait_bound_indirectly_in_where_clause {
327 #[cfg(any(cfail1,cfail4))]
328 use super::ReferencedTrait1 as Trait;
329 #[cfg(not(any(cfail1,cfail4)))]
330 use super::ReferencedTrait2 as Trait;
332 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
333 #[rustc_clean(cfg="cfail3")]
334 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
335 #[rustc_clean(cfg="cfail6")]
336 struct Struct<T>(T) where T : Trait;