about summary refs log tree commit diff
path: root/library/core
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-12-21 23:20:04 +0000
committerbors <bors@rust-lang.org>2022-12-21 23:20:04 +0000
commitbdbe392a13bc9782b98de193c3751b9d96bb5fcc (patch)
tree860c50e7741ae8896129546d16d0a65956364b33 /library/core
parentb569c9dc57ee22b6ff94563af856909763dfa24b (diff)
parent6f21ba4a06b7fa17113b7029c4aa7805db16aa32 (diff)
downloadrust-bdbe392a13bc9782b98de193c3751b9d96bb5fcc.tar.gz
rust-bdbe392a13bc9782b98de193c3751b9d96bb5fcc.zip
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`
Diffstat (limited to 'library/core')
-rw-r--r--library/core/src/intrinsics.rs6
-rw-r--r--library/core/src/mem/mod.rs3
2 files changed, 5 insertions, 4 deletions
diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs
index 7ed7d767f2f..a521905a9e7 100644
--- a/library/core/src/intrinsics.rs
+++ b/library/core/src/intrinsics.rs
@@ -959,13 +959,13 @@ extern "rust-intrinsic" {
     #[rustc_safe_intrinsic]
     pub fn assert_zero_valid<T>();
 
-    /// A guard for unsafe functions that cannot ever be executed if `T` has invalid
-    /// bit patterns: This will statically either panic, or do nothing.
+    /// A guard for `std::mem::uninitialized`. 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_safe_intrinsic]
-    pub fn assert_uninit_valid<T>();
+    #[cfg(not(bootstrap))]
+    pub fn assert_mem_uninitialized_valid<T>();
 
     /// Gets a reference to a static `Location` indicating where it was called.
     ///
diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs
index 383bdc7b6e2..5e01ccc07d8 100644
--- a/library/core/src/mem/mod.rs
+++ b/library/core/src/mem/mod.rs
@@ -682,7 +682,8 @@ pub unsafe fn zeroed<T>() -> T {
 pub unsafe fn uninitialized<T>() -> T {
     // SAFETY: the caller must guarantee that an uninitialized value is valid for `T`.
     unsafe {
-        intrinsics::assert_uninit_valid::<T>();
+        #[cfg(not(bootstrap))] // If the compiler hits this itself then it deserves the UB.
+        intrinsics::assert_mem_uninitialized_valid::<T>();
         let mut val = MaybeUninit::<T>::uninit();
 
         // Fill memory with 0x01, as an imperfect mitigation for old code that uses this function on