rust-lang / rust-lang/reference

Guarantee that uninitialized bytes have no bit validity

Open
#1,411 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.6k
Forks
607
PR merge metrics
PR metrics pending

Description

While this has been discussed before, it's not explicitly documented in the reference.

A few open questions:

  • Does it make sense to speak about uninitialized bytes in general, or only about padding bytes? Does Rust currently have other forms of uninitialized bytes?
  • Does it make sense to also define that uninitialized bytes cannot be "observed"? Currently, the closest that we have to this is statements on bit validity for various primitive types, which refer to uninitialized bytes, but do not define what they are (e.g., bools, numeric types, etc).
    • I could see an argument that we don't need to talk about "observing" in the general sense; it is sufficient to define that it is UB to transmute an uninitialized byte to another type. In fact, it should technically be sufficient not to define that it is sound to transmute an uninitialized byte to a type; since there are no types for which this is sound, there exists no soundness proof for code which would attempt to do this regardless of "intermediate" type.
  • Where would be best to document this?

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 by reading the earlier unsafe-code-guidelines discussion and the Reference sections on bit validity for boolean and numeric types. Determine whether the Reference should define uninitialized bytes generally or only padding, and whether observation or transmutation needs explicit treatment; done means the open questions are resolved and the rule has a clear documentation location.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.