This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Original file line number Diff line number Diff line change 119119//! # Representation
120120//!
121121//! Rust guarantees to optimize the following types `T` such that
122- //! [`Option<T>`] has the same size and alignment as `T`:
123- //!
124- //! * [`Box<U>`]
125- //! * `&U`
126- //! * `&mut U`
127- //! * `fn`, `extern "C" fn`[^extern_fn]
128- //! * [`num::NonZero*`]
129- //! * [`ptr::NonNull<U>`]
130- //! * `#[repr(transparent)]` struct around one of the types in this list.
122+ //! [`Option<T>`] has the same size and alignment as `T`. In some
123+ //! of these cases, Rust further guarantees that
124+ //! `transmute::<_, Option<T>>([0u8; size_of::<T>()])` is sound and
125+ //! produces `Option::<T>::None`. These cases are identified by the
126+ //! second column:
127+ //!
128+ //! | `T` | `transmute::<_, Option<T>>([0u8; size_of::<T>()])` sound? |
129+ //! |---------------------------------------------------------------------|----------------------------------------------------------------------|
130+ //! | [`Box<U>`] | when `U: Sized` |
131+ //! | `&U` | when `U: Sized` |
132+ //! | `&mut U` | when `U: Sized` |
133+ //! | `fn`, `extern "C" fn`[^extern_fn] | always |
134+ //! | [`num::NonZero*`] | always |
135+ //! | [`ptr::NonNull<U>`] | when `U: Sized` |
136+ //! | `#[repr(transparent)]` struct around one of the types in this list. | when it holds for the inner type |
131137//!
132138//! [^extern_fn]: this remains true for any other ABI: `extern "abi" fn` (_e.g._, `extern "system" fn`)
133139//!
You can’t perform that action at this time.
0 commit comments