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