|
120 | 120 | //! |
121 | 121 | //! Rust guarantees to optimize the following types `T` such that |
122 | 122 | //! [`Option<T>`] has the same size, alignment, and [function call ABI] 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>`] (specifically, only `Box<U, Global>`) | 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 | |
| 123 | +//! of these cases, Rust further guarantees the following: |
| 124 | +//! - `transmute::<_, Option<T>>([0u8; size_of::<T>()])` is sound and produces |
| 125 | +//! `Option::<T>::None` |
| 126 | +//! - `transmute::<_, [u8; size_of::<T>()]>(Option::<T>::None)` is sound and produces |
| 127 | +//! `[0u8; size_of::<T>()]` |
| 128 | +//! These cases are identified by the second column: |
| 129 | +//! |
| 130 | +//! | `T` | Transmuting between `[0u8; size_of::<T>()]` and `Option::<T>::None` sound? | |
| 131 | +//! |---------------------------------------------------------------------|----------------------------------------------------------------------------| |
| 132 | +//! | [`Box<U>`] (specifically, only `Box<U, Global>`) | when `U: Sized` | |
| 133 | +//! | `&U` | when `U: Sized` | |
| 134 | +//! | `&mut U` | when `U: Sized` | |
| 135 | +//! | `fn`, `extern "C" fn`[^extern_fn] | always | |
| 136 | +//! | [`num::NonZero*`] | always | |
| 137 | +//! | [`ptr::NonNull<U>`] | when `U: Sized` | |
| 138 | +//! | `#[repr(transparent)]` struct around one of the types in this list. | when it holds for the inner type | |
137 | 139 | //! |
138 | 140 | //! [^extern_fn]: this remains true for any argument/return types and any other ABI: `extern "abi" fn` (_e.g._, `extern "system" fn`) |
139 | 141 | //! |
|
0 commit comments