]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/unary_and_binary_exprs.rs
Merge pull request #2 from rust-lang/master
[rust.git] / src / test / incremental / hashes / unary_and_binary_exprs.rs
1 // This test case tests the incremental compilation hash (ICH) implementation
2 // for unary and binary 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 #![allow(warnings)]
13 #![feature(rustc_attrs)]
14 #![crate_type="rlib"]
15
16
17 // Change constant operand of negation -----------------------------------------
18 #[cfg(cfail1)]
19 pub fn const_negation() -> i32 {
20     -10
21 }
22
23 #[cfg(not(cfail1))]
24 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
25 #[rustc_clean(cfg="cfail3")]
26 pub fn const_negation() -> i32 {
27     -1
28 }
29
30
31
32 // Change constant operand of bitwise not --------------------------------------
33 #[cfg(cfail1)]
34 pub fn const_bitwise_not() -> i32 {
35     !100
36 }
37
38 #[cfg(not(cfail1))]
39 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
40 #[rustc_clean(cfg="cfail3")]
41 pub fn const_bitwise_not() -> i32 {
42     !99
43 }
44
45
46
47 // Change variable operand of negation -----------------------------------------
48 #[cfg(cfail1)]
49 pub fn var_negation(x: i32, y: i32) -> i32 {
50     -x
51 }
52
53 #[cfg(not(cfail1))]
54 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
55 #[rustc_clean(cfg="cfail3")]
56 pub fn var_negation(x: i32, y: i32) -> i32 {
57     -y
58 }
59
60
61
62 // Change variable operand of bitwise not --------------------------------------
63 #[cfg(cfail1)]
64 pub fn var_bitwise_not(x: i32, y: i32) -> i32 {
65     !x
66 }
67
68 #[cfg(not(cfail1))]
69 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
70 #[rustc_clean(cfg="cfail3")]
71 pub fn var_bitwise_not(x: i32, y: i32) -> i32 {
72     !y
73 }
74
75
76
77 // Change variable operand of deref --------------------------------------------
78 #[cfg(cfail1)]
79 pub fn var_deref(x: &i32, y: &i32) -> i32 {
80     *x
81 }
82
83 #[cfg(not(cfail1))]
84 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
85 #[rustc_clean(cfg="cfail3")]
86 pub fn var_deref(x: &i32, y: &i32) -> i32 {
87     *y
88 }
89
90
91
92 // Change first constant operand of addition -----------------------------------
93 #[cfg(cfail1)]
94 pub fn first_const_add() -> i32 {
95     1 + 3
96 }
97
98 #[cfg(not(cfail1))]
99 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
100 #[rustc_clean(cfg="cfail3")]
101 pub fn first_const_add() -> i32 {
102     2 + 3
103 }
104
105
106
107 // Change second constant operand of addition -----------------------------------
108 #[cfg(cfail1)]
109 pub fn second_const_add() -> i32 {
110     1 + 2
111 }
112
113 #[cfg(not(cfail1))]
114 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
115 #[rustc_clean(cfg="cfail3")]
116 pub fn second_const_add() -> i32 {
117     1 + 3
118 }
119
120
121
122 // Change first variable operand of addition -----------------------------------
123 #[cfg(cfail1)]
124 pub fn first_var_add(a: i32, b: i32) -> i32 {
125     a + 2
126 }
127
128 #[cfg(not(cfail1))]
129 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
130 #[rustc_clean(cfg="cfail3")]
131 pub fn first_var_add(a: i32, b: i32) -> i32 {
132     b + 2
133 }
134
135
136
137 // Change second variable operand of addition ----------------------------------
138 #[cfg(cfail1)]
139 pub fn second_var_add(a: i32, b: i32) -> i32 {
140     1 + a
141 }
142
143 #[cfg(not(cfail1))]
144 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
145 #[rustc_clean(cfg="cfail3")]
146 pub fn second_var_add(a: i32, b: i32) -> i32 {
147     1 + b
148 }
149
150
151
152 // Change operator from + to - -------------------------------------------------
153 #[cfg(cfail1)]
154 pub fn plus_to_minus(a: i32) -> i32 {
155     1 + a
156 }
157
158 #[cfg(not(cfail1))]
159 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
160 #[rustc_clean(cfg="cfail3")]
161 pub fn plus_to_minus(a: i32) -> i32 {
162     1 - a
163 }
164
165
166
167 // Change operator from + to * -------------------------------------------------
168 #[cfg(cfail1)]
169 pub fn plus_to_mult(a: i32) -> i32 {
170     1 + a
171 }
172
173 #[cfg(not(cfail1))]
174 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
175 #[rustc_clean(cfg="cfail3")]
176 pub fn plus_to_mult(a: i32) -> i32 {
177     1 * a
178 }
179
180
181
182 // Change operator from + to / -------------------------------------------------
183 #[cfg(cfail1)]
184 pub fn plus_to_div(a: i32) -> i32 {
185     1 + a
186 }
187
188 #[cfg(not(cfail1))]
189 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
190 #[rustc_clean(cfg="cfail3")]
191 pub fn plus_to_div(a: i32) -> i32 {
192     1 / a
193 }
194
195
196
197 // Change operator from + to % -------------------------------------------------
198 #[cfg(cfail1)]
199 pub fn plus_to_mod(a: i32) -> i32 {
200     1 + a
201 }
202
203 #[cfg(not(cfail1))]
204 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
205 #[rustc_clean(cfg="cfail3")]
206 pub fn plus_to_mod(a: i32) -> i32 {
207     1 % a
208 }
209
210
211
212 // Change operator from && to || -----------------------------------------------
213 #[cfg(cfail1)]
214 pub fn and_to_or(a: bool, b: bool) -> bool {
215     a && b
216 }
217
218 #[cfg(not(cfail1))]
219 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
220 #[rustc_clean(cfg="cfail3")]
221 pub fn and_to_or(a: bool, b: bool) -> bool {
222     a || b
223 }
224
225
226
227 // Change operator from & to | -------------------------------------------------
228 #[cfg(cfail1)]
229 pub fn bitwise_and_to_bitwise_or(a: i32) -> i32 {
230     1 & a
231 }
232
233 #[cfg(not(cfail1))]
234 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
235 #[rustc_clean(cfg="cfail3")]
236 pub fn bitwise_and_to_bitwise_or(a: i32) -> i32 {
237     1 | a
238 }
239
240
241
242 // Change operator from & to ^ -------------------------------------------------
243 #[cfg(cfail1)]
244 pub fn bitwise_and_to_bitwise_xor(a: i32) -> i32 {
245     1 & a
246 }
247
248 #[cfg(not(cfail1))]
249 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
250 #[rustc_clean(cfg="cfail3")]
251 pub fn bitwise_and_to_bitwise_xor(a: i32) -> i32 {
252     1 ^ a
253 }
254
255
256
257 // Change operator from & to << ------------------------------------------------
258 #[cfg(cfail1)]
259 pub fn bitwise_and_to_lshift(a: i32) -> i32 {
260     a & 1
261 }
262
263 #[cfg(not(cfail1))]
264 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
265 #[rustc_clean(cfg="cfail3")]
266 pub fn bitwise_and_to_lshift(a: i32) -> i32 {
267     a << 1
268 }
269
270
271
272 // Change operator from & to >> ------------------------------------------------
273 #[cfg(cfail1)]
274 pub fn bitwise_and_to_rshift(a: i32) -> i32 {
275     a & 1
276 }
277
278 #[cfg(not(cfail1))]
279 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
280 #[rustc_clean(cfg="cfail3")]
281 pub fn bitwise_and_to_rshift(a: i32) -> i32 {
282     a >> 1
283 }
284
285
286
287 // Change operator from == to != -----------------------------------------------
288 #[cfg(cfail1)]
289 pub fn eq_to_uneq(a: i32) -> bool {
290     a == 1
291 }
292
293 #[cfg(not(cfail1))]
294 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
295 #[rustc_clean(cfg="cfail3")]
296 pub fn eq_to_uneq(a: i32) -> bool {
297     a != 1
298 }
299
300
301
302 // Change operator from == to < ------------------------------------------------
303 #[cfg(cfail1)]
304 pub fn eq_to_lt(a: i32) -> bool {
305     a == 1
306 }
307
308 #[cfg(not(cfail1))]
309 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
310 #[rustc_clean(cfg="cfail3")]
311 pub fn eq_to_lt(a: i32) -> bool {
312     a < 1
313 }
314
315
316
317 // Change operator from == to > ------------------------------------------------
318 #[cfg(cfail1)]
319 pub fn eq_to_gt(a: i32) -> bool {
320     a == 1
321 }
322
323 #[cfg(not(cfail1))]
324 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
325 #[rustc_clean(cfg="cfail3")]
326 pub fn eq_to_gt(a: i32) -> bool {
327     a > 1
328 }
329
330
331
332 // Change operator from == to <= -----------------------------------------------
333 #[cfg(cfail1)]
334 pub fn eq_to_le(a: i32) -> bool {
335     a == 1
336 }
337
338 #[cfg(not(cfail1))]
339 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
340 #[rustc_clean(cfg="cfail3")]
341 pub fn eq_to_le(a: i32) -> bool {
342     a <= 1
343 }
344
345
346
347 // Change operator from == to >= -----------------------------------------------
348 #[cfg(cfail1)]
349 pub fn eq_to_ge(a: i32) -> bool {
350     a == 1
351 }
352
353 #[cfg(not(cfail1))]
354 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
355 #[rustc_clean(cfg="cfail3")]
356 pub fn eq_to_ge(a: i32) -> bool {
357     a >= 1
358 }
359
360
361
362 // Change type in cast expression ----------------------------------------------
363 #[cfg(cfail1)]
364 pub fn type_cast(a: u8) -> u64 {
365     let b = a as i32;
366     let c = b as u64;
367     c
368 }
369
370 #[cfg(not(cfail1))]
371 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built,typeck_tables_of", cfg="cfail2")]
372 #[rustc_clean(cfg="cfail3")]
373 pub fn type_cast(a: u8) -> u64 {
374     let b = a as u32;
375     let c = b as u64;
376     c
377 }
378
379
380
381 // Change value in cast expression ---------------------------------------------
382 #[cfg(cfail1)]
383 pub fn value_cast(a: u32) -> i32 {
384     1 as i32
385 }
386
387 #[cfg(not(cfail1))]
388 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
389 #[rustc_clean(cfg="cfail3")]
390 pub fn value_cast(a: u32) -> i32 {
391     2 as i32
392 }
393
394
395
396 // Change place in assignment --------------------------------------------------
397 #[cfg(cfail1)]
398 pub fn place() -> i32 {
399     let mut x = 10;
400     let mut y = 11;
401     x = 9;
402     x
403 }
404
405 #[cfg(not(cfail1))]
406 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
407 #[rustc_clean(cfg="cfail3")]
408 pub fn place() -> i32 {
409     let mut x = 10;
410     let mut y = 11;
411     y = 9;
412     x
413 }
414
415
416
417 // Change r-value in assignment ------------------------------------------------
418 #[cfg(cfail1)]
419 pub fn rvalue() -> i32 {
420     let mut x = 10;
421     x = 9;
422     x
423 }
424
425 #[cfg(not(cfail1))]
426 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
427 #[rustc_clean(cfg="cfail3")]
428 pub fn rvalue() -> i32 {
429     let mut x = 10;
430     x = 8;
431     x
432 }
433
434
435
436 // Change index into slice -----------------------------------------------------
437 #[cfg(cfail1)]
438 pub fn index_to_slice(s: &[u8], i: usize, j: usize) -> u8 {
439     s[i]
440 }
441
442 #[cfg(not(cfail1))]
443 #[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")]
444 #[rustc_clean(cfg="cfail3")]
445 pub fn index_to_slice(s: &[u8], i: usize, j: usize) -> u8 {
446     s[j]
447 }