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