From fc4056ec78ca113d5296634cb59c9dd3325c1153 Mon Sep 17 00:00:00 2001 From: nxsaken Date: Sun, 9 Nov 2025 20:21:12 +0400 Subject: [PATCH 1/2] Constify `ManuallyDrop::take` --- library/core/src/mem/manually_drop.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/core/src/mem/manually_drop.rs b/library/core/src/mem/manually_drop.rs index 334a4b7119a11..b2328fcf7d844 100644 --- a/library/core/src/mem/manually_drop.rs +++ b/library/core/src/mem/manually_drop.rs @@ -217,8 +217,9 @@ impl ManuallyDrop { /// #[must_use = "if you don't need the value, you can use `ManuallyDrop::drop` instead"] #[stable(feature = "manually_drop_take", since = "1.42.0")] + #[rustc_const_unstable(feature = "const_manually_drop_take", issue = "none")] #[inline] - pub unsafe fn take(slot: &mut ManuallyDrop) -> T { + pub const unsafe fn take(slot: &mut ManuallyDrop) -> T { // SAFETY: we are reading from a reference, which is guaranteed // to be valid for reads. unsafe { ptr::read(&slot.value) } From 356484783228e1761866b54a7341d1c96f003fcc Mon Sep 17 00:00:00 2001 From: nxsaken Date: Sun, 9 Nov 2025 21:07:54 +0400 Subject: [PATCH 2/2] Constify `DropGuard` methods --- library/core/src/mem/drop_guard.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/library/core/src/mem/drop_guard.rs b/library/core/src/mem/drop_guard.rs index fecc94b815e97..9d929c3b8a315 100644 --- a/library/core/src/mem/drop_guard.rs +++ b/library/core/src/mem/drop_guard.rs @@ -1,4 +1,5 @@ use crate::fmt::{self, Debug}; +use crate::marker::Destruct; use crate::mem::ManuallyDrop; use crate::ops::{Deref, DerefMut}; @@ -84,8 +85,12 @@ where /// assert_eq!(DropGuard::into_inner(guard), "Nori likes chicken"); /// ``` #[unstable(feature = "drop_guard", issue = "144426")] + #[rustc_const_unstable(feature = "const_drop_guard", issue = "none")] #[inline] - pub fn into_inner(guard: Self) -> T { + pub const fn into_inner(guard: Self) -> T + where + F: [const] Destruct, + { // First we ensure that dropping the guard will not trigger // its destructor let mut guard = ManuallyDrop::new(guard); @@ -106,7 +111,8 @@ where } #[unstable(feature = "drop_guard", issue = "144426")] -impl Deref for DropGuard +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const Deref for DropGuard where F: FnOnce(T), { @@ -118,7 +124,8 @@ where } #[unstable(feature = "drop_guard", issue = "144426")] -impl DerefMut for DropGuard +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const DerefMut for DropGuard where F: FnOnce(T), { @@ -128,9 +135,10 @@ where } #[unstable(feature = "drop_guard", issue = "144426")] -impl Drop for DropGuard +#[rustc_const_unstable(feature = "const_drop_guard", issue = "none")] +impl const Drop for DropGuard where - F: FnOnce(T), + F: [const] FnOnce(T), { fn drop(&mut self) { // SAFETY: `DropGuard` is in the process of being dropped.