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