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

MaybeUninit+Cell results in constant evaluation error: Location is not frozen long enough #615

Open
Amanieu opened this Issue Feb 7, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@Amanieu
Copy link

Amanieu commented Feb 7, 2019

The following code triggers an error in miri:

#![feature(maybe_uninit)]
use std::mem::MaybeUninit;
use std::cell::Cell;

fn main() {
    let x: MaybeUninit<(Cell<u32>, u32)> = MaybeUninit::uninitialized();
    x.as_ptr();
}
error[E0080]: constant evaluation error: Location is not frozen long enough
    --> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/mem.rs:1141:20
     |
1141 |         unsafe { &*self.value as *const T }
     |                    ^^^^^^^^^^ Location is not frozen long enough
     |
note: inside call to `<std::mem::MaybeUninit<T>><(std::cell::Cell<u32>, u32)>::as_ptr` at src/main.rs:7:5
    --> src/main.rs:7:5
     |
7    |     x.as_ptr();
     |     ^^^^^^^^^^
     = note: inside call to `main` at /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:64:34
@RalfJung

This comment has been minimized.

Copy link
Member

RalfJung commented Feb 7, 2019

Ah, I figured there'd be a Cell involved. :/

This is a Stacked Borrows model issue (not an implementation bug) that gets "fixed" by implementing rust-lang/rfcs#2582, but not really.

@RalfJung

This comment has been minimized.

Copy link
Member

RalfJung commented Feb 8, 2019

This version of the problem is worse:

#![feature(maybe_uninit)]
use std::mem::MaybeUninit;
use std::cell::Cell;

fn main() {
    let mut x: MaybeUninit<(Cell<u32>, u32)> = MaybeUninit::uninitialized();
    x.set((Cell::new(0), 0));
    unsafe { x.get_ref(); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.