]> git.lizzy.rs Git - rust.git/blob - tests/incremental/hashes/struct_defs.rs
Rollup merge of #106244 - atouchet:readme3, r=workingjubilee
[rust.git] / tests / 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 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
20 #![allow(warnings)]
21 #![feature(rustc_attrs)]
22 #![crate_type="rlib"]
23
24 // Layout ----------------------------------------------------------------------
25 #[cfg(any(cfail1,cfail4))]
26 pub struct LayoutPacked;
27
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")]
33 #[repr(packed)]
34 pub struct LayoutPacked;
35
36 #[cfg(any(cfail1,cfail4))]
37 struct LayoutC;
38
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")]
44 #[repr(C)]
45 struct LayoutC;
46
47
48 // Tuple Struct Change Field Type ----------------------------------------------
49
50 #[cfg(any(cfail1,cfail4))]
51 struct TupleStructFieldType(i32);
52
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(
61     u32
62 );
63
64
65 // Tuple Struct Add Field ------------------------------------------------------
66
67 #[cfg(any(cfail1,cfail4))]
68 struct TupleStructAddField(i32);
69
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(
76     i32,
77     u32
78 );
79
80
81 // Tuple Struct Field Visibility -----------------------------------------------
82
83 #[cfg(any(cfail1,cfail4))]
84 struct TupleStructFieldVisibility(    char);
85
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);
92
93
94 // Record Struct Field Type ----------------------------------------------------
95
96 #[cfg(any(cfail1,cfail4))]
97 struct RecordStructFieldType { x: f32 }
98
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 {
107     x: u64
108 }
109
110
111 // Record Struct Field Name ----------------------------------------------------
112
113 #[cfg(any(cfail1,cfail4))]
114 struct RecordStructFieldName { x: f32 }
115
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 }
122
123
124 // Record Struct Add Field -----------------------------------------------------
125
126 #[cfg(any(cfail1,cfail4))]
127 struct RecordStructAddField { x: f32 }
128
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 {
135     x: f32,
136     y: () }
137
138
139 // Record Struct Field Visibility ----------------------------------------------
140
141 #[cfg(any(cfail1,cfail4))]
142 struct RecordStructFieldVisibility {     x: f32 }
143
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 }
150
151
152 // Add Lifetime Parameter ------------------------------------------------------
153
154 #[cfg(any(cfail1,cfail4))]
155 struct AddLifetimeParameter<'a>(&'a f32, &'a f64);
156
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);
163
164
165 // Add Lifetime Parameter Bound ------------------------------------------------
166
167 #[cfg(any(cfail1,cfail4))]
168 struct AddLifetimeParameterBound<'a, 'b>(&'a f32, &'b f64);
169
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>(
176     &'a f32,
177     &'b f64
178 );
179
180 #[cfg(any(cfail1,cfail4))]
181 struct AddLifetimeParameterBoundWhereClause<'a, 'b>(&'a f32, &'b f64);
182
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>(
189     &'a f32,
190     &'b f64)
191     where 'b: 'a;
192
193
194 // Add Type Parameter ----------------------------------------------------------
195
196 #[cfg(any(cfail1,cfail4))]
197 struct AddTypeParameter<T1>(T1, T1);
198
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.
207     T1,
208     T2
209 );
210
211
212 // Add Type Parameter Bound ----------------------------------------------------
213
214 #[cfg(any(cfail1,cfail4))]
215 struct AddTypeParameterBound<T>(T);
216
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>(
223     T
224 );
225
226
227 #[cfg(any(cfail1,cfail4))]
228 struct AddTypeParameterBoundWhereClause<T>(T);
229
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>(
236     T
237 ) where T: Sync;
238
239
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;
250
251
252 // Visibility ------------------------------------------------------------------
253
254 #[cfg(any(cfail1,cfail4))]
255 struct     Visibility;
256
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;
263
264 struct ReferencedType1;
265 struct ReferencedType2;
266
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;
273
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")]
278     struct TupleStruct(
279         FieldType
280     );
281 }
282
283
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;
290
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 {
296         _x: FieldType
297     }
298 }
299
300
301
302
303 trait ReferencedTrait1 {}
304 trait ReferencedTrait2 {}
305
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;
312
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);
318 }
319
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;
326
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;
332 }