Skip to content

Commit e4c62ac

Browse files
committed
Indicate that all types subject to mandatory discriminant elision are abi compatible with their *elision candidate field*s
1 parent 97cd91f commit e4c62ac

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/abi.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,13 @@ A [`struct`] declared with the `transparent` representation is *abi compatible*
132132
r[abi.compatibility.zst]
133133
Two types, `T` and `U`, are *abi compatible* if both have size 0 and alignment 1.
134134

135-
r[abi.compatibility.option]
136-
If `T` is a type listed in [layout.enum.option](https://doc.rust-lang.org/stable/core/option/index.html#representation), then given `S` is a type with size 0 and alignment 1, `T` is *abi compatible* with the types [`core::option::Option<T>`], [`core::result::Result<T,S>`], and [`core::result::Result<S,T>`].
135+
r[abi.compatibility.discriminant]
136+
If `T` is an a type listed in [layout.repr.rust.option.elision], and `U` is the type of the *elision candidate field*, then `T` is layout compatible with `U`.
137+
138+
> [!NOTE]
139+
> `Option<U>`, `Result<U,Z>`, or `Result<Z,U>` are such types, when `U` are *elision candidate type*s, and `Z` is a 1-ZST type.
140+
>
141+
> Due to transitivity, two such types are *abi compatible* with each other if their *elision candidate field*s are *abi comaptible*
137142
138143
r[abi.compatibility.fn-ptr]
139144
An [function pointer] type `T` is *abi compatible* with an [function pointer] type `U` if `T` and `U` have *abi compatible* tags.
@@ -206,6 +211,8 @@ The behavior of a call that is not valid is undefined.
206211
[`__m512f`]: https://doc.rust-lang.org/stable/core/arch/x86_64/struct.__m512f.html
207212
[`__m512d`]: https://doc.rust-lang.org/stable/core/arch/x86_64/struct.__m512d.html
208213

214+
[layout.repr.rust.option]: https://github.com/RalfJung/unsafe-code-guidelines/blob/option-like/reference/src/layout/enums.md#discriminant-elision-on-option-like-enums
215+
209216
## The `used` attribute
210217

211218
r[abi.used]

0 commit comments

Comments
 (0)