Doc clarification for MaybeUninit::zeroed()
#74343
Labels
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
👋 Hi! While reading the documentation for
MaybeUninit::zeroed()
I found it unclear whether using this method for a struct where0
is an invalid bit pattern is correct usage or not.The method description makes it clear that it is acceptable to use this method, only a user cannot assume that it is already valid.
https://doc.rust-lang.org/std/mem/union.MaybeUninit.html#method.zeroed
However, the example introduces some ambiguity.
This phrasing seems to suggest that you should not use
MaybeUninit::zeroed()
when 0 is not a valid bit pattern. However, I believe the intent is to merely to convey that callingassume_init()
without otherwise initializing the value is invalid.There are some valid use cases to zero the memory to prevent an accidental security issue from mis-initialization, even if the bit pattern is invalid.
Suggested alternate phrasing:
The text was updated successfully, but these errors were encountered: