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

Is it sound to split an UnsafeCell into multiple UnsafeCells? #458

Closed
joshlf opened this issue Sep 6, 2023 · 3 comments
Closed

Is it sound to split an UnsafeCell into multiple UnsafeCells? #458

joshlf opened this issue Sep 6, 2023 · 3 comments

Comments

@joshlf
Copy link

joshlf commented Sep 6, 2023

Miri doesn't complain about the following code, but is this guaranteed to be sound?

fn main() {
    let x = UnsafeCell::new([0u8; 2]);
    let x = &x;
    let x_ptr: *const UnsafeCell<[u8; 2]> = x;
    let y_ptr = x_ptr as *const [UnsafeCell<u8>; 2];
    let _y = unsafe { &*y_ptr };
}

I read #451 (comment) as implying this is intended to be sound, but I wanted to double-check.

@RalfJung
Copy link
Member

RalfJung commented Sep 6, 2023

@RalfJung
Copy link
Member

RalfJung commented Sep 6, 2023

Also I'd say this is a duplicate of #451; projection to struct fields and array "fields" should behave the same.

@joshlf
Copy link
Author

joshlf commented Sep 6, 2023

Sounds good, that's what I figured. Thanks!

@joshlf joshlf closed this as completed Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants