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