We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ab5b9ae commit 92d1b39Copy full SHA for 92d1b39
src/test/ui/consts/promotion.rs
@@ -4,12 +4,23 @@
4
5
fn foo(_: &'static [&'static str]) {}
6
fn bar(_: &'static [&'static str; 3]) {}
7
-fn baz_i32(_: &'static i32) {}
8
-fn baz_u32(_: &'static u32) {}
+const fn baz_i32(_: &'static i32) {}
+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
+};
19
20
fn main() {
21
foo(&["a", "b", "c"]);
22
bar(&["d", "e", "f"]);
23
+ assert_eq!(C, 42);
24
25
// make sure that these do not cause trouble despite overflowing
26
baz_u32(&(0-1));
0 commit comments