Skip to content

Commit 5e5f334

Browse files
committed
Stabilize const_mem_zeroed
Make `core::mem::zeroed` const stable. Newly stable API: // core::mem pub const unsafe fn zeroed<T>() -> T; This is stabilized with `const_maybe_uninit_zeroed` since it is a simple wrapper. In order to make this possible, intrinsics `assert_zero_valid` was made const stable under `const_assert_type2`. `assert_mem_uninitialized_valid` was also made const stable since it is under the same gate.
1 parent f6ce646 commit 5e5f334

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

library/core/src/intrinsics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1072,15 +1072,15 @@ extern "rust-intrinsic" {
10721072
/// zero-initialization: This will statically either panic, or do nothing.
10731073
///
10741074
/// This intrinsic does not have a stable counterpart.
1075-
#[rustc_const_unstable(feature = "const_assert_type2", issue = "none")]
1075+
#[rustc_const_stable(feature = "const_assert_type2", since = "CURRENT_RUSTC_VERSION")]
10761076
#[rustc_safe_intrinsic]
10771077
#[rustc_nounwind]
10781078
pub fn assert_zero_valid<T>();
10791079

10801080
/// A guard for `std::mem::uninitialized`. This will statically either panic, or do nothing.
10811081
///
10821082
/// This intrinsic does not have a stable counterpart.
1083-
#[rustc_const_unstable(feature = "const_assert_type2", issue = "none")]
1083+
#[rustc_const_stable(feature = "const_assert_type2", since = "CURRENT_RUSTC_VERSION")]
10841084
#[rustc_safe_intrinsic]
10851085
#[rustc_nounwind]
10861086
pub fn assert_mem_uninitialized_valid<T>();

library/core/src/mem/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,8 @@ pub const fn needs_drop<T: ?Sized>() -> bool {
647647
#[allow(deprecated)]
648648
#[rustc_diagnostic_item = "mem_zeroed"]
649649
#[track_caller]
650-
pub unsafe fn zeroed<T>() -> T {
650+
#[rustc_const_stable(feature = "const_mem_zeroed", since = "CURRENT_RUSTC_VERSION")]
651+
pub const unsafe fn zeroed<T>() -> T {
651652
// SAFETY: the caller must guarantee that an all-zero value is valid for `T`.
652653
unsafe {
653654
intrinsics::assert_zero_valid::<T>();

tests/ui/consts/assert-type-intrinsics.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(never_type)]
2-
#![feature(const_assert_type2)]
32
#![feature(core_intrinsics)]
43

54
use std::intrinsics;

tests/ui/consts/assert-type-intrinsics.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/assert-type-intrinsics.rs:12:9
2+
--> $DIR/assert-type-intrinsics.rs:11:9
33
|
44
LL | MaybeUninit::<!>::uninit().assume_init();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'aborted execution: attempted to instantiate uninhabited type `!`', $DIR/assert-type-intrinsics.rs:12:36
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'aborted execution: attempted to instantiate uninhabited type `!`', $DIR/assert-type-intrinsics.rs:11:36
66

77
error[E0080]: evaluation of constant value failed
8-
--> $DIR/assert-type-intrinsics.rs:16:9
8+
--> $DIR/assert-type-intrinsics.rs:15:9
99
|
1010
LL | intrinsics::assert_mem_uninitialized_valid::<&'static i32>();
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'aborted execution: attempted to leave type `&i32` uninitialized, which is invalid', $DIR/assert-type-intrinsics.rs:16:9
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'aborted execution: attempted to leave type `&i32` uninitialized, which is invalid', $DIR/assert-type-intrinsics.rs:15:9
1212

1313
error[E0080]: evaluation of constant value failed
14-
--> $DIR/assert-type-intrinsics.rs:20:9
14+
--> $DIR/assert-type-intrinsics.rs:19:9
1515
|
1616
LL | intrinsics::assert_zero_valid::<&'static i32>();
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'aborted execution: attempted to zero-initialize type `&i32`, which is invalid', $DIR/assert-type-intrinsics.rs:20:9
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'aborted execution: attempted to zero-initialize type `&i32`, which is invalid', $DIR/assert-type-intrinsics.rs:19:9
1818

1919
error: aborting due to 3 previous errors
2020

0 commit comments

Comments
 (0)