@@ -1231,25 +1231,26 @@ impl<'a, T: ?Sized + fmt::Display> fmt::Display for RefMut<'a, T> {
1231
1231
///
1232
1232
/// If you have a reference `&SomeStruct`, then normally in Rust all fields of `SomeStruct` are
1233
1233
/// 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
1235
1235
/// 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.
1237
1237
///
1238
1238
/// The `UnsafeCell` API itself is technically very simple: it gives you a raw pointer `*mut T` to
1239
1239
/// its contents. It is up to _you_ as the abstraction designer to use that raw pointer correctly.
1240
1240
///
1241
1241
/// The precise Rust aliasing rules are somewhat in flux, but the main points are not contentious:
1242
1242
///
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.
1251
1252
///
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
1253
1254
/// the same `UnsafeCell`, then any writes must have a proper happens-before relation to all other
1254
1255
/// accesses (or use atomics).
1255
1256
///
@@ -1259,10 +1260,10 @@ impl<'a, T: ?Sized + fmt::Display> fmt::Display for RefMut<'a, T> {
1259
1260
/// 1. A `&T` reference can be released to safe code and there it can co-exit with other `&T`
1260
1261
/// references, but not with a `&mut T`
1261
1262
///
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`
1263
1264
/// co-exist with it. A `&mut T` must always be unique.
1264
1265
///
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
1266
1267
/// okay (provided you enforce the invariants some other way), it is still undefined behavior
1267
1268
/// to have multiple `&mut UnsafeCell<T>` aliases.
1268
1269
///
0 commit comments