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
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(cfg="cfail2", except="type_of")]
91 #[rustc_clean(cfg="cfail3")]
92 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,type_of")]
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(cfg="cfail2", except="type_of")]
149 #[rustc_clean(cfg="cfail3")]
150 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,type_of")]
151 #[rustc_clean(cfg="cfail6")]
152 struct RecordStructFieldVisibility { pub x: f32 }
155 // Add Lifetime Parameter ------------------------------------------------------
157 #[cfg(any(cfail1,cfail4))]
158 struct AddLifetimeParameter
<'a
>(&'a
f32, &'a
f64);
160 #[cfg(not(any(cfail1,cfail4)))]
161 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of,generics_of", cfg="cfail2")]
162 #[rustc_clean(cfg="cfail3")]
163 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of,generics_of", cfg="cfail5")]
164 #[rustc_clean(cfg="cfail6")]
165 struct AddLifetimeParameter
<'a
, 'b
>(&'a
f32, &'b
f64);
168 // Add Lifetime Parameter Bound ------------------------------------------------
170 #[cfg(any(cfail1,cfail4))]
171 struct AddLifetimeParameterBound
<'a
, 'b
>(&'a
f32, &'b
f64);
173 #[cfg(not(any(cfail1,cfail4)))]
174 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
175 #[rustc_clean(cfg="cfail3")]
176 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
177 #[rustc_clean(cfg="cfail6")]
178 struct AddLifetimeParameterBound
<'a
, 'b
: 'a
>(
183 #[cfg(any(cfail1,cfail4))]
184 struct AddLifetimeParameterBoundWhereClause
<'a
, 'b
>(&'a
f32, &'b
f64);
186 #[cfg(not(any(cfail1,cfail4)))]
187 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
188 #[rustc_clean(cfg="cfail3")]
189 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
190 #[rustc_clean(cfg="cfail6")]
191 struct AddLifetimeParameterBoundWhereClause
<'a
, 'b
>(
197 // Add Type Parameter ----------------------------------------------------------
199 #[cfg(any(cfail1,cfail4))]
200 struct AddTypeParameter
<T1
>(T1
, T1
);
202 #[cfg(not(any(cfail1,cfail4)))]
203 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of,generics_of,predicates_of", cfg="cfail2")]
204 #[rustc_clean(cfg="cfail3")]
205 #[rustc_clean(except="hir_owner,hir_owner_nodes,type_of,generics_of,predicates_of", cfg="cfail5")]
206 #[rustc_clean(cfg="cfail6")]
207 struct AddTypeParameter
<T1
, T2
>(
208 // The field contains the parent's Generics, so it's dirty even though its
209 // type hasn't changed.
215 // Add Type Parameter Bound ----------------------------------------------------
217 #[cfg(any(cfail1,cfail4))]
218 struct AddTypeParameterBound
<T
>(T
);
220 #[cfg(not(any(cfail1,cfail4)))]
221 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
222 #[rustc_clean(cfg="cfail3")]
223 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
224 #[rustc_clean(cfg="cfail6")]
225 struct AddTypeParameterBound
<T
: Send
>(
230 #[cfg(any(cfail1,cfail4))]
231 struct AddTypeParameterBoundWhereClause
<T
>(T
);
233 #[cfg(not(any(cfail1,cfail4)))]
234 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
235 #[rustc_clean(cfg="cfail3")]
236 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
237 #[rustc_clean(cfg="cfail6")]
238 struct AddTypeParameterBoundWhereClause
<T
>(
243 // Empty struct ----------------------------------------------------------------
244 // Since we cannot change anything in this case, we just make sure that the
245 // fingerprint is stable (i.e., that there are no random influences like memory
246 // addresses taken into account by the hashing algorithm).
247 // Note: there is no #[cfg(...)], so this is ALWAYS compiled
248 #[rustc_clean(cfg="cfail2")]
249 #[rustc_clean(cfg="cfail3")]
250 #[rustc_clean(cfg="cfail5")]
251 #[rustc_clean(cfg="cfail6")]
252 pub struct EmptyStruct
;
255 // Visibility ------------------------------------------------------------------
257 #[cfg(any(cfail1,cfail4))]
260 #[cfg(not(any(cfail1,cfail4)))]
261 #[rustc_clean(cfg="cfail2")]
262 #[rustc_clean(cfg="cfail3")]
263 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes")]
264 #[rustc_clean(cfg="cfail6")]
265 pub struct Visibility
;
267 struct ReferencedType1
;
268 struct ReferencedType2
;
270 // Tuple Struct Change Field Type Indirectly -----------------------------------
271 mod tuple_struct_change_field_type_indirectly
{
272 #[cfg(any(cfail1,cfail4))]
273 use super::ReferencedType1
as FieldType
;
274 #[cfg(not(any(cfail1,cfail4)))]
275 use super::ReferencedType2
as FieldType
;
277 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail2")]
278 #[rustc_clean(cfg="cfail3")]
279 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail5")]
280 #[rustc_clean(cfg="cfail6")]
287 // Record Struct Change Field Type Indirectly -----------------------------------
288 mod record_struct_change_field_type_indirectly
{
289 #[cfg(any(cfail1,cfail4))]
290 use super::ReferencedType1
as FieldType
;
291 #[cfg(not(any(cfail1,cfail4)))]
292 use super::ReferencedType2
as FieldType
;
294 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail2")]
295 #[rustc_clean(cfg="cfail3")]
296 #[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail5")]
297 #[rustc_clean(cfg="cfail6")]
298 struct RecordStruct
{
306 trait ReferencedTrait1 {}
307 trait ReferencedTrait2 {}
309 // Change Trait Bound Indirectly -----------------------------------------------
310 mod change_trait_bound_indirectly
{
311 #[cfg(any(cfail1,cfail4))]
312 use super::ReferencedTrait1
as Trait
;
313 #[cfg(not(any(cfail1,cfail4)))]
314 use super::ReferencedTrait2
as Trait
;
316 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
317 #[rustc_clean(cfg="cfail3")]
318 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
319 #[rustc_clean(cfg="cfail6")]
320 struct Struct
<T
: Trait
>(T
);
323 // Change Trait Bound Indirectly In Where Clause -------------------------------
324 mod change_trait_bound_indirectly_in_where_clause
{
325 #[cfg(any(cfail1,cfail4))]
326 use super::ReferencedTrait1
as Trait
;
327 #[cfg(not(any(cfail1,cfail4)))]
328 use super::ReferencedTrait2
as Trait
;
330 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail2")]
331 #[rustc_clean(cfg="cfail3")]
332 #[rustc_clean(except="hir_owner,hir_owner_nodes,predicates_of", cfg="cfail5")]
333 #[rustc_clean(cfg="cfail6")]
334 struct Struct
<T
>(T
) where T
: Trait
;