Skip to content

Commit f1c1fc2

Browse files
committed
rephrase UnsafeCell doc
Make UnsafeCell doc easier to follow
1 parent 4d2d3fc commit f1c1fc2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/libcore/cell.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,11 +1164,12 @@ impl<'a, T: ?Sized + fmt::Display> fmt::Display for RefMut<'a, T> {
11641164
/// The compiler makes optimizations based on the knowledge that `&T` is not mutably aliased or
11651165
/// mutated, and that `&mut T` is unique. When building abstractions like `Cell`, `RefCell`,
11661166
/// `Mutex`, etc, you need to turn these optimizations off. `UnsafeCell` is the only legal way
1167-
/// to do this. When `UnsafeCell<T>` is immutably aliased, it is still safe to obtain a mutable
1168-
/// reference to its interior and/or to mutate it. However, it is up to the abstraction designer
1169-
/// to ensure that no two mutable references obtained this way are active at the same time, and
1170-
/// that there are no active mutable references or mutations when an immutable reference is obtained
1171-
/// from the cell. This is often done via runtime checks.
1167+
/// to do this. When `UnsafeCell<T>` _itself_ is immutably aliased, it is still safe to obtain
1168+
/// a mutable reference to its _interior_ and/or to mutate the interior. However, it is up to
1169+
/// the abstraction designer to ensure that no two mutable references obtained this way are active
1170+
/// at the same time, there are no active immutable reference when a mutable reference is obtained
1171+
/// from the cell, and that there are no active mutable references or mutations when an immutable
1172+
/// reference is obtained. This is often done via runtime checks.
11721173
///
11731174
/// Note that while mutating or mutably aliasing the contents of an `& UnsafeCell<T>` is
11741175
/// okay (provided you enforce the invariants some other way); it is still undefined behavior
@@ -1240,9 +1241,9 @@ impl<T: ?Sized> UnsafeCell<T> {
12401241
/// Gets a mutable pointer to the wrapped value.
12411242
///
12421243
/// This can be cast to a pointer of any kind.
1243-
/// Ensure that the access is unique when casting to
1244-
/// `&mut T`, and ensure that there are no mutations or mutable
1245-
/// aliases going on when casting to `&T`
1244+
/// Ensure that the access is unique (no active references, mutable or not)
1245+
/// when casting to `&mut T`, and ensure that there are no mutations
1246+
/// or mutable aliases going on when casting to `&T`
12461247
///
12471248
/// # Examples
12481249
///

0 commit comments

Comments
 (0)