UnsafeCell::get is currently implemented by simply casting the &UnsafeCell<T> to a *mut T. A comment inside it notes that this is only able to work because libcore is a special library. Should this comment still apply? Is there benefit in forcing all writes to an UnsafeCell to go through UnsafeCell::get, or should UnsafeCell be treated as just a type-level indicator that the inner data is interior mutable? Since UnsafeCell is #[repr(transparent)] I don't think it is UB to read from a casted pointer, but I'm not sure if the same logic applies to writes.
UnsafeCell::getis currently implemented by simply casting the&UnsafeCell<T>to a*mut T. A comment inside it notes that this is only able to work because libcore is a special library. Should this comment still apply? Is there benefit in forcing all writes to anUnsafeCellto go throughUnsafeCell::get, or shouldUnsafeCellbe treated as just a type-level indicator that the inner data is interior mutable? SinceUnsafeCellis#[repr(transparent)]I don't think it is UB to read from a casted pointer, but I'm not sure if the same logic applies to writes.