Skip to content

Commit 9daac58

Browse files
authored
Rollup merge of rust-lang#80696 - RalfJung:failing-promoteds, r=oli-obk
make sure that promoteds which fail to evaluate in dead const code behave correctly rust-lang#80243 showed that we'll have to live with these kinds of failing promoteds for a while, so let's make sure we have a test that covers them.
2 parents ee94d9d + 92d1b39 commit 9daac58

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/test/ui/consts/promotion.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,23 @@
44

55
fn foo(_: &'static [&'static str]) {}
66
fn bar(_: &'static [&'static str; 3]) {}
7-
fn baz_i32(_: &'static i32) {}
8-
fn baz_u32(_: &'static u32) {}
7+
const fn baz_i32(_: &'static i32) {}
8+
const fn baz_u32(_: &'static u32) {}
9+
10+
const fn fail() -> i32 { 1/0 }
11+
const C: i32 = {
12+
// Promoted that fails to evaluate in dead code -- this must work
13+
// (for backwards compatibility reasons).
14+
if false {
15+
baz_i32(&fail());
16+
}
17+
42
18+
};
919

1020
fn main() {
1121
foo(&["a", "b", "c"]);
1222
bar(&["d", "e", "f"]);
23+
assert_eq!(C, 42);
1324

1425
// make sure that these do not cause trouble despite overflowing
1526
baz_u32(&(0-1));

0 commit comments

Comments
 (0)