diff options
| author | Ralf Jung <post@ralfj.de> | 2021-01-04 17:15:57 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2021-01-04 19:48:56 +0100 |
| commit | 92d1b390438e1aefef6532463ddccc27ec3b2dda (patch) | |
| tree | a924ce53ad205b09b09b464aa6443f8f63b1752a | |
| parent | ab5b9aecb9656a6d6e61fc7c14e4f1fe438dde56 (diff) | |
| download | rust-92d1b390438e1aefef6532463ddccc27ec3b2dda.tar.gz rust-92d1b390438e1aefef6532463ddccc27ec3b2dda.zip | |
make sure that promoteds which fail to evaluate in dead const code behave correctly
| -rw-r--r-- | src/test/ui/consts/promotion.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/test/ui/consts/promotion.rs b/src/test/ui/consts/promotion.rs index e6f5c3d27ca..b6e7127a9b7 100644 --- a/src/test/ui/consts/promotion.rs +++ b/src/test/ui/consts/promotion.rs @@ -4,12 +4,23 @@ fn foo(_: &'static [&'static str]) {} fn bar(_: &'static [&'static str; 3]) {} -fn baz_i32(_: &'static i32) {} -fn baz_u32(_: &'static u32) {} +const fn baz_i32(_: &'static i32) {} +const fn baz_u32(_: &'static u32) {} + +const fn fail() -> i32 { 1/0 } +const C: i32 = { + // Promoted that fails to evaluate in dead code -- this must work + // (for backwards compatibility reasons). + if false { + baz_i32(&fail()); + } + 42 +}; fn main() { foo(&["a", "b", "c"]); bar(&["d", "e", "f"]); + assert_eq!(C, 42); // make sure that these do not cause trouble despite overflowing baz_u32(&(0-1)); |
