|
232 | 232 | //! |
233 | 233 | //! In some cases, [`Result<T, E>`] comes with size, alignment, and ABI guarantees. |
234 | 234 | //! Specifically, one of either the `T` or `E` type must be a type that qualifies for the `Option` |
235 | | -//! [representation guarantees][opt-rep] (let's call that type `I`), and the *other* type must meet |
236 | | -//! all of the following conditions: |
237 | | -//! * Is a zero-sized type with alignment 1 (a "1-ZST"). |
238 | | -//! * Is either a struct/tuple with no fields, or an enum with no variants. |
239 | | -//! * Does not have the `#[non_exhaustive]` attribute. |
| 235 | +//! [representation guarantees][opt-rep] (let's call that type `I`), and the *other* type |
| 236 | +//! is a zero-sized type with alignment 1 (a "1-ZST"). |
240 | 237 | //! |
241 | 238 | //! If that is the case, then `Result<T, E>` has the same size, alignment, and [function call ABI] |
242 | 239 | //! as `I` (and therefore, as `Option<I>`). If `I` is `T`, it is therefore sound to transmute `t: I` |
243 | 240 | //! to `Result<T, E>` (which will produce `Ok(t)`), and to transmute `Ok(t): Result<T, E>` to `I` |
244 | 241 | //! (which will produce `t`). If `I` is `E`, the same applies with `Ok` replaced by `Err`. |
245 | 242 | //! |
246 | | -//! For example, `NonZeroI32` qualifies for the `Option` representation |
247 | | -//! guarantees, and `()` is a zero-sized type with alignment 1, no fields, and |
248 | | -//! it isn't `non_exhaustive`. This means that both `Result<NonZeroI32, ()>` and |
| 243 | +//! For example, `NonZeroI32` qualifies for the `Option` representation guarantees, and `()` is a |
| 244 | +//! zero-sized type with alignment 1. This means that both `Result<NonZeroI32, ()>` and |
249 | 245 | //! `Result<(), NonZeroI32>` have the same size, alignment, and ABI |
250 | 246 | //! as `NonZeroI32` (and `Option<NonZeroI32>`). The only difference is the implied semantics: |
251 | 247 | //! * `Option<NonZeroI32>` is "a non-zero i32 might be present" |
|
0 commit comments