Is it sound to split an `UnsafeCell` into multiple `UnsafeCell`s?
joshlf opened this issue · comments
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.
Isn't this basically https://doc.rust-lang.org/nightly/std/cell/struct.Cell.html#method.as_array_of_cells ?
Also I'd say this is a duplicate of #451; projection to struct fields and array "fields" should behave the same.
Sounds good, that's what I figured. Thanks!