rust-lang / rust-lang/reference
Warn that `repr(packed)` and `repr(align)` do not guarantee field order, and as a result do not guarantee size
Open
Beginner friendly
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 607
- PR merge metrics
- PR metrics pending
Description
While this is already implied by the type layout docs, it's easy to miss since the type layout docs describe reprs as guaranteeing things about the layout, and the special case of repr(packed(1)) does guarantee size.
In particular, call out the following:
- A
repr(packed(N))struct's size may change depending on field order- As a special case, a
repr(packed(1))orrepr(packed)struct's size does not depend on field order
- As a special case, a
- A
repr(align(N))struct's size may change depending on field order - In each of these cases, suggest using
repr(C)to guarantee field order if guaranteed size is important
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked type layout documentation and read the sections on repr(packed) and repr(align). Update the documentation to explain field-order effects on size, the repr(packed(1)) and repr(packed) exception, and when repr(C) is needed; done means all three cases are stated clearly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100