Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions library/core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,17 @@ impl<T> MaybeUninit<T> {
/// let x_init = unsafe { x.assume_init() };
/// // `x` had not been initialized yet, so this last line caused undefined behavior. ⚠️
/// ```
///
/// This also applies to simple types that can hold any bit pattern, like integers, boolean and so on.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Booleans cannot hold any bit pattern.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry my bad, a single bit, will amend that, any other improvements needed?

/// See the [type-level documentation][inv] for more details.
///
/// ```rust,no_run
/// use std::mem::MaybeUninit;
///
/// let x = MaybeUninit::<u8>::uninit();
/// let x_init = unsafe { x.assume_init() }; // undefined behavior! ⚠️
/// // Even though `u8` can represent any bit pattern, reading uninitialized memory is still undefined behaviour.
/// ```
#[stable(feature = "maybe_uninit", since = "1.36.0")]
#[rustc_const_stable(feature = "const_maybe_uninit_assume_init_by_value", since = "1.59.0")]
#[inline(always)]
Expand Down
Loading