Location (URL)
https://doc.rust-lang.org/stable/std/cell/struct.UnsafeCell.html
Summary
The documentation has extensive explanation of how to obtain and use an *mut T or &mut T from UnsafeCell<T> and use that pointer to mutate the cell. However, it says nothing explicitly about the means to, and the safety considerations of, obtaining &Ts which derive from and overlap with an &UnsafeCell<T>, or any other situations involving immutable references. For example, if one is working with bulk data, one might have these questions:
-
Is it sound to cast &UnsafeCell<[T]> to &[UnsafeCell<T>]?
The implementation of Cell::as_slice_of_cells() implies that it is, so it would be desirable to have the more general property documented.
-
Is it sound to cast &[UnsafeCell<T>] to &UnsafeCell<[T]>?
-
Is it sound to cast &[UnsafeCell<T>] to &[T], provided no mutation occurs while the reference is in use?
UCG says this is not yet definitively OK because SB rejects it but the library documentation should at least explicitly caveat this.
@rustbot label +T-libs +T-opsem
Location (URL)
https://doc.rust-lang.org/stable/std/cell/struct.UnsafeCell.html
Summary
The documentation has extensive explanation of how to obtain and use an
*mut Tor&mut TfromUnsafeCell<T>and use that pointer to mutate the cell. However, it says nothing explicitly about the means to, and the safety considerations of, obtaining&Ts which derive from and overlap with an&UnsafeCell<T>, or any other situations involving immutable references. For example, if one is working with bulk data, one might have these questions:Is it sound to cast
&UnsafeCell<[T]>to&[UnsafeCell<T>]?The implementation of
Cell::as_slice_of_cells()implies that it is, so it would be desirable to have the more general property documented.Is it sound to cast
&[UnsafeCell<T>]to&UnsafeCell<[T]>?Is it sound to cast
&[UnsafeCell<T>]to&[T], provided no mutation occurs while the reference is in use?UCG says this is not yet definitively OK because SB rejects it but the library documentation should at least explicitly caveat this.
@rustbot label +T-libs +T-opsem