Skip to content

Doc for size of unions in core - #166616

Open
giltho wants to merge 1 commit into
rust-lang:mainfrom
giltho:core-doc-reprc-union
Open

giltho wants to merge 1 commit into
rust-lang:mainfrom
giltho:core-doc-reprc-union

Conversation

@giltho

@giltho giltho commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

The doc for the size of repr(C) unions in core was slightly unclear. It said "The size of a union is the size of its largest field", which isn't quite true.

Take

union U { a: [u8; 3], b: u16 }

The size and alignment of a are respectively 3 and 1, and it's 2 and 2 for b.
The sentence seems to imply that the size of U is 3, when it's in fact 4, because it is rounded to the largest alignment of any of the fields.

The Reference is already correct:

The union will have a size of the maximum size of all of its fields rounded to its alignment, and an alignment of the maximum alignment of all of its fields.

I went for a slightly different wording because the above sentence made me pause for a second, there's an ambiguity to what its in its alignment refers to (is it the field with the maximum size or the union?). Technically, I understand that the english is not ambiguous, but I had to read it three times to be sure, so I thought I'd go with another wording

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 26, 2026
@rustbot

rustbot commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 38 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, clarfonthey, jhpratt, joboet

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants