-
Notifications
You must be signed in to change notification settings - Fork 61
Open
Description
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 😃
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels