]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/struct_defs.rs
Rollup merge of #93746 - cjgillot:nodefii, r=nikomatsakis
[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
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(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);
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(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 {
153     pub x: f32
154 }
155
156
157 // Add Lifetime Parameter ------------------------------------------------------
158
159 #[cfg(any(cfail1,cfail4))]
160 struct AddLifetimeParameter<'a>(&'a f32, &'a f64);
161
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);
168
169
170 // Add Lifetime Parameter Bound ------------------------------------------------
171
172 #[cfg(any(cfail1,cfail4))]
173 struct AddLifetimeParameterBound<'a, 'b>(&'a f32, &'b f64);
174
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>(
181     &'a f32,
182     &'b f64
183 );
184
185 #[cfg(any(cfail1,cfail4))]
186 struct AddLifetimeParameterBoundWhereClause<'a, 'b>(&'a f32, &'b f64);
187
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>(
194     &'a f32,
195     &'b f64)
196     where 'b: 'a;
197
198
199 // Add Type Parameter ----------------------------------------------------------
200
201 #[cfg(any(cfail1,cfail4))]
202 struct AddTypeParameter<T1>(T1, T1);
203
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.
212     T1,
213     T2
214 );
215
216
217 // Add Type Parameter Bound ----------------------------------------------------
218
219 #[cfg(any(cfail1,cfail4))]
220 struct AddTypeParameterBound<T>(T);
221
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>(
228     T
229 );
230
231
232 #[cfg(any(cfail1,cfail4))]
233 struct AddTypeParameterBoundWhereClause<T>(T);
234
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>(
241     T
242 ) where T: Sync;
243
244
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;
255
256
257 // Visibility ------------------------------------------------------------------
258
259 #[cfg(any(cfail1,cfail4))]
260 struct Visibility;
261
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;
268
269 struct ReferencedType1;
270 struct ReferencedType2;
271
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;
278
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")]
283     struct TupleStruct(
284         FieldType
285     );
286 }
287
288
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;
295
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 {
301         _x: FieldType
302     }
303 }
304
305
306
307
308 trait ReferencedTrait1 {}
309 trait ReferencedTrait2 {}
310
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;
317
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);
323 }
324
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;
331
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;
337 }