From e30555bd091740d3298869fc15ff38fdaaa6fcab Mon Sep 17 00:00:00 2001 From: laddery-a <250672660+laddery-a@users.noreply.github.com> Date: Sun, 1 Mar 2026 11:47:32 +0100 Subject: [PATCH 1/2] core: clarify assume_init UB for uninitialized integers --- library/core/src/mem/maybe_uninit.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index 5941477201933..b70879ff60b64 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -658,8 +658,8 @@ impl MaybeUninit { /// /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized /// state. Calling this when the content is not yet fully initialized causes immediate undefined - /// behavior. The [type-level documentation][inv] contains more information about - /// this initialization invariant. + /// behavior, even if `T` is an integer or other plain old data type. The [type-level + /// documentation][inv] contains more information about this initialization invariant. /// /// [inv]: #initialization-invariant /// @@ -695,6 +695,14 @@ impl MaybeUninit { /// let x_init = unsafe { x.assume_init() }; /// // `x` had not been initialized yet, so this last line caused undefined behavior. ⚠️ /// ``` + /// + /// ```rust,no_run + /// use std::mem::MaybeUninit; + /// + /// let x = MaybeUninit::::uninit(); + /// let x_init = unsafe { x.assume_init() }; + /// // `x` had not been initialized yet, so this last line caused undefined behavior. ⚠️ + /// ``` #[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)] From 3f0ac2c6513a99b6f806fc2eb6e827e2953570b7 Mon Sep 17 00:00:00 2001 From: laddery-a <250672660+laddery-a@users.noreply.github.com> Date: Sun, 1 Mar 2026 11:51:52 +0100 Subject: [PATCH 2/2] core: avoid POD wording in MaybeUninit::assume_init docs --- library/core/src/mem/maybe_uninit.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index b70879ff60b64..89cb3ddfb2480 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -658,8 +658,8 @@ impl MaybeUninit { /// /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized /// state. Calling this when the content is not yet fully initialized causes immediate undefined - /// behavior, even if `T` is an integer or other plain old data type. The [type-level - /// documentation][inv] contains more information about this initialization invariant. + /// behavior, even if `T` is an integer type. The [type-level documentation][inv] contains more + /// information about this initialization invariant. /// /// [inv]: #initialization-invariant /// @@ -695,14 +695,6 @@ impl MaybeUninit { /// let x_init = unsafe { x.assume_init() }; /// // `x` had not been initialized yet, so this last line caused undefined behavior. ⚠️ /// ``` - /// - /// ```rust,no_run - /// use std::mem::MaybeUninit; - /// - /// let x = MaybeUninit::::uninit(); - /// let x_init = unsafe { x.assume_init() }; - /// // `x` had not been initialized yet, so this last line caused undefined behavior. ⚠️ - /// ``` #[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)]