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 #[allow(arithmetic_overflow)]
9 const fn assert_static<T>(_: &'static T) {}
11 const fn fail() -> i32 { 1/0 }
13 // Promoted that fails to evaluate in dead code -- this must work
14 // (for backwards compatibility reasons).
16 assert_static(&fail());
22 assert_static(&["a", "b", "c"]);
23 assert_static(&["d", "e", "f"]);
26 // make sure that these do not cause trouble despite overflowing
27 assert_static(&(0-1));
28 assert_static(&-i32::MIN);
30 // div-by-non-0 is okay
31 assert_static(&(1/1));
32 assert_static(&(1%1));
34 // in-bounds array access is okay
35 assert_static(&([1,2,3][0] + 1));
36 assert_static(&[[1,2][1]]);
38 // Top-level projections are not part of the promoted, so no error here.
40 #[allow(unconditional_panic)]
41 assert_static(&[1,2,3][4]);