diff options
| author | Joshua Liebow-Feeser <joshlf@users.noreply.github.com> | 2023-08-28 23:47:17 -0700 |
|---|---|---|
| committer | Joshua Liebow-Feeser <joshlf@google.com> | 2023-10-14 04:41:17 +0000 |
| commit | 9703cb2deb45b2901e6a13708ba18201ee021383 (patch) | |
| tree | a3130e12d13ffdefa1001dd15b518e03e9debbb6 | |
| parent | 2a7c2df506fcd5611967a203cc994da5f21abd1e (diff) | |
| download | rust-9703cb2deb45b2901e6a13708ba18201ee021383.tar.gz rust-9703cb2deb45b2901e6a13708ba18201ee021383.zip | |
Guarantee representation of None in NPO
| -rw-r--r-- | library/core/src/option.rs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs index bdaeea66622..f01f888383d 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -119,15 +119,21 @@ //! # Representation //! //! Rust guarantees to optimize the following types `T` such that -//! [`Option<T>`] has the same size and alignment as `T`: -//! -//! * [`Box<U>`] -//! * `&U` -//! * `&mut U` -//! * `fn`, `extern "C" fn`[^extern_fn] -//! * [`num::NonZero*`] -//! * [`ptr::NonNull<U>`] -//! * `#[repr(transparent)]` struct around one of the types in this list. +//! [`Option<T>`] has the same size and alignment as `T`. In some +//! of these cases, Rust further guarantees that +//! `transmute::<_, Option<T>>([0u8; size_of::<T>()])` is sound and +//! produces `Option::<T>::None`. These cases are identified by the +//! second column: +//! +//! | `T` | `transmute::<_, Option<T>>([0u8; size_of::<T>()])` sound? | +//! |---------------------------------------------------------------------|----------------------------------------------------------------------| +//! | [`Box<U>`] | when `U: Sized` | +//! | `&U` | when `U: Sized` | +//! | `&mut U` | when `U: Sized` | +//! | `fn`, `extern "C" fn`[^extern_fn] | always | +//! | [`num::NonZero*`] | always | +//! | [`ptr::NonNull<U>`] | when `U: Sized` | +//! | `#[repr(transparent)]` struct around one of the types in this list. | when it holds for the inner type | //! //! [^extern_fn]: this remains true for any other ABI: `extern "abi" fn` (_e.g._, `extern "system" fn`) //! |
