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