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