about summary refs log tree commit diff
path: root/tests/rustdoc-js-std/doc-alias-use.js
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-06-12 20:03:36 +0200
committerGitHub <noreply@github.com>2025-06-12 20:03:36 +0200
commit0c81fd0743a23d6fc1d3655b542a62cfb2c7bc9a (patch)
treebdfa62dc34345cfd134848c1fe182bb64f53d95d /tests/rustdoc-js-std/doc-alias-use.js
parent94e8a2448f8aa9e9715fef0f7253a1e5a0a2c423 (diff)
parentc0851d76c95723b25712eb418b4c728b2980c60c (diff)
downloadrust-0c81fd0743a23d6fc1d3655b542a62cfb2c7bc9a.tar.gz
rust-0c81fd0743a23d6fc1d3655b542a62cfb2c7bc9a.zip
Rollup merge of #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: https://github.com/rust-lang/rust/pull/130628#issuecomment-2402761599 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``````
Diffstat (limited to 'tests/rustdoc-js-std/doc-alias-use.js')
0 files changed, 0 insertions, 0 deletions