2018-03-06 05:43:02 -06:00
|
|
|
// needed because negating int::MIN will behave differently between
|
|
|
|
// optimized compilation and unoptimized compilation and thus would
|
|
|
|
// lead to different lints being emitted
|
2019-12-13 21:28:32 -06:00
|
|
|
|
2020-02-19 04:25:41 -06:00
|
|
|
// revisions: noopt opt opt_with_overflow_checks
|
2020-02-15 03:51:51 -06:00
|
|
|
//[noopt]compile-flags: -C opt-level=0
|
2020-02-15 03:47:27 -06:00
|
|
|
//[opt]compile-flags: -O
|
|
|
|
//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O
|
|
|
|
|
2019-12-13 21:28:32 -06:00
|
|
|
// build-fail
|
2018-03-06 05:43:02 -06:00
|
|
|
|
2016-04-26 08:32:18 -05:00
|
|
|
#![feature(rustc_attrs)]
|
|
|
|
|
|
|
|
fn black_box<T>(_: T) {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2020-10-24 18:21:40 -05:00
|
|
|
let a = -i8::MIN;
|
2020-02-15 03:47:27 -06:00
|
|
|
//~^ ERROR arithmetic operation will overflow
|
2020-10-24 18:21:40 -05:00
|
|
|
let a_i128 = -i128::MIN;
|
2020-02-15 03:47:27 -06:00
|
|
|
//~^ ERROR arithmetic operation will overflow
|
2016-04-26 08:32:18 -05:00
|
|
|
let b = 200u8 + 200u8 + 200u8;
|
2020-02-15 03:47:27 -06:00
|
|
|
//~^ ERROR arithmetic operation will overflow
|
2020-10-24 18:21:40 -05:00
|
|
|
let b_i128 = i128::MIN - i128::MAX;
|
2020-02-15 03:47:27 -06:00
|
|
|
//~^ ERROR arithmetic operation will overflow
|
2016-04-26 08:32:18 -05:00
|
|
|
let c = 200u8 * 4;
|
2020-02-15 03:47:27 -06:00
|
|
|
//~^ ERROR arithmetic operation will overflow
|
2016-04-26 08:32:18 -05:00
|
|
|
let d = 42u8 - (42u8 + 1);
|
2020-02-15 03:47:27 -06:00
|
|
|
//~^ ERROR arithmetic operation will overflow
|
2016-04-26 08:32:18 -05:00
|
|
|
let _e = [5u8][1];
|
2020-02-15 03:47:27 -06:00
|
|
|
//~^ ERROR operation will panic
|
2016-04-26 08:32:18 -05:00
|
|
|
black_box(a);
|
2020-02-10 04:37:02 -06:00
|
|
|
black_box(a_i128);
|
2016-04-26 08:32:18 -05:00
|
|
|
black_box(b);
|
2020-02-10 04:37:02 -06:00
|
|
|
black_box(b_i128);
|
2016-04-26 08:32:18 -05:00
|
|
|
black_box(c);
|
|
|
|
black_box(d);
|
|
|
|
}
|