diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-07-05 13:53:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-05 13:53:00 +0200 |
| commit | 1d45156866b54c3fc36edfdfcdd8149ad9cb5711 (patch) | |
| tree | ac5494522211f56dbf9596988b1c4c5014085f7d /src/libcore | |
| parent | 0f92eb8a4a7d8715381f5b5d748d22315f6ff9c7 (diff) | |
| parent | e4f250e405046713ba6fbcf481d0a88f26d25ae8 (diff) | |
| download | rust-1d45156866b54c3fc36edfdfcdd8149ad9cb5711.tar.gz rust-1d45156866b54c3fc36edfdfcdd8149ad9cb5711.zip | |
Rollup merge of #62150 - alex:mem-uninit-refactor, r=RalfJung
Implement mem::{zeroed,uninitialized} in terms of MaybeUninit.
Refs #62061
r? @oli-obk
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/intrinsics.rs | 16 | ||||
| -rw-r--r-- | src/libcore/mem/mod.rs | 6 |
2 files changed, 9 insertions, 13 deletions
diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 8e53022c287..67430e5bbda 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. |
