Skip to content

Commit 5d186d0

Browse files
committedNov 8, 2016
ICH: Add test case for match-expressions
1 parent f7d2a81 commit 5d186d0

File tree

1 file changed

+342
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)
Please sign in to comment.