]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/struct_constructors.rs
ICH: Add missing annotations for struct constructor expr test case.
[rust.git] / src / test / incremental / hashes / struct_constructors.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 constructor expressions.
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 // must-compile-successfully
20 // revisions: cfail1 cfail2 cfail3
21 // compile-flags: -Z query-dep-graph
22
23 #![allow(warnings)]
24 #![feature(rustc_attrs)]
25 #![crate_type="rlib"]
26
27
28 struct RegularStruct {
29     x: i32,
30     y: i64,
31     z: i16,
32 }
33
34 // Change field value (regular struct) -----------------------------------------
35 #[cfg(cfail1)]
36 fn change_field_value_regular_struct() -> RegularStruct {
37     RegularStruct {
38         x: 0,
39         y: 1,
40         z: 2,
41     }
42 }
43
44 #[cfg(not(cfail1))]
45 #[rustc_clean(label="Hir", cfg="cfail2")]
46 #[rustc_clean(label="Hir", cfg="cfail3")]
47 #[rustc_dirty(label="HirBody", cfg="cfail2")]
48 #[rustc_clean(label="HirBody", cfg="cfail3")]
49 #[rustc_metadata_clean(cfg="cfail2")]
50 #[rustc_metadata_clean(cfg="cfail3")]
51 fn change_field_value_regular_struct() -> RegularStruct {
52     RegularStruct {
53         x: 0,
54         y: 2,
55         z: 2,
56     }
57 }
58
59
60
61 // Change field order (regular struct) -----------------------------------------
62 #[cfg(cfail1)]
63 fn change_field_order_regular_struct() -> RegularStruct {
64     RegularStruct {
65         x: 3,
66         y: 4,
67         z: 5,
68     }
69 }
70
71 #[cfg(not(cfail1))]
72 #[rustc_clean(label="Hir", cfg="cfail2")]
73 #[rustc_clean(label="Hir", cfg="cfail3")]
74 #[rustc_dirty(label="HirBody", cfg="cfail2")]
75 #[rustc_clean(label="HirBody", cfg="cfail3")]
76 #[rustc_metadata_clean(cfg="cfail2")]
77 #[rustc_metadata_clean(cfg="cfail3")]
78 fn change_field_order_regular_struct() -> RegularStruct {
79     RegularStruct {
80         y: 4,
81         x: 3,
82         z: 5,
83     }
84 }
85
86
87
88 // Add field (regular struct) --------------------------------------------------
89 #[cfg(cfail1)]
90 fn add_field_regular_struct() -> RegularStruct {
91     let struct1 = RegularStruct {
92         x: 3,
93         y: 4,
94         z: 5,
95     };
96
97     RegularStruct {
98         x: 7,
99         .. struct1
100     }
101 }
102
103 #[cfg(not(cfail1))]
104 #[rustc_clean(label="Hir", cfg="cfail2")]
105 #[rustc_clean(label="Hir", cfg="cfail3")]
106 #[rustc_dirty(label="HirBody", cfg="cfail2")]
107 #[rustc_clean(label="HirBody", cfg="cfail3")]
108 #[rustc_metadata_clean(cfg="cfail2")]
109 #[rustc_metadata_clean(cfg="cfail3")]
110 fn add_field_regular_struct() -> RegularStruct {
111     let struct1 = RegularStruct {
112         x: 3,
113         y: 4,
114         z: 5,
115     };
116
117     RegularStruct {
118         x: 7,
119         y: 8,
120         .. struct1
121     }
122 }
123
124
125
126 // Change field label (regular struct) -----------------------------------------
127 #[cfg(cfail1)]
128 fn change_field_label_regular_struct() -> RegularStruct {
129     let struct1 = RegularStruct {
130         x: 3,
131         y: 4,
132         z: 5,
133     };
134
135     RegularStruct {
136         x: 7,
137         y: 9,
138         .. struct1
139     }
140 }
141
142 #[cfg(not(cfail1))]
143 #[rustc_clean(label="Hir", cfg="cfail2")]
144 #[rustc_clean(label="Hir", cfg="cfail3")]
145 #[rustc_dirty(label="HirBody", cfg="cfail2")]
146 #[rustc_clean(label="HirBody", cfg="cfail3")]
147 #[rustc_metadata_clean(cfg="cfail2")]
148 #[rustc_metadata_clean(cfg="cfail3")]
149 fn change_field_label_regular_struct() -> RegularStruct {
150     let struct1 = RegularStruct {
151         x: 3,
152         y: 4,
153         z: 5,
154     };
155
156     RegularStruct {
157         x: 7,
158         z: 9,
159         .. struct1
160     }
161 }
162
163
164
165 struct RegularStruct2 {
166     x: i8,
167     y: i8,
168     z: i8,
169 }
170
171 // Change constructor path (regular struct) ------------------------------------
172 #[cfg(cfail1)]
173 fn change_constructor_path_regular_struct() {
174     let _ = RegularStruct {
175         x: 0,
176         y: 1,
177         z: 2,
178     };
179 }
180
181 #[cfg(not(cfail1))]
182 #[rustc_clean(label="Hir", cfg="cfail2")]
183 #[rustc_clean(label="Hir", cfg="cfail3")]
184 #[rustc_dirty(label="HirBody", cfg="cfail2")]
185 #[rustc_clean(label="HirBody", cfg="cfail3")]
186 #[rustc_metadata_clean(cfg="cfail2")]
187 #[rustc_metadata_clean(cfg="cfail3")]
188 fn change_constructor_path_regular_struct() {
189     let _ = RegularStruct2 {
190         x: 0,
191         y: 1,
192         z: 2,
193     };
194 }
195
196
197
198 // Change constructor path indirectly (regular struct) -------------------------
199 mod change_constructor_path_indirectly_regular_struct {
200     #[cfg(cfail1)]
201     use super::RegularStruct as Struct;
202     #[cfg(not(cfail1))]
203     use super::RegularStruct2 as Struct;
204
205     #[rustc_dirty(label="Hir", cfg="cfail2")]
206     #[rustc_clean(label="Hir", cfg="cfail3")]
207     #[rustc_dirty(label="HirBody", cfg="cfail2")]
208     #[rustc_clean(label="HirBody", cfg="cfail3")]
209     #[rustc_metadata_dirty(cfg="cfail2")]
210     #[rustc_metadata_clean(cfg="cfail3")]
211     fn function() -> Struct {
212         Struct {
213             x: 0,
214             y: 1,
215             z: 2,
216         }
217     }
218 }
219
220
221
222 struct TupleStruct(i32, i64, i16);
223
224 // Change field value (tuple struct) -------------------------------------------
225 #[cfg(cfail1)]
226 fn change_field_value_tuple_struct() -> TupleStruct {
227     TupleStruct(0, 1, 2)
228 }
229
230 #[cfg(not(cfail1))]
231 #[rustc_clean(label="Hir", cfg="cfail2")]
232 #[rustc_clean(label="Hir", cfg="cfail3")]
233 #[rustc_dirty(label="HirBody", cfg="cfail2")]
234 #[rustc_clean(label="HirBody", cfg="cfail3")]
235 #[rustc_metadata_clean(cfg="cfail2")]
236 #[rustc_metadata_clean(cfg="cfail3")]
237 fn change_field_value_tuple_struct() -> TupleStruct {
238     TupleStruct(0, 1, 3)
239 }
240
241
242
243 struct TupleStruct2(u16, u16, u16);
244
245 // Change constructor path (tuple struct) --------------------------------------
246 #[cfg(cfail1)]
247 fn change_constructor_path_tuple_struct() {
248     let _ = TupleStruct(0, 1, 2);
249 }
250
251 #[cfg(not(cfail1))]
252 #[rustc_clean(label="Hir", cfg="cfail2")]
253 #[rustc_clean(label="Hir", cfg="cfail3")]
254 #[rustc_dirty(label="HirBody", cfg="cfail2")]
255 #[rustc_clean(label="HirBody", cfg="cfail3")]
256 #[rustc_metadata_clean(cfg="cfail2")]
257 #[rustc_metadata_clean(cfg="cfail3")]
258 fn change_constructor_path_tuple_struct() {
259     let _ = TupleStruct2(0, 1, 2);
260 }
261
262
263
264 // Change constructor path indirectly (tuple struct) ---------------------------
265 mod change_constructor_path_indirectly_tuple_struct {
266     #[cfg(cfail1)]
267     use super::TupleStruct as Struct;
268     #[cfg(not(cfail1))]
269     use super::TupleStruct2 as Struct;
270
271     #[rustc_dirty(label="Hir", cfg="cfail2")]
272     #[rustc_clean(label="Hir", cfg="cfail3")]
273     #[rustc_dirty(label="HirBody", cfg="cfail2")]
274     #[rustc_clean(label="HirBody", cfg="cfail3")]
275     #[rustc_metadata_dirty(cfg="cfail2")]
276     #[rustc_metadata_clean(cfg="cfail3")]
277     fn function() -> Struct {
278         Struct(0, 1, 2)
279     }
280 }