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

Closed
Amanieu opened this issue Feb 7, 2019 · 3 comments · Fixed by #695
Closed
Labels
A-aliasing Area: This affects the aliasing model (Stacked/Tree Borrows) C-bug Category: This is a bug.

Comments

@Amanieu
Copy link
Member

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
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
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(); }
}

@RalfJung RalfJung added C-bug Category: This is a bug. A-aliasing Area: This affects the aliasing model (Stacked/Tree Borrows) labels Mar 8, 2019
@RalfJung
Copy link
Member

This will be fixed by #695, I added the examples above as a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-aliasing Area: This affects the aliasing model (Stacked/Tree Borrows) C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants