Commit 0c81fd0
authored
Rollup merge of rust-lang#141947 - zachs18:patch-4, r=workingjubilee,traviscross
Specify that "option-like" enums must be `#[repr(Rust)]` to be ABI-compatible with their non-1ZST field.
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.
The specific rules here were decided on here: rust-lang#130628 (comment) but `repr` was not mentioned. In practice, only `#[repr(Rust)]` (or no `repr` attribute, which is equivalent) works for this, so add that to the docs.
-----
Restrict to `#[repr(Rust)]` only, since:
* `#[repr(C)]` and the primitive representations (`#[repr(u8)]` etc) definitely disqualify the enum from NPO, since they have defined layouts that store the tag separately to the payload.
* `#[repr(transparent)]` enums are covered two bullet points above this (line 1830), and cannot have multiple variants, so would fail the "The enum has exactly two variants" requirement anyway.
As for `#[repr(align)]`: my current wording that it is completely disallowed may be too strong: it seems like `#[repr(align(<= alignment of T))] enum Foo { X, Y(T) }` currently does still have the same ABI as `T` in practice, though this may not be something we want to promise. (`#[repr(align(> alignment of T))]` definitely disqualifies the enum from being ABI-compatible with T currently).
I added the note about `packed` to match `align`, but `#[repr(packed)]` currently can't be applied to `enum`s at all anyway, so might be unnecessary.
-----
I think this needs T-lang approval?
cc ``````@workingjubilee``````1 file changed
+3
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1847 | 1847 | | |
1848 | 1848 | | |
1849 | 1849 | | |
| 1850 | + | |
| 1851 | + | |
1850 | 1852 | | |
1851 | 1853 | | |
1852 | 1854 | | |
| |||
1920 | 1922 | | |
1921 | 1923 | | |
1922 | 1924 | | |
| 1925 | + | |
1923 | 1926 | | |
1924 | 1927 | | |
1925 | 1928 | | |
| |||
0 commit comments