about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2019-06-26 07:50:30 -0400
committerAlex Gaynor <alex.gaynor@gmail.com>2019-07-04 09:33:15 -0400
commite4f250e405046713ba6fbcf481d0a88f26d25ae8 (patch)
treeb16fc6e7817c8f9caeddff1ed84bd8887b17d61a /src/libcore
parentb43eb4235ac43c822d903ad26ed806f34cc1a14a (diff)
downloadrust-e4f250e405046713ba6fbcf481d0a88f26d25ae8.tar.gz
rust-e4f250e405046713ba6fbcf481d0a88f26d25ae8.zip
Implement mem::{zeroed,uninitialized} in terms of MaybeUninit.
Refs #62061
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/intrinsics.rs16
-rw-r--r--src/libcore/mem/mod.rs6
2 files changed, 9 insertions, 13 deletions
diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs
index b30eff8baa9..7383b90bb41 100644
--- a/src/libcore/intrinsics.rs
+++ b/src/libcore/intrinsics.rs
@@ -700,17 +700,15 @@ extern "rust-intrinsic" {
     /// which is unsafe unless `T` is `Copy`. Also, even if T is
     /// `Copy`, an all-zero value may not correspond to any legitimate
     /// state for the type in question.
+    #[unstable(feature = "core_intrinsics",
+               reason = "intrinsics are unlikely to ever be stabilized, instead \
+                         they should be used through stabilized interfaces \
+                         in the rest of the standard library",
+               issue = "0")]
+    #[rustc_deprecated(reason = "no longer used by rustc, will be removed - use MaybeUnint instead",
+                       since = "1.38.0")]
     pub fn init<T>() -> T;
 
-    /// Creates an uninitialized value.
-    ///
-    /// `uninit` is unsafe because there is no guarantee of what its
-    /// contents are. In particular its drop-flag may be set to any
-    /// state, which means it may claim either dropped or
-    /// undropped. In the general case one must use `ptr::write` to
-    /// initialize memory previous set to the result of `uninit`.
-    pub fn uninit<T>() -> T;
-
     /// Moves a value out of scope without running drop glue.
     pub fn forget<T: ?Sized>(_: T);
 
diff --git a/src/libcore/mem/mod.rs b/src/libcore/mem/mod.rs
index b31522db474..b62d81affdd 100644
--- a/src/libcore/mem/mod.rs
+++ b/src/libcore/mem/mod.rs
@@ -450,8 +450,7 @@ pub const fn needs_drop<T>() -> bool {
 #[inline]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub unsafe fn zeroed<T>() -> T {
-    intrinsics::panic_if_uninhabited::<T>();
-    intrinsics::init()
+    MaybeUninit::zeroed().assume_init()
 }
 
 /// Bypasses Rust's normal memory-initialization checks by pretending to
@@ -476,8 +475,7 @@ pub unsafe fn zeroed<T>() -> T {
 #[rustc_deprecated(since = "1.38.0", reason = "use `mem::MaybeUninit` instead")]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub unsafe fn uninitialized<T>() -> T {
-    intrinsics::panic_if_uninhabited::<T>();
-    intrinsics::uninit()
+    MaybeUninit::uninit().assume_init()
 }
 
 /// Swaps the values at two mutable locations, without deinitializing either one.