Skip to content

Commit 21b5367

Browse files
committed
Auto merge of #50898 - shepmaster:typo, r=QuietMisdreavus
UnsafeCell doc typos and minor flow improvements r? @QuietMisdreavus
2 parents 98686ca + 52249e3 commit 21b5367

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/libcore/cell.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -1231,25 +1231,26 @@ impl<'a, T: ?Sized + fmt::Display> fmt::Display for RefMut<'a, T> {
12311231
///
12321232
/// If you have a reference `&SomeStruct`, then normally in Rust all fields of `SomeStruct` are
12331233
/// immutable. The compiler makes optimizations based on the knowledge that `&T` is not mutably
1234-
/// aliased or mutated, and that `&mut T` is unique. `UnsafeCel<T>` is the only core language
1234+
/// aliased or mutated, and that `&mut T` is unique. `UnsafeCell<T>` is the only core language
12351235
/// feature to work around this restriction. All other types that allow internal mutability, such as
1236-
/// `Cell<T>` and `RefCell<T>` use `UnsafeCell` to wrap their internal data.
1236+
/// `Cell<T>` and `RefCell<T>`, use `UnsafeCell` to wrap their internal data.
12371237
///
12381238
/// The `UnsafeCell` API itself is technically very simple: it gives you a raw pointer `*mut T` to
12391239
/// its contents. It is up to _you_ as the abstraction designer to use that raw pointer correctly.
12401240
///
12411241
/// The precise Rust aliasing rules are somewhat in flux, but the main points are not contentious:
12421242
///
1243-
/// - If you create a safe reference with lifetime `'a` (either a `&T` or `&mut T` reference) that
1244-
/// is accessible by safe code (for example, because you returned it), then you must not access
1245-
/// the data in any way that contradicts that reference for the remainder of `'a`. For example, that
1246-
/// means that if you take the `*mut T` from an `UnsafeCell<T>` and case it to an `&T`, then until
1247-
/// that reference's lifetime expires, the data in `T` must remain immutable (modulo any
1248-
/// `UnsafeCell` data found within `T`, of course). Similarly, if you create an `&mut T` reference
1249-
/// that is released to safe code, then you must not access the data within the `UnsafeCell` until
1250-
/// that reference expires.
1243+
/// - If you create a safe reference with lifetime `'a` (either a `&T` or `&mut T`
1244+
/// reference) that is accessible by safe code (for example, because you returned it),
1245+
/// then you must not access the data in any way that contradicts that reference for the
1246+
/// remainder of `'a`. For example, this means that if you take the `*mut T` from an
1247+
/// `UnsafeCell<T>` and cast it to an `&T`, then the data in `T` must remain immutable
1248+
/// (modulo any `UnsafeCell` data found within `T`, of course) until that reference's
1249+
/// lifetime expires. Similarly, if you create a `&mut T` reference that is released to
1250+
/// safe code, then you must not access the data within the `UnsafeCell` until that
1251+
/// reference expires.
12511252
///
1252-
/// - At all times, you must avoid data races, meaning that if multiple threads have access to
1253+
/// - At all times, you must avoid data races. If multiple threads have access to
12531254
/// the same `UnsafeCell`, then any writes must have a proper happens-before relation to all other
12541255
/// accesses (or use atomics).
12551256
///
@@ -1259,10 +1260,10 @@ impl<'a, T: ?Sized + fmt::Display> fmt::Display for RefMut<'a, T> {
12591260
/// 1. A `&T` reference can be released to safe code and there it can co-exit with other `&T`
12601261
/// references, but not with a `&mut T`
12611262
///
1262-
/// 2. A `&mut T` reference may be released to safe code, provided neither other `&mut T` nor `&T`
1263+
/// 2. A `&mut T` reference may be released to safe code provided neither other `&mut T` nor `&T`
12631264
/// co-exist with it. A `&mut T` must always be unique.
12641265
///
1265-
/// Note that while mutating or mutably aliasing the contents of an `& UnsafeCell<T>` is
1266+
/// Note that while mutating or mutably aliasing the contents of an `&UnsafeCell<T>` is
12661267
/// okay (provided you enforce the invariants some other way), it is still undefined behavior
12671268
/// to have multiple `&mut UnsafeCell<T>` aliases.
12681269
///

0 commit comments

Comments
 (0)