Skip to content

docs: clarify that reading uninit memory is UB even for POD types#153248

Closed
Not-Sarthak wants to merge 1 commit intorust-lang:mainfrom
Not-Sarthak:fix-150689-maybeuninit-docs
Closed

docs: clarify that reading uninit memory is UB even for POD types#153248
Not-Sarthak wants to merge 1 commit intorust-lang:mainfrom
Not-Sarthak:fix-150689-maybeuninit-docs

Conversation

@Not-Sarthak
Copy link

@Not-Sarthak Not-Sarthak commented Mar 1, 2026

Summary

  • Adds a paragraph to MaybeUninit::assume_init docs clarifying that uninitialized memory is UB even for types where every bit pattern is valid (like u8, i32)
  • Adds a u8 example to the "incorrect usage" section to make this concrete
  • Directs readers to the type-level documentation for more details

Closes #150689

Test plan

  • ./x test tidy --bless passes
  • Doc examples render correctly with ./x doc library/core
  • No changes to compiled code — documentation only

@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 Mar 1, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 1, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, joboet, scottmcm

@rustbot

This comment has been minimized.

MaybeUninit::assume_init docs now explicitly state that uninitialized
memory is undefined behavior even for types where every bit pattern is
valid (like u8 or i32), since uninitialized data is not a fixed value.
Also adds a u8 example to the "incorrect usage" section.
@Not-Sarthak Not-Sarthak force-pushed the fix-150689-maybeuninit-docs branch from b87104a to 2494b7f Compare March 1, 2026 07:10
@Not-Sarthak
Copy link
Author

Closing as duplicate of #153030

@Not-Sarthak Not-Sarthak closed this Mar 1, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Docs for MaybeUninit::assume_init should indicate that reading uninit POD isn't sound

3 participants