From 7048167eb3e9ac1b839c5b9adef69a9f10812aff Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 29 Sep 2023 02:40:30 -0400 Subject: [PATCH] Stabilize `const_mem_zeroed` Make `core::mem::zeroed` const stable. Newly stable API: // core::mem pub const unsafe fn zeroed() -> T; This is stabilized with `const_maybe_uninit_zeroed` since it is a simple wrapper. --- library/core/src/intrinsics.rs | 2 +- library/core/src/mem/mod.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 4c76662ac0975..9cbfb65305183 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1072,7 +1072,7 @@ extern "rust-intrinsic" { /// zero-initialization: This will statically either panic, or do nothing. /// /// This intrinsic does not have a stable counterpart. - #[rustc_const_unstable(feature = "const_assert_type2", issue = "none")] + #[rustc_const_stable(feature = "const_assert_zero_valid", since = "CURRENT_RUSTC_VERSION")] #[rustc_safe_intrinsic] #[rustc_nounwind] pub fn assert_zero_valid(); diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index d7abc9a0e23aa..82ce901140ada 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -647,7 +647,8 @@ pub const fn needs_drop() -> bool { #[allow(deprecated)] #[rustc_diagnostic_item = "mem_zeroed"] #[track_caller] -pub unsafe fn zeroed() -> T { +#[rustc_const_stable(feature = "const_mem_zeroed", since = "CURRENT_RUSTC_VERSION")] +pub const unsafe fn zeroed() -> T { // SAFETY: the caller must guarantee that an all-zero value is valid for `T`. unsafe { intrinsics::assert_zero_valid::();