mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 06:35:27 +00:00
Explicitly document the size guarantees that Option makes.
Triggered by a discussion on wg-unsafe-code-guidelines about which layouts of `Option<T>` one can guarantee are optimised to a single pointer.
This commit is contained in:
parent
5989bf4872
commit
73ada2d404
@ -70,10 +70,18 @@
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! This usage of [`Option`] to create safe nullable pointers is so
|
||||
//! common that Rust does special optimizations to make the
|
||||
//! representation of [`Option`]`<`[`Box<T>`]`>` a single pointer. Optional pointers
|
||||
//! in Rust are stored as efficiently as any other pointer type.
|
||||
//! # Representation
|
||||
//!
|
||||
//! Rust guarantees to optimise the following inner types such that an [`Option`] which contains
|
||||
//! them has the same size as a pointer:
|
||||
//!
|
||||
//! * `&T`
|
||||
//! * `&mut T`
|
||||
//! * `extern "C" fn`
|
||||
//! * [`num::NonZero*`]
|
||||
//! * [`ptr::NonNull<T>`]
|
||||
//! * `#[repr(transparent)]` struct around one of the types in this list.
|
||||
//! * [`Box<T>`]
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
|
Loading…
Reference in New Issue
Block a user