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
7 // ignore-pass (test emits codegen-time warnings and verifies that they are not errors)
9 #![warn(const_err, arithmetic_overflow, unconditional_panic)]
11 // The only way to have promoteds that fail is in `const fn` called from `const`/`static`.
12 const fn overflow() -> u32 {
14 //[opt_with_overflow_checks,noopt]~^ WARN any use of this value will cause an error
15 //[opt_with_overflow_checks,noopt]~| WARN this was previously accepted by the compiler
17 const fn div_by_zero1() -> i32 {
19 //[opt]~^ WARN any use of this value will cause an error
20 //[opt]~| WARN this was previously accepted by the compiler but is being phased out
22 const fn div_by_zero2() -> i32 {
25 const fn div_by_zero3() -> i32 {
28 const fn oob() -> i32 {
33 let _x: &'static u32 = &overflow();
34 //[opt_with_overflow_checks,noopt]~^ WARN any use of this value will cause an error
35 //[opt_with_overflow_checks,noopt]~| WARN this was previously accepted by the compiler
36 let _x: &'static i32 = &div_by_zero1();
37 //[opt]~^ WARN any use of this value will cause an error
38 //[opt]~| WARN this was previously accepted by the compiler but is being phased out
39 let _x: &'static i32 = &div_by_zero2();
40 let _x: &'static i32 = &div_by_zero3();
41 let _x: &'static i32 = &oob();