Skip to content

Commit 0c7fd2c

Browse files
committed
expand successful-promotion test a bit
1 parent f62cecd commit 0c7fd2c

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

Diff for: src/test/ui/consts/promotion.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
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
25

3-
// compile-flags: -O
6+
// build-pass
7+
#[allow(arithmetic_overflow)]
48

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) {}
910

1011
const fn fail() -> i32 { 1/0 }
1112
const C: i32 = {
1213
// Promoted that fails to evaluate in dead code -- this must work
1314
// (for backwards compatibility reasons).
1415
if false {
15-
baz_i32(&fail());
16+
assert_static(&fail());
1617
}
1718
42
1819
};
1920

2021
fn main() {
21-
foo(&["a", "b", "c"]);
22-
bar(&["d", "e", "f"]);
22+
assert_static(&["a", "b", "c"]);
23+
assert_static(&["d", "e", "f"]);
2324
assert_eq!(C, 42);
2425

2526
// 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);
2829

2930
// 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));
3233

3334
// 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]]);
3537

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.
3739
if false {
3840
#[allow(unconditional_panic)]
39-
baz_i32(&[1,2,3][4]);
41+
assert_static(&[1,2,3][4]);
4042
}
4143
}

0 commit comments

Comments
 (0)