reference icon indicating copy to clipboard operation
reference copied to clipboard

fix field-less repr(C) enum docs

Open RalfJung opened this issue 3 months ago • 1 comments

The docs for field-less repr(C) enums are wrong in the sense that they say "the C representation has the size and alignment of the default enum size and alignment for the target platform's C ABI" which implies that there's a single size and alignment (determined by the target) that all repr(C) enums share -- which isn't true. The size of the enum depends on the discriminant values and is intended to mimic what the default C compiler for the target would do with an enum that has the same discriminant values.

Also, it seems worth mentioning the type that the discriminant expressions of an enum are type-checked at: that's isize for all enums expect those with primitive representation.

This PR presupposes that we are going ahead with https://github.com/rust-lang/rust/pull/147017 and documents things as-if the FCW added there was already a hard error. This is mostly because otherwise it's unclear what we should document as the logic before that bug doesn't always match the target's C compiler (see https://github.com/rust-lang/rust/pull/146504).

RalfJung avatar Sep 25 '25 19:09 RalfJung

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

rustbot avatar Dec 09 '25 22:12 rustbot