rust-lang / rust-lang/reference

Confusion about whether union writes ever have to be placed in `unsafe` blocks

Open
#1,091 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Language Cleanup
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 Copy or ManuallyDrop union fields do not require reads for running destructors, so these writes don't have to be placed in unsafe blocks

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 Copy type or of the shape ManuallyDrop<_>.

If the latter is true, then the former seems to be written in an overly-qualified way.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.