]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/match_expressions.rs
Auto merge of #95884 - cjgillot:assoc-item, r=lcnr
[rust.git] / src / test / incremental / hashes / match_expressions.rs
1 // This test case tests the incremental compilation hash (ICH) implementation
2 // for match 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 // [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 // Add Arm ---------------------------------------------------------------------
23 #[cfg(any(cfail1,cfail4))]
24 pub fn add_arm(x: u32) -> u32 {
25     match x {
26         0 => 0,
27         1 => 1,
28         /*---*/
29         _ => 100,
30     }
31 }
32
33 #[cfg(not(any(cfail1,cfail4)))]
34 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
35 #[rustc_clean(cfg="cfail3")]
36 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
37 #[rustc_clean(cfg="cfail6")]
38 pub fn add_arm(x: u32) -> u32 {
39     match x {
40         0 => 0,
41         1 => 1,
42         2 => 2,
43         _ => 100,
44     }
45 }
46
47
48
49 // Change Order Of Arms --------------------------------------------------------
50 #[cfg(any(cfail1,cfail4))]
51 pub fn change_order_of_arms(x: u32) -> u32 {
52     match x {
53         0 => 0,
54         1 => 1,
55         _ => 100,
56     }
57 }
58
59 #[cfg(not(any(cfail1,cfail4)))]
60 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
61 #[rustc_clean(cfg="cfail3")]
62 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
63 #[rustc_clean(cfg="cfail6")]
64 pub fn change_order_of_arms(x: u32) -> u32 {
65     match x {
66         1 => 1,
67         0 => 0,
68         _ => 100,
69     }
70 }
71
72
73
74 // Add Guard Clause ------------------------------------------------------------
75 #[cfg(any(cfail1,cfail4))]
76 pub fn add_guard_clause(x: u32, y: bool) -> u32 {
77     match x {
78         0 => 0,
79         1      => 1,
80         _ => 100,
81     }
82 }
83
84 #[cfg(not(any(cfail1,cfail4)))]
85 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
86 #[rustc_clean(cfg="cfail3")]
87 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
88 #[rustc_clean(cfg="cfail6")]
89 pub fn add_guard_clause(x: u32, y: bool) -> u32 {
90     match x {
91         0 => 0,
92         1 if y => 1,
93         _ => 100,
94     }
95 }
96
97
98
99 // Change Guard Clause ------------------------------------------------------------
100 #[cfg(any(cfail1,cfail4))]
101 pub fn change_guard_clause(x: u32, y: bool) -> u32 {
102     match x {
103         0 => 0,
104         1 if  y => 1,
105         _ => 100,
106     }
107 }
108
109 #[cfg(not(any(cfail1,cfail4)))]
110 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
111 #[rustc_clean(cfg="cfail3")]
112 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
113 #[rustc_clean(cfg="cfail6")]
114 pub fn change_guard_clause(x: u32, y: bool) -> u32 {
115     match x {
116         0 => 0,
117         1 if !y => 1,
118         _ => 100,
119     }
120 }
121
122
123
124 // Add @-Binding ---------------------------------------------------------------
125 #[cfg(any(cfail1,cfail4))]
126 pub fn add_at_binding(x: u32) -> u32 {
127     match x {
128         0 => 0,
129         1 => 1,
130             _ => x,
131     }
132 }
133
134 #[cfg(not(any(cfail1,cfail4)))]
135 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
136 #[rustc_clean(cfg="cfail3")]
137 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
138 #[rustc_clean(cfg="cfail6")]
139 pub fn add_at_binding(x: u32) -> u32 {
140     match x {
141         0 => 0,
142         1 => 1,
143         x @ _ => x,
144     }
145 }
146
147
148
149 // Change Name of @-Binding ----------------------------------------------------
150 #[cfg(any(cfail1,cfail4))]
151 pub fn change_name_of_at_binding(x: u32) -> u32 {
152     match x {
153         0 => 0,
154         1 => 1,
155         x @ _ => 7,
156     }
157 }
158
159 #[cfg(not(any(cfail1,cfail4)))]
160 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
161 #[rustc_clean(cfg="cfail3")]
162 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
163 #[rustc_clean(cfg="cfail6")]
164 pub fn change_name_of_at_binding(x: u32) -> u32 {
165     match x {
166         0 => 0,
167         1 => 1,
168         y @ _ => 7,
169     }
170 }
171
172
173
174 // Change Simple Binding To Pattern --------------------------------------------
175 #[cfg(any(cfail1,cfail4))]
176 pub fn change_simple_name_to_pattern(x: u32) -> u32 {
177     match (x, x & 1) {
178         (0, 0) => 0,
179          a     => 1,
180     }
181 }
182
183 #[cfg(not(any(cfail1,cfail4)))]
184 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
185 #[rustc_clean(cfg="cfail3")]
186 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
187 #[rustc_clean(cfg="cfail6")]
188 pub fn change_simple_name_to_pattern(x: u32) -> u32 {
189     match (x, x & 1) {
190         (0, 0) => 0,
191         (x, y) => 1,
192     }
193 }
194
195
196
197 // Change Name In Pattern ------------------------------------------------------
198 #[cfg(any(cfail1,cfail4))]
199 pub fn change_name_in_pattern(x: u32) -> u32 {
200     match (x, x & 1) {
201         (a, 0) => 0,
202         (a, 1) => a,
203         _ => 100,
204     }
205 }
206
207 #[cfg(not(any(cfail1,cfail4)))]
208 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
209 #[rustc_clean(cfg="cfail3")]
210 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
211 #[rustc_clean(cfg="cfail6")]
212 pub fn change_name_in_pattern(x: u32) -> u32 {
213     match (x, x & 1) {
214         (b, 0) => 0,
215         (a, 1) => a,
216         _ => 100,
217     }
218 }
219
220
221
222 // Change Mutability Of Binding In Pattern -------------------------------------
223 #[cfg(any(cfail1,cfail4))]
224 pub fn change_mutability_of_binding_in_pattern(x: u32) -> u32 {
225     match (x, x & 1) {
226         (    a, 0) => 0,
227         _ => 1,
228     }
229 }
230
231 #[cfg(not(any(cfail1,cfail4)))]
232 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck")]
233 #[rustc_clean(cfg="cfail3")]
234 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir,typeck")]
235 #[rustc_clean(cfg="cfail6")]
236 pub fn change_mutability_of_binding_in_pattern(x: u32) -> u32 {
237     match (x, x & 1) {
238         (mut a, 0) => 0,
239         _ => 1,
240     }
241 }
242
243
244
245 // Add `ref` To Binding In Pattern -------------------------------------
246 #[cfg(any(cfail1,cfail4))]
247 pub fn add_ref_to_binding_in_pattern(x: u32) -> u32 {
248     match (x, x & 1) {
249         (    a, 0) => 0,
250         _ => 1,
251     }
252 }
253
254 #[cfg(not(any(cfail1,cfail4)))]
255 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck")]
256 #[rustc_clean(cfg="cfail3")]
257 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir,typeck")]
258 #[rustc_clean(cfg="cfail6")]
259 pub fn add_ref_to_binding_in_pattern(x: u32) -> u32 {
260     match (x, x & 1) {
261         (ref a, 0) => 0,
262         _ => 1,
263     }
264 }
265
266
267
268 // Add `&` To Binding In Pattern -------------------------------------
269 #[cfg(any(cfail1,cfail4))]
270 pub fn add_amp_to_binding_in_pattern(x: u32) -> u32 {
271     match (&x, x & 1) {
272         ( a, 0) => 0,
273         _ => 1,
274     }
275 }
276
277 #[cfg(not(any(cfail1,cfail4)))]
278 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
279 #[rustc_clean(cfg="cfail3")]
280 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
281 #[rustc_clean(cfg="cfail6")]
282 pub fn add_amp_to_binding_in_pattern(x: u32) -> u32 {
283     match (&x, x & 1) {
284         (&a, 0) => 0,
285         _ => 1,
286     }
287 }
288
289
290
291 // Change RHS Of Arm -----------------------------------------------------------
292 #[cfg(any(cfail1,cfail4))]
293 pub fn change_rhs_of_arm(x: u32) -> u32 {
294     match x {
295         0 => 0,
296         1 => 1,
297         _ => 2,
298     }
299 }
300
301 #[cfg(not(any(cfail1,cfail4)))]
302 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
303 #[rustc_clean(cfg="cfail3")]
304 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
305 #[rustc_clean(cfg="cfail6")]
306 pub fn change_rhs_of_arm(x: u32) -> u32 {
307     match x {
308         0 => 0,
309         1 => 3,
310         _ => 2,
311     }
312 }
313
314
315
316 // Add Alternative To Arm ------------------------------------------------------
317 #[cfg(any(cfail1,cfail4))]
318 pub fn add_alternative_to_arm(x: u32) -> u32 {
319     match x {
320         0     => 0,
321         1 => 1,
322         _ => 2,
323     }
324 }
325
326 #[cfg(not(any(cfail1,cfail4)))]
327 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
328 #[rustc_clean(cfg="cfail3")]
329 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
330 #[rustc_clean(cfg="cfail6")]
331 pub fn add_alternative_to_arm(x: u32) -> u32 {
332     match x {
333         0 | 7 => 0,
334         1 => 3,
335         _ => 2,
336     }
337 }