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 -O
16 // [cfail1]compile-flags: -Zincremental-ignore-spans
17 // [cfail2]compile-flags: -Zincremental-ignore-spans
18 // [cfail3]compile-flags: -Zincremental-ignore-spans
21 #![feature(rustc_attrs)]
24 // Layout ----------------------------------------------------------------------
25 #[cfg(any(cfail1,cfail4))]
26 pub struct LayoutPacked;
28 #[cfg(not(any(cfail1,cfail4)))]
29 #[rustc_clean(except="type_of", cfg="cfail2")]
30 #[rustc_clean(cfg="cfail3")]
31 #[rustc_clean(except="type_of", cfg="cfail5")]
32 #[rustc_clean(cfg="cfail6")]
34 pub struct LayoutPacked;
36 #[cfg(any(cfail1,cfail4))]
39 #[cfg(not(any(cfail1,cfail4)))]
40 #[rustc_clean(except="type_of", cfg="cfail2")]
41 #[rustc_clean(cfg="cfail3")]
42 #[rustc_clean(except="type_of", cfg="cfail5")]
43 #[rustc_clean(cfg="cfail6")]
48 // Tuple Struct Change Field Type ----------------------------------------------
50 #[cfg(any(cfail1,cfail4))]
51 struct TupleStructFieldType(i32);
53 #[cfg(not(any(cfail1,cfail4)))]
54 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail2")]
55 #[rustc_clean(cfg="cfail3")]
56 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail5")]
57 #[rustc_clean(cfg="cfail6")]
58 // Note that changing the type of a field does not change the type of the struct or enum, but
59 // adding/removing fields or changing a fields name or visibility does.
60 struct TupleStructFieldType(
65 // Tuple Struct Add Field ------------------------------------------------------
67 #[cfg(any(cfail1,cfail4))]
68 struct TupleStructAddField(i32);
70 #[cfg(not(any(cfail1,cfail4)))]
71 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail2")]
72 #[rustc_clean(cfg="cfail3")]
73 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail5")]
74 #[rustc_clean(cfg="cfail6")]
75 struct TupleStructAddField(
81 // Tuple Struct Field Visibility -----------------------------------------------
83 #[cfg(any(cfail1,cfail4))]
84 struct TupleStructFieldVisibility( char);
86 #[cfg(not(any(cfail1,cfail4)))]
87 #[rustc_clean(cfg="cfail2", except="type_of")]
88 #[rustc_clean(cfg="cfail3")]
89 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,type_of")]
90 #[rustc_clean(cfg="cfail6")]
91 struct TupleStructFieldVisibility(pub char);
94 // Record Struct Field Type ----------------------------------------------------
96 #[cfg(any(cfail1,cfail4))]
97 struct RecordStructFieldType { x: f32 }
99 #[cfg(not(any(cfail1,cfail4)))]
100 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail2")]
101 #[rustc_clean(cfg="cfail3")]
102 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail5")]
103 #[rustc_clean(cfg="cfail6")]
104 // Note that changing the type of a field does not change the type of the struct or enum, but
105 // adding/removing fields or changing a fields name or visibility does.
106 struct RecordStructFieldType {
111 // Record Struct Field Name ----------------------------------------------------
113 #[cfg(any(cfail1,cfail4))]
114 struct RecordStructFieldName { x: f32 }
116 #[cfg(not(any(cfail1,cfail4)))]
117 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail2")]
118 #[rustc_clean(cfg="cfail3")]
119 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail5")]
120 #[rustc_clean(cfg="cfail6")]
121 struct RecordStructFieldName { y: f32 }
124 // Record Struct Add Field -----------------------------------------------------
126 #[cfg(any(cfail1,cfail4))]
127 struct RecordStructAddField { x: f32 }
129 #[cfg(not(any(cfail1,cfail4)))]
130 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail2")]
131 #[rustc_clean(cfg="cfail3")]
132 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of", cfg="cfail5")]
133 #[rustc_clean(cfg="cfail6")]
134 struct RecordStructAddField {
139 // Record Struct Field Visibility ----------------------------------------------
141 #[cfg(any(cfail1,cfail4))]
142 struct RecordStructFieldVisibility { x: f32 }
144 #[cfg(not(any(cfail1,cfail4)))]
145 #[rustc_clean(cfg="cfail2", except="type_of")]
146 #[rustc_clean(cfg="cfail3")]
147 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,type_of")]
148 #[rustc_clean(cfg="cfail6")]
149 struct RecordStructFieldVisibility { pub x: f32 }
152 // Add Lifetime Parameter ------------------------------------------------------
154 #[cfg(any(cfail1,cfail4))]
155 struct AddLifetimeParameter<'a>(&'a f32, &'a f64);
157 #[cfg(not(any(cfail1,cfail4)))]
158 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of,generics_of", cfg="cfail2")]
159 #[rustc_clean(cfg="cfail3")]
160 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of,generics_of", cfg="cfail5")]
161 #[rustc_clean(cfg="cfail6")]
162 struct AddLifetimeParameter<'a, 'b>(&'a f32, &'b f64);
165 // Add Lifetime Parameter Bound ------------------------------------------------
167 #[cfg(any(cfail1,cfail4))]
168 struct AddLifetimeParameterBound<'a, 'b>(&'a f32, &'b f64);
170 #[cfg(not(any(cfail1,cfail4)))]
171 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
172 #[rustc_clean(cfg="cfail3")]
173 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
174 #[rustc_clean(cfg="cfail6")]
175 struct AddLifetimeParameterBound<'a, 'b: 'a>(
180 #[cfg(any(cfail1,cfail4))]
181 struct AddLifetimeParameterBoundWhereClause<'a, 'b>(&'a f32, &'b f64);
183 #[cfg(not(any(cfail1,cfail4)))]
184 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
185 #[rustc_clean(cfg="cfail3")]
186 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
187 #[rustc_clean(cfg="cfail6")]
188 struct AddLifetimeParameterBoundWhereClause<'a, 'b>(
194 // Add Type Parameter ----------------------------------------------------------
196 #[cfg(any(cfail1,cfail4))]
197 struct AddTypeParameter<T1>(T1, T1);
199 #[cfg(not(any(cfail1,cfail4)))]
200 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of,generics_of,predicates_of", cfg="cfail2")]
201 #[rustc_clean(cfg="cfail3")]
202 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of,generics_of,predicates_of", cfg="cfail5")]
203 #[rustc_clean(cfg="cfail6")]
204 struct AddTypeParameter<T1, T2>(
205 // The field contains the parent's Generics, so it's dirty even though its
206 // type hasn't changed.
212 // Add Type Parameter Bound ----------------------------------------------------
214 #[cfg(any(cfail1,cfail4))]
215 struct AddTypeParameterBound<T>(T);
217 #[cfg(not(any(cfail1,cfail4)))]
218 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
219 #[rustc_clean(cfg="cfail3")]
220 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
221 #[rustc_clean(cfg="cfail6")]
222 struct AddTypeParameterBound<T: Send>(
227 #[cfg(any(cfail1,cfail4))]
228 struct AddTypeParameterBoundWhereClause<T>(T);
230 #[cfg(not(any(cfail1,cfail4)))]
231 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
232 #[rustc_clean(cfg="cfail3")]
233 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
234 #[rustc_clean(cfg="cfail6")]
235 struct AddTypeParameterBoundWhereClause<T>(
240 // Empty struct ----------------------------------------------------------------
241 // Since we cannot change anything in this case, we just make sure that the
242 // fingerprint is stable (i.e., that there are no random influences like memory
243 // addresses taken into account by the hashing algorithm).
244 // Note: there is no #[cfg(...)], so this is ALWAYS compiled
245 #[rustc_clean(cfg="cfail2")]
246 #[rustc_clean(cfg="cfail3")]
247 #[rustc_clean(cfg="cfail5")]
248 #[rustc_clean(cfg="cfail6")]
249 pub struct EmptyStruct;
252 // Visibility ------------------------------------------------------------------
254 #[cfg(any(cfail1,cfail4))]
257 #[cfg(not(any(cfail1,cfail4)))]
258 #[rustc_clean(cfg="cfail2")]
259 #[rustc_clean(cfg="cfail3")]
260 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes")]
261 #[rustc_clean(cfg="cfail6")]
262 pub struct Visibility;
264 struct ReferencedType1;
265 struct ReferencedType2;
267 // Tuple Struct Change Field Type Indirectly -----------------------------------
268 mod tuple_struct_change_field_type_indirectly {
269 #[cfg(any(cfail1,cfail4))]
270 use super::ReferencedType1 as FieldType;
271 #[cfg(not(any(cfail1,cfail4)))]
272 use super::ReferencedType2 as FieldType;
274 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail2")]
275 #[rustc_clean(cfg="cfail3")]
276 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail5")]
277 #[rustc_clean(cfg="cfail6")]
284 // Record Struct Change Field Type Indirectly -----------------------------------
285 mod record_struct_change_field_type_indirectly {
286 #[cfg(any(cfail1,cfail4))]
287 use super::ReferencedType1 as FieldType;
288 #[cfg(not(any(cfail1,cfail4)))]
289 use super::ReferencedType2 as FieldType;
291 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail2")]
292 #[rustc_clean(cfg="cfail3")]
293 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail5")]
294 #[rustc_clean(cfg="cfail6")]
295 struct RecordStruct {
303 trait ReferencedTrait1 {}
304 trait ReferencedTrait2 {}
306 // Change Trait Bound Indirectly -----------------------------------------------
307 mod change_trait_bound_indirectly {
308 #[cfg(any(cfail1,cfail4))]
309 use super::ReferencedTrait1 as Trait;
310 #[cfg(not(any(cfail1,cfail4)))]
311 use super::ReferencedTrait2 as Trait;
313 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
314 #[rustc_clean(cfg="cfail3")]
315 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
316 #[rustc_clean(cfg="cfail6")]
317 struct Struct<T: Trait>(T);
320 // Change Trait Bound Indirectly In Where Clause -------------------------------
321 mod change_trait_bound_indirectly_in_where_clause {
322 #[cfg(any(cfail1,cfail4))]
323 use super::ReferencedTrait1 as Trait;
324 #[cfg(not(any(cfail1,cfail4)))]
325 use super::ReferencedTrait2 as Trait;
327 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
328 #[rustc_clean(cfg="cfail3")]
329 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
330 #[rustc_clean(cfg="cfail6")]
331 struct Struct<T>(T) where T : Trait;