Skip to content

Commit a10ace2

Browse files
zachs18nealsid
authored andcommitted
Update ABI compatibility docs about null-pointer-optimized enums.
Add that the enum must be `#[repr(Rust)]` and not `#[repr(packed)]` or `#[repr(align)]` in order to be ABI-compatible with its null-pointer-optimized field.
1 parent 5b08178 commit a10ace2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

library/core/src/primitive_docs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,8 @@ mod prim_ref {}
18471847
/// - If `T` is guaranteed to be subject to the [null pointer
18481848
/// optimization](option/index.html#representation), and `E` is an enum satisfying the following
18491849
/// requirements, then `T` and `E` are ABI-compatible. Such an enum `E` is called "option-like".
1850+
/// - The enum `E` uses the [`Rust` representation], and is not modified by the `align` or
1851+
/// `packed` representation modifiers.
18501852
/// - The enum `E` has exactly two variants.
18511853
/// - One variant has exactly one field, of type `T`.
18521854
/// - All fields of the other variant are zero-sized with 1-byte alignment.
@@ -1920,6 +1922,7 @@ mod prim_ref {}
19201922
/// [`Pointer`]: fmt::Pointer
19211923
/// [`UnwindSafe`]: panic::UnwindSafe
19221924
/// [`RefUnwindSafe`]: panic::RefUnwindSafe
1925+
/// [`Rust` representation]: <https://doc.rust-lang.org/reference/type-layout.html#the-rust-representation>
19231926
///
19241927
/// In addition, all *safe* function pointers implement [`Fn`], [`FnMut`], and [`FnOnce`], because
19251928
/// these traits are specially known to the compiler.

0 commit comments

Comments
 (0)