-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Description
Currently, Cell<T> and UnsafeCell<T> are both #[repr(transparent)]. However, it is unclear whether this is stable or just an implementation detail. This line in the implementation of UnsafeCell notes that "there is no guarantee for user code that this [casting a *const UnsafeCell<T> to *mut T] will work in future versions of the compiler"; but it is unclear whether this applies to the casting of *const UnsafeCell<T> to *const T or the casting of *const T to *mut T. as_slice_of_cells also relies on the layout of UnsafeCell, but makes no mention of it being exclusive to std.
Even if they do stably have a transparent layout, there are also some questions to be resolved around whether creating UnsafeCells from references is UB; conversions like *const T to *const UnsafeCell<T>, &T to &UnsafeCell<T>, &mut T to &UnsafeCell<T>, &[UnsafeCell<T>] to &UnsafeCell<[T]> should all probably be specified.