Skip to content

Commit 5c150fc

Browse files
committedJun 26, 2019
Implement mem::{zeroed,uninitialized} in terms of MaybeUninit.
Refs #62061 r?oli-obk
1 parent d3e2cec commit 5c150fc

File tree

5 files changed

+3
-28
lines changed

5 files changed

+3
-28
lines changed
 

‎src/libcore/intrinsics.rs

-9
Original file line numberDiff line numberDiff line change
@@ -702,15 +702,6 @@ extern "rust-intrinsic" {
702702
/// state for the type in question.
703703
pub fn init<T>() -> T;
704704

705-
/// Creates an uninitialized value.
706-
///
707-
/// `uninit` is unsafe because there is no guarantee of what its
708-
/// contents are. In particular its drop-flag may be set to any
709-
/// state, which means it may claim either dropped or
710-
/// undropped. In the general case one must use `ptr::write` to
711-
/// initialize memory previous set to the result of `uninit`.
712-
pub fn uninit<T>() -> T;
713-
714705
/// Moves a value out of scope without running drop glue.
715706
pub fn forget<T: ?Sized>(_: T);
716707

‎src/libcore/mem/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,7 @@ pub const fn needs_drop<T>() -> bool {
450450
#[inline]
451451
#[stable(feature = "rust1", since = "1.0.0")]
452452
pub unsafe fn zeroed<T>() -> T {
453-
intrinsics::panic_if_uninhabited::<T>();
454-
intrinsics::init()
453+
MaybeUninit::zeroed().assume_init()
455454
}
456455

457456
/// Bypasses Rust's normal memory-initialization checks by pretending to
@@ -476,8 +475,7 @@ pub unsafe fn zeroed<T>() -> T {
476475
#[rustc_deprecated(since = "1.38.0", reason = "use `mem::MaybeUninit` instead")]
477476
#[stable(feature = "rust1", since = "1.0.0")]
478477
pub unsafe fn uninitialized<T>() -> T {
479-
intrinsics::panic_if_uninhabited::<T>();
480-
intrinsics::uninit()
478+
MaybeUninit::uninit().assume_init()
481479
}
482480

483481
/// Swaps the values at two mutable locations, without deinitializing either one.

‎src/librustc_codegen_llvm/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
234234
return;
235235
}
236236
// Effectively no-ops
237-
"uninit" | "forget" => {
237+
"forget" => {
238238
return;
239239
}
240240
"needs_drop" => {

‎src/librustc_typeck/check/intrinsic.rs

-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ pub fn check_intrinsic_type<'tcx>(tcx: TyCtxt<'tcx>, it: &hir::ForeignItem) {
145145
"rustc_peek" => (1, vec![param(0)], param(0)),
146146
"panic_if_uninhabited" => (1, Vec::new(), tcx.mk_unit()),
147147
"init" => (1, Vec::new(), param(0)),
148-
"uninit" => (1, Vec::new(), param(0)),
149148
"forget" => (1, vec![param(0)], tcx.mk_unit()),
150149
"transmute" => (2, vec![ param(0) ], param(1)),
151150
"move_val_init" => {

‎src/test/run-pass/intrinsics/intrinsic-uninit.rs

-13
This file was deleted.

0 commit comments

Comments
 (0)