@@ -1766,15 +1766,24 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
17661766///
17671767/// The precise Rust aliasing rules are somewhat in flux, but the main points are not contentious:
17681768///
1769- /// - If you create a safe reference with lifetime `'a` (either a `&T` or `&mut T`
1770- /// reference) that is accessible by safe code (for example, because you returned it),
1771- /// then you must not access the data in any way that contradicts that reference for the
1772- /// remainder of `'a`. For example, this means that if you take the `*mut T` from an
1773- /// `UnsafeCell<T>` and cast it to an `&T`, then the data in `T` must remain immutable
1774- /// (modulo any `UnsafeCell` data found within `T`, of course) until that reference's
1775- /// lifetime expires. Similarly, if you create a `&mut T` reference that is released to
1776- /// safe code, then you must not access the data within the `UnsafeCell` until that
1777- /// reference expires.
1769+ /// - If you create a safe reference with lifetime `'a` (either a `&T` or `&mut T` reference), then
1770+ /// you must not access the data in any way that contradicts that reference for the remainder of
1771+ /// `'a`. For example, this means that if you take the `*mut T` from an `UnsafeCell<T>` and cast it
1772+ /// to an `&T`, then the data in `T` must remain immutable (modulo any `UnsafeCell` data found
1773+ /// within `T`, of course) until that reference's lifetime expires. Similarly, if you create a `&mut
1774+ /// T` reference that is released to safe code, then you must not access the data within the
1775+ /// `UnsafeCell` until that reference expires.
1776+ ///
1777+ /// - For both `&T` without `UnsafeCell<_>` and `&mut T`, you must also not deallocate the data
1778+ /// until the reference expires. As a special exception, given an `&T`, any part of it that is
1779+ /// inside an `UnsafeCell<_>` may be deallocated during the lifetime of the reference, after the
1780+ /// last time the reference is used (dereferenced or reborrowed). Since you cannot deallocate a part
1781+ /// of what a reference points to, this means the memory an `&T` points to can be deallocted only if
1782+ /// *every part of it* (including padding) is inside an `UnsafeCell`.
1783+ ///
1784+ /// However, whenever a `&UnsafeCell<T>` is constructed or dereferenced, it must still point to
1785+ /// live memory and the compiler is allowed to insert spurious reads if it can prove that this
1786+ /// memory has not yet been deallocated.
17781787///
17791788/// - At all times, you must avoid data races. If multiple threads have access to
17801789/// the same `UnsafeCell`, then any writes must have a proper happens-before relation to all other
0 commit comments