2018-03-06 11:43:02 +00: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-14 03:28:32 +00:00
|
|
|
|
2020-02-19 10:25:41 +00:00
|
|
|
// revisions: noopt opt opt_with_overflow_checks
|
2020-02-15 09:51:51 +00:00
|
|
|
//[noopt]compile-flags: -C opt-level=0
|
2020-02-15 09:47:27 +00:00
|
|
|
//[opt]compile-flags: -O
|
|
|
|
//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O
|
|
|
|
|
2019-12-14 03:28:32 +00:00
|
|
|
// build-fail
|
2018-03-06 11:43:02 +00:00
|
|
|
|
2016-04-26 13:32:18 +00:00
|
|
|
#![feature(rustc_attrs)]
|
|
|
|
|
|
|
|
fn black_box<T>(_: T) {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2020-10-24 23:21:40 +00:00
|
|
|
let a = -i8::MIN;
|
2020-02-15 09:47:27 +00:00
|
|
|
//~^ ERROR arithmetic operation will overflow
|
2020-10-24 23:21:40 +00:00
|
|
|
let a_i128 = -i128::MIN;
|
2020-02-15 09:47:27 +00:00
|
|
|
//~^ ERROR arithmetic operation will overflow
|
2016-04-26 13:32:18 +00:00
|
|
|
let b = 200u8 + 200u8 + 200u8;
|
2020-02-15 09:47:27 +00:00
|
|
|
//~^ ERROR arithmetic operation will overflow
|
2020-10-24 23:21:40 +00:00
|
|
|
let b_i128 = i128::MIN - i128::MAX;
|
2020-02-15 09:47:27 +00:00
|
|
|
//~^ ERROR arithmetic operation will overflow
|
2016-04-26 13:32:18 +00:00
|
|
|
let c = 200u8 * 4;
|
2020-02-15 09:47:27 +00:00
|
|
|
//~^ ERROR arithmetic operation will overflow
|
2016-04-26 13:32:18 +00:00
|
|
|
let d = 42u8 - (42u8 + 1);
|
2020-02-15 09:47:27 +00:00
|
|
|
//~^ ERROR arithmetic operation will overflow
|
2016-04-26 13:32:18 +00:00
|
|
|
let _e = [5u8][1];
|
2020-02-15 09:47:27 +00:00
|
|
|
//~^ ERROR operation will panic
|
2016-04-26 13:32:18 +00:00
|
|
|
black_box(a);
|
2020-02-10 10:37:02 +00:00
|
|
|
black_box(a_i128);
|
2016-04-26 13:32:18 +00:00
|
|
|
black_box(b);
|
2020-02-10 10:37:02 +00:00
|
|
|
black_box(b_i128);
|
2016-04-26 13:32:18 +00:00
|
|
|
black_box(c);
|
|
|
|
black_box(d);
|
|
|
|
}
|