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