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