1 // revisions: noopt opt opt_with_overflow_checks
2 //[noopt]compile-flags: -C opt-level=0
3 //[opt]compile-flags: -O
4 //[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O
24 // These constants cannot be evaluated already (they depend on `T::N`), so they can just be linted
25 // like normal run-time code. But codegen works a bit different in const context, so this test
26 // makes sure that we still catch overflow. Also make sure we emit the same lints if we reverse the
27 // operands (so that the generic operand comes first).
28 impl<T: Foo> Foo for Vec<T> {
29 const NEG: i32 = -i32::MIN + T::NEG;
30 //~^ ERROR arithmetic operation will overflow
31 const NEG_REV: i32 = T::NEG + (-i32::MIN);
32 //~^ ERROR arithmetic operation will overflow
34 const ADD: i32 = (i32::MAX+1) + T::ADD;
35 //~^ ERROR arithmetic operation will overflow
36 const ADD_REV: i32 = T::ADD + (i32::MAX+1);
37 //~^ ERROR arithmetic operation will overflow
39 const DIV: i32 = (1/0) + T::DIV;
40 //~^ ERROR operation will panic
41 const DIV_REV: i32 = T::DIV + (1/0);
42 //~^ ERROR operation will panic
44 const OOB: i32 = [1][1] + T::OOB;
45 //~^ ERROR operation will panic
46 const OOB_REV: i32 = T::OOB + [1][1];
47 //~^ ERROR operation will panic