Skip to content

Commit bd0a81e

Browse files
committed
centralize aliasing rules discussion in UnsafeCell docs
1 parent bafe406 commit bd0a81e

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

library/core/src/cell.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,8 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
19141914
/// [`.get()`]: `UnsafeCell::get`
19151915
/// [concurrent memory model]: ../sync/atomic/index.html#memory-model-for-atomic-accesses
19161916
///
1917+
/// # Aliasing rules
1918+
///
19171919
/// The precise Rust aliasing rules are somewhat in flux, but the main points are not contentious:
19181920
///
19191921
/// - If you create a safe reference with lifetime `'a` (either a `&T` or `&mut T` reference), then
@@ -2167,10 +2169,9 @@ impl<T: ?Sized> UnsafeCell<T> {
21672169

21682170
/// Gets a mutable pointer to the wrapped value.
21692171
///
2170-
/// This can be cast to a pointer of any kind.
2171-
/// Ensure that the access is unique (no active references, mutable or not)
2172-
/// when casting to `&mut T`, and ensure that there are no mutations
2173-
/// or mutable aliases going on when casting to `&T`.
2172+
/// This can be cast to a pointer of any kind. When creating references, you must uphold the
2173+
/// aliasing rules; see [the type-level docs][UnsafeCell#aliasing-rules] for more discussion and
2174+
/// caveats.
21742175
///
21752176
/// # Examples
21762177
///
@@ -2219,10 +2220,9 @@ impl<T: ?Sized> UnsafeCell<T> {
22192220
/// The difference from [`get`] is that this function accepts a raw pointer,
22202221
/// which is useful to avoid the creation of temporary references.
22212222
///
2222-
/// The result can be cast to a pointer of any kind.
2223-
/// Ensure that the access is unique (no active references, mutable or not)
2224-
/// when casting to `&mut T`, and ensure that there are no mutations
2225-
/// or mutable aliases going on when casting to `&T`.
2223+
/// This can be cast to a pointer of any kind. When creating references, you must uphold the
2224+
/// aliasing rules; see [the type-level docs][UnsafeCell#aliasing-rules] for more discussion and
2225+
/// caveats.
22262226
///
22272227
/// [`get`]: UnsafeCell::get()
22282228
///

library/core/src/pin/unsafe_pinned.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,10 @@ impl<T: ?Sized> UnsafePinned<T> {
8888

8989
/// Get mutable access to the contents of a shared `UnsafePinned`.
9090
///
91-
/// This can be cast to a pointer of any kind.
92-
/// Ensure that the access is unique (no active references, mutable or not)
93-
/// when casting to `&mut T`, and ensure that there are no mutations
94-
/// or mutable aliases going on when casting to `&T`.
91+
/// This can be cast to a pointer of any kind. When creating references, you must uphold the
92+
/// aliasing rules; see [`UnsafeCell`] for more discussion and caveats.
9593
///
96-
/// All the usual caveats around mutation shared state apply, see [`UnsafeCell`].
97-
///
98-
/// [`UnsafeCell`]: crate::cell::UnsafeCell
94+
/// [`UnsafeCell`]: crate::cell::UnsafeCell#aliasing-rules
9995
///
10096
/// ```rust,no_run
10197
/// #![feature(unsafe_pinned)]

0 commit comments

Comments
 (0)