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
22 // These constants cannot be evaluated already (they depend on `T::N`), so they can just be linted
23 // like normal run-time code. But codegen works a bit different in const context, so this test
24 // makes sure that we still catch overflow. Also make sure we emit the same lints if we reverse the
25 // operands (so that the generic operand comes first).
26 impl<T: Foo> Foo for Vec<T> {
27 const NEG: i32 = -i32::MIN + T::NEG;
28 //~^ ERROR arithmetic operation will overflow
29 const NEG_REV: i32 = T::NEG + (-i32::MIN);
30 //~^ ERROR arithmetic operation will overflow
32 const ADD: i32 = (i32::MAX+1) + T::ADD;
33 //~^ ERROR arithmetic operation will overflow
34 const ADD_REV: i32 = T::ADD + (i32::MAX+1);
35 //~^ ERROR arithmetic operation will overflow
37 const DIV: i32 = (1/0) + T::DIV;
38 //~^ ERROR operation will panic
39 const DIV_REV: i32 = T::DIV + (1/0);
40 //~^ ERROR operation will panic
42 const OOB: i32 = [1][1] + T::OOB;
43 //~^ ERROR operation will panic
44 const OOB_REV: i32 = T::OOB + [1][1];
45 //~^ ERROR operation will panic