Skip to content

Commit 2099db2

Browse files
committed
Auto merge of #105613 - Nilstrieb:rename-assert_uninit_valid, r=RalfJung
Rename `assert_uninit_valid` intrinsic It's not about "uninit" anymore but about "filling with 0x01 bytes" so the name should at least try to reflect that. This is actually not fully correct though, as it does still panic for all uninit with `-Zstrict-init-checks`. I'm not sure what the best way is to deal with that not causing confusion. I guess we could just remove the flag? I don't think having it makes a lot of sense anymore with the direction that we have chose to go. It could be relevant again if #100423 lands so removing it may be a bit over eager. r? `@RalfJung`
2 parents 2b23e1b + 8401b0c commit 2099db2

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

core/src/intrinsics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -959,13 +959,13 @@ extern "rust-intrinsic" {
959959
#[rustc_safe_intrinsic]
960960
pub fn assert_zero_valid<T>();
961961

962-
/// A guard for unsafe functions that cannot ever be executed if `T` has invalid
963-
/// bit patterns: This will statically either panic, or do nothing.
962+
/// A guard for `std::mem::uninitialized`. This will statically either panic, or do nothing.
964963
///
965964
/// This intrinsic does not have a stable counterpart.
966965
#[rustc_const_unstable(feature = "const_assert_type2", issue = "none")]
967966
#[rustc_safe_intrinsic]
968-
pub fn assert_uninit_valid<T>();
967+
#[cfg(not(bootstrap))]
968+
pub fn assert_mem_uninitialized_valid<T>();
969969

970970
/// Gets a reference to a static `Location` indicating where it was called.
971971
///

core/src/mem/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,8 @@ pub unsafe fn zeroed<T>() -> T {
682682
pub unsafe fn uninitialized<T>() -> T {
683683
// SAFETY: the caller must guarantee that an uninitialized value is valid for `T`.
684684
unsafe {
685-
intrinsics::assert_uninit_valid::<T>();
685+
#[cfg(not(bootstrap))] // If the compiler hits this itself then it deserves the UB.
686+
intrinsics::assert_mem_uninitialized_valid::<T>();
686687
let mut val = MaybeUninit::<T>::uninit();
687688

688689
// Fill memory with 0x01, as an imperfect mitigation for old code that uses this function on

0 commit comments

Comments
 (0)