Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StorageLive already live in const let else regression #101932

Closed
juntyr opened this issue Sep 17, 2022 · 3 comments · Fixed by #101894
Closed

StorageLive already live in const let else regression #101932

juntyr opened this issue Sep 17, 2022 · 3 comments · Fixed by #101894
Labels
C-bug Category: This is a bug. F-let-else Issues related to let-else statements (RFC 3137)

Comments

@juntyr
Copy link
Contributor

juntyr commented Sep 17, 2022

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 juntyr added the C-bug Category: This is a bug. label Sep 17, 2022
juntyr added a commit to juntyr/const-type-layout that referenced this issue Sep 17, 2022
@est31
Copy link
Member

est31 commented Sep 17, 2022

Dupe of #101867 , fixed by #101894

@est31
Copy link
Member

est31 commented Sep 17, 2022

There is also some discussion in: #101410 (comment)

@est31
Copy link
Member

est31 commented Sep 17, 2022

@rustbot label F-let-else

@rustbot rustbot added the F-let-else Issues related to let-else statements (RFC 3137) label Sep 17, 2022
@bors bors closed this as completed in 2019147 Sep 19, 2022
juntyr added a commit to juntyr/const-type-layout that referenced this issue Oct 30, 2022
juntyr added a commit to juntyr/const-type-layout that referenced this issue Oct 30, 2022
* Fix undefined behaviour by removing `MayebUninit` usage (#4)

* Experiments with less uninit

* Some more experimentation

* Some progress on box, ptr, ref (still no mut ref)

* Upgraded MSRV to 1.60.0

* Added more examples

* Mutable ref with const uninit fn

* Clean up const generation

* Removed core->alloc dependency for ptr+ref

* Removed extraneous Static type alias

* Feature `const_ptr_offset_from` stabilised in 1.65.0

* Added back derive attrs for custom PhantomData

* Cleaned up some TODOs

* Added the ! type

* Added the ground attribute

* Use power tools in CI

* Add miri to CI

* Explicit miri component in CI

* Removed rust-toolchain

* Clarified unsafe uninit() API by constructing MaybeUninit

* Added initial inhabited calculation

* Implemented uninit() for uninhabited types

* Fixed enum + union uninit order with #[layout(bound)]

* Ignore clippy::forget_copy

* Patch for rust-lang/rust#101932

* feature(let_else) is stable in 1.66

* Annotated traits with #[const_trait]

* Strengthen TypeGraphLayout bounds

* Small clippy fixes

* Fix TypeLayoutGraph::new const bound
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-let-else Issues related to let-else statements (RFC 3137)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants