rust-lang / rust-lang/reference
Confusion about whether union writes ever have to be placed in `unsafe` blocks
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 607
- PR merge metrics
- PR metrics pending
Description
https://doc.rust-lang.org/reference/items/unions.html says:
Writes to
CopyorManuallyDropunion fields do not require reads for running destructors, so these writes don't have to be placed inunsafeblocks
but later also says:
When a union is dropped, it cannot know which of its fields needs to be dropped. For this reason, all union fields must either be of a
Copytype or of the shapeManuallyDrop<_>.
If the latter is true, then the former seems to be written in an overly-qualified way.
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 union section in the Rust Reference at items/unions.html and compare the two quoted statements about union field writes and dropping. Clarify the wording so the rules no longer appear contradictory; the issue is resolved when the section accurately explains when union writes require unsafe blocks.
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
- Mostly clear
- Newbie friendliness
- 35/100