Obviously it doesn't in practice, but is this guaranteed? In particular, is the following code guaranteed to be sound?
fn read_box_as_raw_ptr<T: Sized>(b: &Box<T>) -> *const T {
let b_ptr: *const Box<T> = b;
let ptr_ptr = b_ptr.cast::<*const T>();
unsafe { core::ptr::read(ptr_ptr) }
}
In particular, this would be unsound if Box contained any UnsafeCells because it would run afoul of aliasing rules. The std::boxed docs guarantee that, for T: Sized, Box<T> is ABI-compatible with *const T, but this could in principle just be talking about value transmutations, which don't technically rule out UnsafeCell.
Specifically, my question is: Is it consistent to read the std::boxed docs as logically implying that Box does not contain any UnsafeCells? If not, I'll put up a PR 😃
Obviously it doesn't in practice, but is this guaranteed? In particular, is the following code guaranteed to be sound?
In particular, this would be unsound if
Boxcontained anyUnsafeCells because it would run afoul of aliasing rules. Thestd::boxeddocs guarantee that, forT: Sized,Box<T>is ABI-compatible with*const T, but this could in principle just be talking about value transmutations, which don't technically rule outUnsafeCell.Specifically, my question is: Is it consistent to read the
std::boxeddocs as logically implying thatBoxdoes not contain anyUnsafeCells? If not, I'll put up a PR 😃