]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/promoted_errors.rs
Rollup merge of #83634 - JohnTitor:proc-macro-ice, r=varkor
[rust.git] / src / test / ui / consts / const-eval / promoted_errors.rs
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
5
6 // build-pass
7 // ignore-pass (test emits codegen-time warnings and verifies that they are not errors)
8
9 #![warn(const_err, arithmetic_overflow, unconditional_panic)]
10
11 // The only way to have promoteds that fail is in `const fn` called from `const`/`static`.
12 const fn overflow() -> u32 {
13     0 - 1
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
16 }
17 const fn div_by_zero1() -> i32 {
18     1 / 0
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
21 }
22 const fn div_by_zero2() -> i32 {
23     1 / (1 - 1)
24 }
25 const fn div_by_zero3() -> i32 {
26     1 / (false as i32)
27 }
28 const fn oob() -> i32 {
29     [1, 2, 3][4]
30 }
31
32 const X: () = {
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();
42 };
43
44 fn main() {}