Skip to content

Commit c0851d7

Browse files
committed
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 99426c5 commit c0851d7

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
@@ -1833,6 +1833,8 @@ mod prim_ref {}
18331833
/// - If `T` is guaranteed to be subject to the [null pointer
18341834
/// optimization](option/index.html#representation), and `E` is an enum satisfying the following
18351835
/// requirements, then `T` and `E` are ABI-compatible. Such an enum `E` is called "option-like".
1836+
/// - The enum `E` uses the [`Rust` representation], and is not modified by the `align` or
1837+
/// `packed` representation modifiers.
18361838
/// - The enum `E` has exactly two variants.
18371839
/// - One variant has exactly one field, of type `T`.
18381840
/// - All fields of the other variant are zero-sized with 1-byte alignment.
@@ -1906,6 +1908,7 @@ mod prim_ref {}
19061908
/// [`Pointer`]: fmt::Pointer
19071909
/// [`UnwindSafe`]: panic::UnwindSafe
19081910
/// [`RefUnwindSafe`]: panic::RefUnwindSafe
1911+
/// [`Rust` representation]: <https://doc.rust-lang.org/reference/type-layout.html#the-rust-representation>
19091912
///
19101913
/// In addition, all *safe* function pointers implement [`Fn`], [`FnMut`], and [`FnOnce`], because
19111914
/// these traits are specially known to the compiler.

0 commit comments

Comments
 (0)