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