|
7 | 7 | // those terms.
|
8 | 8 |
|
9 | 9 | use core::{
|
10 |
| - cell::UnsafeCell, |
| 10 | + cell::{Cell, UnsafeCell}, |
11 | 11 | mem::{ManuallyDrop, MaybeUninit},
|
12 | 12 | num::Wrapping,
|
13 | 13 | ptr::NonNull,
|
@@ -405,20 +405,44 @@ safety_comment! {
|
405 | 405 | unsafe_impl_invariants_eq!(T => T, Wrapping<T>);
|
406 | 406 |
|
407 | 407 | /// SAFETY:
|
408 |
| - /// - `Unalign<T>` has the same size as `T` [1]. |
409 |
| - /// - Per [1], `Unalign<T>` has the same bit validity as `T`. Technically |
| 408 | + /// - `UnsafeCell<T>` has the same size as `T` [1]. |
| 409 | + /// - Per [1], `UnsafeCell<T>` has the same bit validity as `T`. Technically |
410 | 410 | /// the term "representation" doesn't guarantee this, but the subsequent
|
411 | 411 | /// sentence in the documentation makes it clear that this is the
|
412 | 412 | /// intention.
|
413 | 413 | ///
|
414 | 414 | /// [1] Per https://doc.rust-lang.org/1.81.0/core/cell/struct.UnsafeCell.html#memory-layout:
|
415 | 415 | ///
|
416 |
| - /// `UnsafeCell<T>` has the same in-memory representation as its inner type |
417 |
| - /// `T`. A consequence of this guarantee is that it is possible to convert |
418 |
| - /// between `T` and `UnsafeCell<T>`. |
| 416 | + /// `UnsafeCell<T>` has the same in-memory representation as its inner |
| 417 | + /// type `T`. A consequence of this guarantee is that it is possible to |
| 418 | + /// convert between `T` and `UnsafeCell<T>`. |
419 | 419 | unsafe_impl_for_transparent_wrapper!(T: ?Sized => UnsafeCell<T>);
|
| 420 | + |
| 421 | + /// SAFETY: |
| 422 | + /// - `Cell<T>` has the same size as `T` [1]. |
| 423 | + /// - Per [1], `Cell<T>` has the same bit validity as `T`. Technically the |
| 424 | + /// term "representation" doesn't guarantee this, but it does promise to |
| 425 | + /// have the "same memory layout and caveats as `UnsafeCell<T>`." The |
| 426 | + /// `UnsafeCell` docs [2] make it clear that bit validity is the intention |
| 427 | + /// even if that phrase isn't used. |
| 428 | + /// |
| 429 | + /// [1] Per https://doc.rust-lang.org/1.85.0/std/cell/struct.Cell.html#memory-layout: |
| 430 | + /// |
| 431 | + /// `Cell<T>` has the same memory layout and caveats as `UnsafeCell<T>`. |
| 432 | + /// In particular, this means that `Cell<T>` has the same in-memory |
| 433 | + /// representation as its inner type `T`. |
| 434 | + /// |
| 435 | + /// [2] Per https://doc.rust-lang.org/1.81.0/core/cell/struct.UnsafeCell.html#memory-layout: |
| 436 | + /// |
| 437 | + /// `UnsafeCell<T>` has the same in-memory representation as its inner |
| 438 | + /// type `T`. A consequence of this guarantee is that it is possible to |
| 439 | + /// convert between `T` and `UnsafeCell<T>`. |
| 440 | + unsafe_impl_for_transparent_wrapper!(T: ?Sized => Cell<T>); |
420 | 441 | }
|
421 | 442 |
|
| 443 | +impl_transitive_transmute_from!(T: ?Sized => Cell<T> => T => UnsafeCell<T>); |
| 444 | +impl_transitive_transmute_from!(T: ?Sized => UnsafeCell<T> => T => Cell<T>); |
| 445 | + |
422 | 446 | // SAFETY: `MaybeUninit<T>` has no validity requirements. Currently this is not
|
423 | 447 | // explicitly guaranteed, but it's obvious from `MaybeUninit`'s documentation
|
424 | 448 | // that this is the intention:
|
|
0 commit comments