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