]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/struct_defs.rs
Rollup merge of #41141 - michaelwoerister:direct-metadata-ich-final, r=nikomatsakis
[rust.git] / src / test / incremental / hashes / struct_defs.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12 // This test case tests the incremental compilation hash (ICH) implementation
13 // for struct definitions.
14
15 // The general pattern followed here is: Change one thing between rev1 and rev2
16 // and make sure that the hash has changed, then change nothing between rev2 and
17 // rev3 and make sure that the hash has not changed.
18
19 // We also test the ICH for struct definitions exported in metadata. Same as
20 // above, we want to make sure that the change between rev1 and rev2 also
21 // results in a change of the ICH for the struct's metadata, and that it stays
22 // the same between rev2 and rev3.
23
24 // must-compile-successfully
25 // revisions: cfail1 cfail2 cfail3
26 // compile-flags: -Z query-dep-graph
27
28
29 #![allow(warnings)]
30 #![feature(rustc_attrs)]
31 #![crate_type="rlib"]
32
33 // Layout ----------------------------------------------------------------------
34 #[cfg(cfail1)]
35 pub struct LayoutPacked;
36
37 #[cfg(not(cfail1))]
38 #[rustc_dirty(label="Hir", cfg="cfail2")]
39 #[rustc_clean(label="Hir", cfg="cfail3")]
40 #[rustc_metadata_dirty(cfg="cfail2")]
41 #[rustc_metadata_clean(cfg="cfail3")]
42 #[repr(packed)]
43 pub struct LayoutPacked;
44
45 #[cfg(cfail1)]
46 struct LayoutC;
47
48 #[cfg(not(cfail1))]
49 #[rustc_dirty(label="Hir", cfg="cfail2")]
50 #[rustc_clean(label="Hir", cfg="cfail3")]
51 #[rustc_metadata_dirty(cfg="cfail2")]
52 #[rustc_metadata_clean(cfg="cfail3")]
53 #[repr(C)]
54 struct LayoutC;
55
56
57 // Tuple Struct Change Field Type ----------------------------------------------
58
59 #[cfg(cfail1)]
60 struct TupleStructFieldType(i32);
61
62 #[cfg(not(cfail1))]
63 #[rustc_dirty(label="Hir", cfg="cfail2")]
64 #[rustc_clean(label="Hir", cfg="cfail3")]
65 #[rustc_metadata_clean(cfg="cfail2")]
66 #[rustc_metadata_clean(cfg="cfail3")]
67 struct TupleStructFieldType(
68     #[rustc_metadata_dirty(cfg="cfail2")]
69     #[rustc_metadata_clean(cfg="cfail3")]
70     u32
71 );
72
73
74 // Tuple Struct Add Field ------------------------------------------------------
75
76 #[cfg(cfail1)]
77 struct TupleStructAddField(i32);
78
79 #[cfg(not(cfail1))]
80 #[rustc_dirty(label="Hir", cfg="cfail2")]
81 #[rustc_clean(label="Hir", cfg="cfail3")]
82 #[rustc_metadata_dirty(cfg="cfail2")]
83 #[rustc_metadata_clean(cfg="cfail3")]
84 struct TupleStructAddField(
85     #[rustc_metadata_clean(cfg="cfail2")]
86     #[rustc_metadata_clean(cfg="cfail3")]
87     i32,
88     #[rustc_metadata_clean(cfg="cfail3")]
89     u32
90 );
91
92
93 // Tuple Struct Field Visibility -----------------------------------------------
94
95 #[cfg(cfail1)]
96 struct TupleStructFieldVisibility(char);
97
98 #[cfg(not(cfail1))]
99 #[rustc_dirty(label="Hir", cfg="cfail2")]
100 #[rustc_clean(label="Hir", cfg="cfail3")]
101 #[rustc_metadata_dirty(cfg="cfail2")]
102 #[rustc_metadata_clean(cfg="cfail3")]
103 struct TupleStructFieldVisibility(pub char);
104
105
106 // Record Struct Field Type ----------------------------------------------------
107
108 #[cfg(cfail1)]
109 struct RecordStructFieldType { x: f32 }
110
111 #[cfg(not(cfail1))]
112 #[rustc_dirty(label="Hir", cfg="cfail2")]
113 #[rustc_clean(label="Hir", cfg="cfail3")]
114 #[rustc_metadata_clean(cfg="cfail2")]
115 #[rustc_metadata_clean(cfg="cfail3")]
116 struct RecordStructFieldType {
117     #[rustc_metadata_dirty(cfg="cfail2")]
118     #[rustc_metadata_clean(cfg="cfail3")]
119     x: u64
120 }
121
122
123 // Record Struct Field Name ----------------------------------------------------
124
125 #[cfg(cfail1)]
126 struct RecordStructFieldName { x: f32 }
127
128 #[cfg(not(cfail1))]
129 #[rustc_dirty(label="Hir", cfg="cfail2")]
130 #[rustc_clean(label="Hir", cfg="cfail3")]
131 #[rustc_metadata_dirty(cfg="cfail2")]
132 #[rustc_metadata_clean(cfg="cfail3")]
133 struct RecordStructFieldName { y: f32 }
134
135
136 // Record Struct Add Field -----------------------------------------------------
137
138 #[cfg(cfail1)]
139 struct RecordStructAddField { x: f32 }
140
141 #[cfg(not(cfail1))]
142 #[rustc_dirty(label="Hir", cfg="cfail2")]
143 #[rustc_clean(label="Hir", cfg="cfail3")]
144 #[rustc_metadata_dirty(cfg="cfail2")]
145 #[rustc_metadata_clean(cfg="cfail3")]
146 struct RecordStructAddField {
147     #[rustc_metadata_clean(cfg="cfail2")]
148     #[rustc_metadata_clean(cfg="cfail3")]
149     x: f32,
150     #[rustc_metadata_clean(cfg="cfail3")]
151     y: () }
152
153
154 // Record Struct Field Visibility ----------------------------------------------
155
156 #[cfg(cfail1)]
157 struct RecordStructFieldVisibility { x: f32 }
158
159 #[cfg(not(cfail1))]
160 #[rustc_dirty(label="Hir", cfg="cfail2")]
161 #[rustc_clean(label="Hir", cfg="cfail3")]
162 #[rustc_metadata_dirty(cfg="cfail2")]
163 #[rustc_metadata_clean(cfg="cfail3")]
164 struct RecordStructFieldVisibility {
165     #[rustc_metadata_dirty(cfg="cfail2")]
166     #[rustc_metadata_clean(cfg="cfail3")]
167     pub x: f32
168 }
169
170
171 // Add Lifetime Parameter ------------------------------------------------------
172
173 #[cfg(cfail1)]
174 struct AddLifetimeParameter<'a>(&'a f32, &'a f64);
175
176 #[cfg(not(cfail1))]
177 #[rustc_dirty(label="Hir", cfg="cfail2")]
178 #[rustc_clean(label="Hir", cfg="cfail3")]
179 #[rustc_metadata_dirty(cfg="cfail2")]
180 #[rustc_metadata_clean(cfg="cfail3")]
181 struct AddLifetimeParameter<'a, 'b>(&'a f32, &'b f64);
182
183
184 // Add Lifetime Parameter Bound ------------------------------------------------
185
186 #[cfg(cfail1)]
187 struct AddLifetimeParameterBound<'a, 'b>(&'a f32, &'b f64);
188
189 #[cfg(not(cfail1))]
190 #[rustc_dirty(label="Hir", cfg="cfail2")]
191 #[rustc_clean(label="Hir", cfg="cfail3")]
192 #[rustc_metadata_dirty(cfg="cfail2")]
193 #[rustc_metadata_clean(cfg="cfail3")]
194 struct AddLifetimeParameterBound<'a, 'b: 'a>(
195     #[rustc_metadata_clean(cfg="cfail2")]
196     #[rustc_metadata_clean(cfg="cfail3")]
197     &'a f32,
198     #[rustc_metadata_clean(cfg="cfail2")]
199     #[rustc_metadata_clean(cfg="cfail3")]
200     &'b f64
201 );
202
203 #[cfg(cfail1)]
204 struct AddLifetimeParameterBoundWhereClause<'a, 'b>(&'a f32, &'b f64);
205
206 #[cfg(not(cfail1))]
207 #[rustc_dirty(label="Hir", cfg="cfail2")]
208 #[rustc_clean(label="Hir", cfg="cfail3")]
209 #[rustc_metadata_dirty(cfg="cfail2")]
210 #[rustc_metadata_clean(cfg="cfail3")]
211 struct AddLifetimeParameterBoundWhereClause<'a, 'b>(
212     #[rustc_metadata_clean(cfg="cfail2")]
213     #[rustc_metadata_clean(cfg="cfail3")]
214     &'a f32,
215     #[rustc_metadata_clean(cfg="cfail2")]
216     #[rustc_metadata_clean(cfg="cfail3")]
217     &'b f64)
218     where 'b: 'a;
219
220
221 // Add Type Parameter ----------------------------------------------------------
222
223 #[cfg(cfail1)]
224 struct AddTypeParameter<T1>(T1, T1);
225
226 #[cfg(not(cfail1))]
227 #[rustc_dirty(label="Hir", cfg="cfail2")]
228 #[rustc_clean(label="Hir", cfg="cfail3")]
229 #[rustc_metadata_dirty(cfg="cfail2")]
230 #[rustc_metadata_clean(cfg="cfail3")]
231 struct AddTypeParameter<T1, T2>(
232      // The field contains the parent's Generics, so it's dirty even though its
233      // type hasn't changed.
234     #[rustc_metadata_dirty(cfg="cfail2")]
235     #[rustc_metadata_clean(cfg="cfail3")]
236     T1,
237     #[rustc_metadata_dirty(cfg="cfail2")]
238     #[rustc_metadata_clean(cfg="cfail3")]
239     T2
240 );
241
242
243 // Add Type Parameter Bound ----------------------------------------------------
244
245 #[cfg(cfail1)]
246 struct AddTypeParameterBound<T>(T);
247
248 #[cfg(not(cfail1))]
249 #[rustc_dirty(label="Hir", cfg="cfail2")]
250 #[rustc_clean(label="Hir", cfg="cfail3")]
251 #[rustc_metadata_dirty(cfg="cfail2")]
252 #[rustc_metadata_clean(cfg="cfail3")]
253 struct AddTypeParameterBound<T: Send>(
254     #[rustc_metadata_clean(cfg="cfail2")]
255     #[rustc_metadata_clean(cfg="cfail3")]
256     T
257 );
258
259
260 #[cfg(cfail1)]
261 struct AddTypeParameterBoundWhereClause<T>(T);
262
263 #[cfg(not(cfail1))]
264 #[rustc_dirty(label="Hir", cfg="cfail2")]
265 #[rustc_clean(label="Hir", cfg="cfail3")]
266 #[rustc_metadata_dirty(cfg="cfail2")]
267 #[rustc_metadata_clean(cfg="cfail3")]
268 struct AddTypeParameterBoundWhereClause<T>(
269     #[rustc_metadata_clean(cfg="cfail2")]
270     #[rustc_metadata_clean(cfg="cfail3")]
271     T
272 ) where T: Sync;
273
274
275 // Empty struct ----------------------------------------------------------------
276
277 #[rustc_clean(label="Hir", cfg="cfail2")]
278 #[rustc_metadata_clean(cfg="cfail2")]
279 pub struct EmptyStruct;
280
281
282 // Visibility ------------------------------------------------------------------
283
284 #[cfg(cfail1)]
285 struct Visibility;
286
287 #[cfg(not(cfail1))]
288 #[rustc_dirty(label="Hir", cfg="cfail2")]
289 #[rustc_clean(label="Hir", cfg="cfail3")]
290 #[rustc_metadata_dirty(cfg="cfail2")]
291 #[rustc_metadata_clean(cfg="cfail3")]
292 pub struct Visibility;
293
294
295
296
297 struct ReferencedType1;
298 struct ReferencedType2;
299
300 // Tuple Struct Change Field Type Indirectly -----------------------------------
301 mod tuple_struct_change_field_type_indirectly {
302     #[cfg(cfail1)]
303     use super::ReferencedType1 as FieldType;
304     #[cfg(not(cfail1))]
305     use super::ReferencedType2 as FieldType;
306
307     #[rustc_dirty(label="Hir", cfg="cfail2")]
308     #[rustc_clean(label="Hir", cfg="cfail3")]
309     #[rustc_metadata_clean(cfg="cfail2")]
310     #[rustc_metadata_clean(cfg="cfail3")]
311     struct TupleStruct(
312         #[rustc_metadata_dirty(cfg="cfail2")]
313         #[rustc_metadata_clean(cfg="cfail3")]
314         FieldType
315     );
316 }
317
318
319 // Record Struct Change Field Type Indirectly -----------------------------------
320 mod record_struct_change_field_type_indirectly {
321     #[cfg(cfail1)]
322     use super::ReferencedType1 as FieldType;
323     #[cfg(not(cfail1))]
324     use super::ReferencedType2 as FieldType;
325
326     #[rustc_dirty(label="Hir", cfg="cfail2")]
327     #[rustc_clean(label="Hir", cfg="cfail3")]
328     #[rustc_metadata_clean(cfg="cfail2")]
329     #[rustc_metadata_clean(cfg="cfail3")]
330     struct RecordStruct {
331         #[rustc_metadata_dirty(cfg="cfail2")]
332         #[rustc_metadata_clean(cfg="cfail3")]
333         _x: FieldType
334     }
335 }
336
337
338
339
340 trait ReferencedTrait1 {}
341 trait ReferencedTrait2 {}
342
343 // Change Trait Bound Indirectly -----------------------------------------------
344 mod change_trait_bound_indirectly {
345     #[cfg(cfail1)]
346     use super::ReferencedTrait1 as Trait;
347     #[cfg(not(cfail1))]
348     use super::ReferencedTrait2 as Trait;
349
350     #[rustc_dirty(label="Hir", cfg="cfail2")]
351     #[rustc_clean(label="Hir", cfg="cfail3")]
352     #[rustc_metadata_dirty(cfg="cfail2")]
353     #[rustc_metadata_clean(cfg="cfail3")]
354     struct Struct<T: Trait>(T);
355 }
356
357 // Change Trait Bound Indirectly In Where Clause -------------------------------
358 mod change_trait_bound_indirectly_in_where_clause {
359     #[cfg(cfail1)]
360     use super::ReferencedTrait1 as Trait;
361     #[cfg(not(cfail1))]
362     use super::ReferencedTrait2 as Trait;
363
364     #[rustc_dirty(label="Hir", cfg="cfail2")]
365     #[rustc_clean(label="Hir", cfg="cfail3")]
366     #[rustc_metadata_dirty(cfg="cfail2")]
367     #[rustc_metadata_clean(cfg="cfail3")]
368     struct Struct<T>(T) where T : Trait;
369 }