]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/struct_defs.rs
Merge commit 'd3a2366ee877075c59b38bd8ced55f224fc7ef51' into sync_cg_clif-2022-07-26
[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 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
22
23 #![allow(warnings)]
24 #![feature(rustc_attrs)]
25 #![crate_type="rlib"]
26
27 // Layout ----------------------------------------------------------------------
28 #[cfg(any(cfail1,cfail4))]
29 pub struct LayoutPacked;
30
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")]
36 #[repr(packed)]
37 pub struct LayoutPacked;
38
39 #[cfg(any(cfail1,cfail4))]
40 struct LayoutC;
41
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")]
47 #[repr(C)]
48 struct LayoutC;
49
50
51 // Tuple Struct Change Field Type ----------------------------------------------
52
53 #[cfg(any(cfail1,cfail4))]
54 struct TupleStructFieldType(i32);
55
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(
64     u32
65 );
66
67
68 // Tuple Struct Add Field ------------------------------------------------------
69
70 #[cfg(any(cfail1,cfail4))]
71 struct TupleStructAddField(i32);
72
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(
79     i32,
80     u32
81 );
82
83
84 // Tuple Struct Field Visibility -----------------------------------------------
85
86 #[cfg(any(cfail1,cfail4))]
87 struct TupleStructFieldVisibility(    char);
88
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);
95
96
97 // Record Struct Field Type ----------------------------------------------------
98
99 #[cfg(any(cfail1,cfail4))]
100 struct RecordStructFieldType { x: f32 }
101
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 {
110     x: u64
111 }
112
113
114 // Record Struct Field Name ----------------------------------------------------
115
116 #[cfg(any(cfail1,cfail4))]
117 struct RecordStructFieldName { x: f32 }
118
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 }
125
126
127 // Record Struct Add Field -----------------------------------------------------
128
129 #[cfg(any(cfail1,cfail4))]
130 struct RecordStructAddField { x: f32 }
131
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 {
138     x: f32,
139     y: () }
140
141
142 // Record Struct Field Visibility ----------------------------------------------
143
144 #[cfg(any(cfail1,cfail4))]
145 struct RecordStructFieldVisibility {     x: f32 }
146
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 }
153
154
155 // Add Lifetime Parameter ------------------------------------------------------
156
157 #[cfg(any(cfail1,cfail4))]
158 struct AddLifetimeParameter<'a>(&'a f32, &'a f64);
159
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);
166
167
168 // Add Lifetime Parameter Bound ------------------------------------------------
169
170 #[cfg(any(cfail1,cfail4))]
171 struct AddLifetimeParameterBound<'a, 'b>(&'a f32, &'b f64);
172
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>(
179     &'a f32,
180     &'b f64
181 );
182
183 #[cfg(any(cfail1,cfail4))]
184 struct AddLifetimeParameterBoundWhereClause<'a, 'b>(&'a f32, &'b f64);
185
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>(
192     &'a f32,
193     &'b f64)
194     where 'b: 'a;
195
196
197 // Add Type Parameter ----------------------------------------------------------
198
199 #[cfg(any(cfail1,cfail4))]
200 struct AddTypeParameter<T1>(T1, T1);
201
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.
210     T1,
211     T2
212 );
213
214
215 // Add Type Parameter Bound ----------------------------------------------------
216
217 #[cfg(any(cfail1,cfail4))]
218 struct AddTypeParameterBound<T>(T);
219
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>(
226     T
227 );
228
229
230 #[cfg(any(cfail1,cfail4))]
231 struct AddTypeParameterBoundWhereClause<T>(T);
232
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>(
239     T
240 ) where T: Sync;
241
242
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;
253
254
255 // Visibility ------------------------------------------------------------------
256
257 #[cfg(any(cfail1,cfail4))]
258 struct     Visibility;
259
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;
266
267 struct ReferencedType1;
268 struct ReferencedType2;
269
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;
276
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")]
281     struct TupleStruct(
282         FieldType
283     );
284 }
285
286
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;
293
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 {
299         _x: FieldType
300     }
301 }
302
303
304
305
306 trait ReferencedTrait1 {}
307 trait ReferencedTrait2 {}
308
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;
315
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);
321 }
322
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;
329
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;
335 }