From c0851d76c95723b25712eb418b4c728b2980c60c Mon Sep 17 00:00:00 2001 From: zachs18 <8355914+zachs18@users.noreply.github.com> Date: Tue, 3 Jun 2025 00:22:10 -0500 Subject: [PATCH] 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. --- library/core/src/primitive_docs.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/core/src/primitive_docs.rs b/library/core/src/primitive_docs.rs index 10b11613f90fa..9a06e43093edb 100644 --- a/library/core/src/primitive_docs.rs +++ b/library/core/src/primitive_docs.rs @@ -1833,6 +1833,8 @@ mod prim_ref {} /// - If `T` is guaranteed to be subject to the [null pointer /// optimization](option/index.html#representation), and `E` is an enum satisfying the following /// requirements, then `T` and `E` are ABI-compatible. Such an enum `E` is called "option-like". +/// - The enum `E` uses the [`Rust` representation], and is not modified by the `align` or +/// `packed` representation modifiers. /// - The enum `E` has exactly two variants. /// - One variant has exactly one field, of type `T`. /// - All fields of the other variant are zero-sized with 1-byte alignment. @@ -1906,6 +1908,7 @@ mod prim_ref {} /// [`Pointer`]: fmt::Pointer /// [`UnwindSafe`]: panic::UnwindSafe /// [`RefUnwindSafe`]: panic::RefUnwindSafe +/// [`Rust` representation]: /// /// In addition, all *safe* function pointers implement [`Fn`], [`FnMut`], and [`FnOnce`], because /// these traits are specially known to the compiler.