]>
Commit | Line | Data |
---|---|---|
5869c6ff XL |
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 | |
b7449926 | 5 | |
5869c6ff | 6 | // build-pass |
b7449926 | 7 | |
5869c6ff XL |
8 | const fn assert_static<T>(_: &'static T) {} |
9 | ||
ee023bcb FG |
10 | #[allow(unconditional_panic)] |
11 | const fn fail() -> i32 { | |
12 | 1/0 | |
13 | } | |
5869c6ff XL |
14 | const C: i32 = { |
15 | // Promoted that fails to evaluate in dead code -- this must work | |
16 | // (for backwards compatibility reasons). | |
17 | if false { | |
18 | assert_static(&fail()); | |
19 | } | |
20 | 42 | |
21 | }; | |
0531ce1d | 22 | |
a7813a04 | 23 | fn main() { |
5869c6ff XL |
24 | assert_static(&["a", "b", "c"]); |
25 | assert_static(&["d", "e", "f"]); | |
26 | assert_eq!(C, 42); | |
b7449926 XL |
27 | |
28 | // make sure that these do not cause trouble despite overflowing | |
5869c6ff XL |
29 | assert_static(&(0-1)); |
30 | assert_static(&-i32::MIN); | |
31 | ||
32 | // div-by-non-0 is okay | |
33 | assert_static(&(1/1)); | |
34 | assert_static(&(1%1)); | |
35 | ||
36 | // in-bounds array access is okay | |
37 | assert_static(&([1,2,3][0] + 1)); | |
38 | assert_static(&[[1,2][1]]); | |
39 | ||
40 | // Top-level projections are not part of the promoted, so no error here. | |
41 | if false { | |
42 | #[allow(unconditional_panic)] | |
43 | assert_static(&[1,2,3][4]); | |
44 | } | |
54a0048b | 45 | } |