Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back out #62150 (Implement mem::{zeroed,uninitialized} in terms of MaybeUninit) #63343

Merged
merged 1 commit into from
Aug 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,11 +707,26 @@ extern "rust-intrinsic" {
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 MaybeUninit \
instead",
#[rustc_deprecated(reason = "superseded by MaybeUninit, removal planned",
RalfJung marked this conversation as resolved.
Show resolved Hide resolved
since = "1.38.0")]
pub fn init<T>() -> T;
ishitatsuyuki marked this conversation as resolved.
Show resolved Hide resolved

/// 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`.
#[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 = "superseded by MaybeUninit, removal planned",
since = "1.38.0")]
pub fn uninit<T>() -> T;

/// Moves a value out of scope without running drop glue.
pub fn forget<T: ?Sized>(_: T);

Expand Down
10 changes: 8 additions & 2 deletions src/libcore/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,11 @@ pub const fn needs_drop<T>() -> bool {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(bootstrap, allow(deprecated_in_future))]
#[allow(deprecated)]
pub unsafe fn zeroed<T>() -> T {
MaybeUninit::zeroed().assume_init()
intrinsics::panic_if_uninhabited::<T>();
intrinsics::init()
}

/// Bypasses Rust's normal memory-initialization checks by pretending to
Expand All @@ -477,8 +480,11 @@ pub unsafe fn zeroed<T>() -> T {
#[inline]
#[rustc_deprecated(since = "1.39.0", reason = "use `mem::MaybeUninit` instead")]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(bootstrap, allow(deprecated_in_future))]
#[allow(deprecated)]
pub unsafe fn uninitialized<T>() -> T {
MaybeUninit::uninit().assume_init()
intrinsics::panic_if_uninhabited::<T>();
intrinsics::uninit()
}

/// Swaps the values at two mutable locations, without deinitializing either one.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
return;
}
// Effectively no-ops
"forget" => {
"uninit" | "forget" => {
return;
}
"needs_drop" => {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_typeck/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
"rustc_peek" => (1, vec![param(0)], param(0)),
"panic_if_uninhabited" => (1, Vec::new(), tcx.mk_unit()),
"init" => (1, Vec::new(), param(0)),
"uninit" => (1, Vec::new(), param(0)),
"forget" => (1, vec![param(0)], tcx.mk_unit()),
"transmute" => (2, vec![ param(0) ], param(1)),
"move_val_init" => {
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/intrinsics/intrinsic-uninit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// run-pass
// pretty-expanded FIXME #23616

#![feature(intrinsics)]

mod rusti {
extern "rust-intrinsic" {
pub fn uninit<T>() -> T;
}
}
pub fn main() {
let _a : isize = unsafe {rusti::uninit()};
}