rust icon indicating copy to clipboard operation
rust copied to clipboard

`StorageLive already live` in const `let else` regression

Open juntyr opened this issue 3 years ago • 3 comments

I tried this code:

#![feature(let_else)]

const fn foo(a: Option<i32>) -> i32 {
    let Some(a) = a else {
        return 42
    };
    
    a + 1
}

fn main() {
    const A: i32 = foo(None);
    const B: i32 = foo(Some(1));

    println!("{} {}", A, B);
}

I expected to see this happen: The code should compile and print "42 2".

Instead, this happened: The evaluation of the constant B fails with StorageLive on a local that was already live.

This code last compiled with nightly-2022-09-15-x86_64-unknown-linux-gnu (750bd1a7f 2022-09-14) and first failed with nightly-2022-09-16-x86_64-unknown-linux-gnu (cf9ed0dd5 2022-09-15).

Meta

rustc --version --verbose:

rustc 1.65.0-nightly (95a992a68 2022-09-16)
binary: rustc
commit-hash: 95a992a68694d8bf3959bd2c0ac27ce9e9208b59
commit-date: 2022-09-16
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0
Backtrace

error[E0080]: evaluation of constant value failed
  --> main.rs:4:14
   |
4  |     let Some(a) = a else {
   |              ^
   |              |
   |              StorageLive on a local that was already live
   |              inside `foo` at main.rs:4:14
...
13 |     const B: i32 = foo(Some(1));
   |                    ------------ inside `B` at main.rs:13:20

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.

juntyr avatar Sep 17 '22 05:09 juntyr

Dupe of #101867 , fixed by #101894

est31 avatar Sep 17 '22 06:09 est31

There is also some discussion in: https://github.com/rust-lang/rust/pull/101410#issuecomment-1248689621

est31 avatar Sep 17 '22 06:09 est31

@rustbot label F-let-else

est31 avatar Sep 17 '22 20:09 est31