Skip to content

Commit 710399a

Browse files
committed
Revert "Rollup merge of #62150 - alex:mem-uninit-refactor, r=RalfJung"
This reverts commit 1d45156, reversing changes made to 0f92eb8.
1 parent c326c2e commit 710399a

File tree

7 files changed

+29
-13
lines changed

7 files changed

+29
-13
lines changed

src/libcore/intrinsics.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -702,16 +702,17 @@ extern "rust-intrinsic" {
702702
/// which is unsafe unless `T` is `Copy`. Also, even if T is
703703
/// `Copy`, an all-zero value may not correspond to any legitimate
704704
/// state for the type in question.
705-
#[unstable(feature = "core_intrinsics",
706-
reason = "intrinsics are unlikely to ever be stabilized, instead \
707-
they should be used through stabilized interfaces \
708-
in the rest of the standard library",
709-
issue = "0")]
710-
#[rustc_deprecated(reason = "no longer used by rustc, will be removed - use MaybeUninit \
711-
instead",
712-
since = "1.38.0")]
713705
pub fn init<T>() -> T;
714706

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

src/libcore/mem/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ pub const fn needs_drop<T>() -> bool {
453453
#[inline]
454454
#[stable(feature = "rust1", since = "1.0.0")]
455455
pub unsafe fn zeroed<T>() -> T {
456-
MaybeUninit::zeroed().assume_init()
456+
intrinsics::panic_if_uninhabited::<T>();
457+
intrinsics::init()
457458
}
458459

459460
/// Bypasses Rust's normal memory-initialization checks by pretending to
@@ -478,7 +479,8 @@ pub unsafe fn zeroed<T>() -> T {
478479
#[rustc_deprecated(since = "1.39.0", reason = "use `mem::MaybeUninit` instead")]
479480
#[stable(feature = "rust1", since = "1.0.0")]
480481
pub unsafe fn uninitialized<T>() -> T {
481-
MaybeUninit::uninit().assume_init()
482+
intrinsics::panic_if_uninhabited::<T>();
483+
intrinsics::uninit()
482484
}
483485

484486
/// 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
@@ -232,7 +232,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
232232
return;
233233
}
234234
// Effectively no-ops
235-
"forget" => {
235+
"uninit" | "forget" => {
236236
return;
237237
}
238238
"needs_drop" => {

src/librustc_typeck/check/intrinsic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, 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)),
148149
"forget" => (1, vec![param(0)], tcx.mk_unit()),
149150
"transmute" => (2, vec![ param(0) ], param(1)),
150151
"move_val_init" => {

src/test/ui/init-unsafe.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![allow(deprecated)]
21
#![feature(core_intrinsics)]
32

43
use std::intrinsics::{init};

src/test/ui/init-unsafe.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2-
--> $DIR/init-unsafe.rs:8:17
2+
--> $DIR/init-unsafe.rs:7:17
33
|
44
LL | let stuff = init::<isize>();
55
| ^^^^^^^^^^^^^^^ call to unsafe function
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// run-pass
2+
// pretty-expanded FIXME #23616
3+
4+
#![feature(intrinsics)]
5+
6+
mod rusti {
7+
extern "rust-intrinsic" {
8+
pub fn uninit<T>() -> T;
9+
}
10+
}
11+
pub fn main() {
12+
let _a : isize = unsafe {rusti::uninit()};
13+
}

0 commit comments

Comments
 (0)