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