]> git.lizzy.rs Git - rust.git/blob - tests/ui/consts/const-err2.rs
Rollup merge of #106427 - mejrs:translation_errors, r=davidtwco
[rust.git] / tests / ui / consts / const-err2.rs
1 // needed because negating int::MIN will behave differently between
2 // optimized compilation and unoptimized compilation and thus would
3 // lead to different lints being emitted
4
5 // revisions: noopt opt opt_with_overflow_checks
6 //[noopt]compile-flags: -C opt-level=0
7 //[opt]compile-flags: -O
8 //[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O
9
10 // build-fail
11
12 #![feature(rustc_attrs)]
13
14 fn black_box<T>(_: T) {
15     unimplemented!()
16 }
17
18 fn main() {
19     let a = -i8::MIN;
20     //~^ ERROR arithmetic operation will overflow
21     let a_i128 = -i128::MIN;
22     //~^ ERROR arithmetic operation will overflow
23     let b = 200u8 + 200u8 + 200u8;
24     //~^ ERROR arithmetic operation will overflow
25     let b_i128 = i128::MIN - i128::MAX;
26     //~^ ERROR arithmetic operation will overflow
27     let c = 200u8 * 4;
28     //~^ ERROR arithmetic operation will overflow
29     let d = 42u8 - (42u8 + 1);
30     //~^ ERROR arithmetic operation will overflow
31     let _e = [5u8][1];
32     //~^ ERROR operation will panic
33     black_box(a);
34     black_box(a_i128);
35     black_box(b);
36     black_box(b_i128);
37     black_box(c);
38     black_box(d);
39 }