diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs index 215689dfc48c9..3cd938f0dd0ae 100644 --- a/src/liballoc/collections/btree/node.rs +++ b/src/liballoc/collections/btree/node.rs @@ -42,7 +42,7 @@ // This implies that even an empty internal node has at least one edge. use core::marker::PhantomData; -use core::mem::{self, MaybeUninit}; +use core::mem::{self, MaybeUninitialized}; use core::ptr::{self, Unique, NonNull}; use core::slice; @@ -70,7 +70,7 @@ struct LeafNode { /// This node's index into the parent node's `edges` array. /// `*node.parent.edges[node.parent_idx]` should be the same thing as `node`. /// This is only guaranteed to be initialized when `parent` is non-null. - parent_idx: MaybeUninit, + parent_idx: MaybeUninitialized, /// The number of keys and values this node stores. /// @@ -80,8 +80,8 @@ struct LeafNode { /// The arrays storing the actual data of the node. Only the first `len` elements of each /// array are initialized and valid. - keys: MaybeUninit<[K; CAPACITY]>, - vals: MaybeUninit<[V; CAPACITY]>, + keys: MaybeUninitialized<[K; CAPACITY]>, + vals: MaybeUninitialized<[V; CAPACITY]>, } impl LeafNode { @@ -91,10 +91,10 @@ impl LeafNode { LeafNode { // As a general policy, we leave fields uninitialized if they can be, as this should // be both slightly faster and easier to track in Valgrind. - keys: MaybeUninit::uninitialized(), - vals: MaybeUninit::uninitialized(), + keys: MaybeUninitialized::uninitialized(), + vals: MaybeUninitialized::uninitialized(), parent: ptr::null(), - parent_idx: MaybeUninit::uninitialized(), + parent_idx: MaybeUninitialized::uninitialized(), len: 0 } } @@ -112,10 +112,10 @@ unsafe impl Sync for LeafNode<(), ()> {} // ever take a pointer past the first key. static EMPTY_ROOT_NODE: LeafNode<(), ()> = LeafNode { parent: ptr::null(), - parent_idx: MaybeUninit::uninitialized(), + parent_idx: MaybeUninitialized::uninitialized(), len: 0, - keys: MaybeUninit::uninitialized(), - vals: MaybeUninit::uninitialized(), + keys: MaybeUninitialized::uninitialized(), + vals: MaybeUninitialized::uninitialized(), }; /// The underlying representation of internal nodes. As with `LeafNode`s, these should be hidden diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index 3717a783f2411..2c2c6764d1be2 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -9,7 +9,7 @@ // except according to those terms. use fmt::{Formatter, Result, LowerExp, UpperExp, Display, Debug}; -use mem::MaybeUninit; +use mem::MaybeUninitialized; use num::flt2dec; // Don't inline this so callers don't use the stack space this function @@ -20,10 +20,10 @@ fn float_to_decimal_common_exact(fmt: &mut Formatter, num: &T, where T: flt2dec::DecodableFloat { unsafe { - let mut buf = MaybeUninit::<[u8; 1024]>::uninitialized(); // enough for f32 and f64 - let mut parts = MaybeUninit::<[flt2dec::Part; 4]>::uninitialized(); + let mut buf = MaybeUninitialized::<[u8; 1024]>::uninitialized(); // enough for f32 and f64 + let mut parts = MaybeUninitialized::<[flt2dec::Part; 4]>::uninitialized(); // FIXME(#53491): Technically, this is calling `get_mut` on an uninitialized - // `MaybeUninit` (here and elsewhere in this file). Revisit this once + // `MaybeUninitialized` (here and elsewhere in this file). Revisit this once // we decided whether that is valid or not. let formatted = flt2dec::to_exact_fixed_str(flt2dec::strategy::grisu::format_exact, *num, sign, precision, @@ -41,8 +41,8 @@ fn float_to_decimal_common_shortest(fmt: &mut Formatter, num: &T, { unsafe { // enough for f32 and f64 - let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninitialized(); - let mut parts = MaybeUninit::<[flt2dec::Part; 4]>::uninitialized(); + let mut buf = MaybeUninitialized::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninitialized(); + let mut parts = MaybeUninitialized::<[flt2dec::Part; 4]>::uninitialized(); let formatted = flt2dec::to_shortest_str(flt2dec::strategy::grisu::format_shortest, *num, sign, precision, false, buf.get_mut(), parts.get_mut()); @@ -79,8 +79,8 @@ fn float_to_exponential_common_exact(fmt: &mut Formatter, num: &T, where T: flt2dec::DecodableFloat { unsafe { - let mut buf = MaybeUninit::<[u8; 1024]>::uninitialized(); // enough for f32 and f64 - let mut parts = MaybeUninit::<[flt2dec::Part; 6]>::uninitialized(); + let mut buf = MaybeUninitialized::<[u8; 1024]>::uninitialized(); // enough for f32 and f64 + let mut parts = MaybeUninitialized::<[flt2dec::Part; 6]>::uninitialized(); let formatted = flt2dec::to_exact_exp_str(flt2dec::strategy::grisu::format_exact, *num, sign, precision, upper, buf.get_mut(), parts.get_mut()); @@ -98,8 +98,8 @@ fn float_to_exponential_common_shortest(fmt: &mut Formatter, { unsafe { // enough for f32 and f64 - let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninitialized(); - let mut parts = MaybeUninit::<[flt2dec::Part; 6]>::uninitialized(); + let mut buf = MaybeUninitialized::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninitialized(); + let mut parts = MaybeUninitialized::<[flt2dec::Part; 6]>::uninitialized(); let formatted = flt2dec::to_shortest_exp_str(flt2dec::strategy::grisu::format_shortest, *num, sign, (0, 0), upper, buf.get_mut(), parts.get_mut()); diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index afd9fcb1fba84..b621cde97d404 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -499,7 +499,8 @@ pub const fn needs_drop() -> bool { /// assert_eq!(0, x); /// ``` #[inline] -#[rustc_deprecated(since = "2.0.0", reason = "use `mem::MaybeUninit::zeroed` instead")] +#[rustc_deprecated(since = "2.0.0", + reason = "use `mem::MaybeUninitialized::zeroed` instead")] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn zeroed() -> T { intrinsics::init() @@ -592,7 +593,8 @@ pub unsafe fn zeroed() -> T { /// [copy_no]: ../intrinsics/fn.copy_nonoverlapping.html /// [`Drop`]: ../ops/trait.Drop.html #[inline] -#[rustc_deprecated(since = "2.0.0", reason = "use `mem::MaybeUninit::uninitialized` instead")] +#[rustc_deprecated(since = "2.0.0", + reason = "use `mem::MaybeUninitialized::uninitialized` instead")] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn uninitialized() -> T { intrinsics::uninit() @@ -1031,52 +1033,53 @@ impl DerefMut for ManuallyDrop { /// A newtype to construct uninitialized instances of `T` #[allow(missing_debug_implementations)] #[unstable(feature = "maybe_uninit", issue = "53491")] -// NOTE after stabilizing `MaybeUninit` proceed to deprecate `mem::{uninitialized,zeroed}` -pub union MaybeUninit { +// NOTE after stabilizing `MaybeUninitialized` proceed to deprecate `mem::{uninitialized,zeroed}` +pub union MaybeUninitialized { uninit: (), value: ManuallyDrop, } -impl MaybeUninit { - /// Create a new `MaybeUninit` initialized with the given value. +impl MaybeUninitialized { + /// Create a new `MaybeUninitialized` initialized with the given value. /// - /// Note that dropping a `MaybeUninit` will never call `T`'s drop code. + /// Note that dropping a `MaybeUninitialized` will never call `T`'s drop code. /// It is your responsibility to make sure `T` gets dropped if it got initialized. #[unstable(feature = "maybe_uninit", issue = "53491")] #[inline(always)] - pub const fn new(val: T) -> MaybeUninit { - MaybeUninit { value: ManuallyDrop::new(val) } + pub const fn new(val: T) -> MaybeUninitialized { + MaybeUninitialized { value: ManuallyDrop::new(val) } } - /// Create a new `MaybeUninit` in an uninitialized state. + /// Create a new `MaybeUninitialized` in an uninitialized state. /// - /// Note that dropping a `MaybeUninit` will never call `T`'s drop code. + /// Note that dropping a `MaybeUninitialized` will never call `T`'s drop code. /// It is your responsibility to make sure `T` gets dropped if it got initialized. #[unstable(feature = "maybe_uninit", issue = "53491")] #[inline(always)] - pub const fn uninitialized() -> MaybeUninit { - MaybeUninit { uninit: () } + pub const fn uninitialized() -> MaybeUninitialized { + MaybeUninitialized { uninit: () } } - /// Create a new `MaybeUninit` in an uninitialized state, with the memory being + /// Create a new `MaybeUninitialized` in an uninitialized state, with the memory being /// filled with `0` bytes. It depends on `T` whether that already makes for - /// proper initialization. For example, `MaybeUninit::zeroed()` is initialized, - /// but `MaybeUninit<&'static i32>::zeroed()` is not because references must not + /// proper initialization. For example, `MaybeUninitialized::zeroed()` is initialized, + /// but `MaybeUninitialized<&'static i32>::zeroed()` is not because references must not /// be null. /// - /// Note that dropping a `MaybeUninit` will never call `T`'s drop code. + /// Note that dropping a `MaybeUninitialized` will never call `T`'s drop code. /// It is your responsibility to make sure `T` gets dropped if it got initialized. #[unstable(feature = "maybe_uninit", issue = "53491")] #[inline] - pub fn zeroed() -> MaybeUninit { - let mut u = MaybeUninit::::uninitialized(); + pub fn zeroed() -> MaybeUninitialized { + let mut u = MaybeUninitialized::::uninitialized(); unsafe { u.as_mut_ptr().write_bytes(0u8, 1); } u } - /// Set the value of the `MaybeUninit`. This overwrites any previous value without dropping it. + /// Set the value of the `MaybeUninitialized`. This overwrites any previous value without + /// dropping it. #[unstable(feature = "maybe_uninit", issue = "53491")] #[inline(always)] pub fn set(&mut self, val: T) { @@ -1085,14 +1088,14 @@ impl MaybeUninit { } } - /// Extract the value from the `MaybeUninit` container. This is a great way + /// Extract the value from the `MaybeUninitialized` container. This is a great way /// to ensure that the data will get dropped, because the resulting `T` is /// subject to the usual drop handling. /// /// # Unsafety /// - /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized - /// state, otherwise this will immediately cause undefined behavior. + /// It is up to the caller to guarantee that the `MaybeUninitialized` really is in an + /// initialized state, otherwise this will immediately cause undefined behavior. #[unstable(feature = "maybe_uninit", issue = "53491")] #[inline(always)] pub unsafe fn into_inner(self) -> T { @@ -1103,8 +1106,8 @@ impl MaybeUninit { /// /// # Unsafety /// - /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized - /// state, otherwise this will immediately cause undefined behavior. + /// It is up to the caller to guarantee that the `MaybeUninitialized` really is in an + /// initialized state, otherwise this will immediately cause undefined behavior. #[unstable(feature = "maybe_uninit", issue = "53491")] #[inline(always)] pub unsafe fn get_ref(&self) -> &T { @@ -1115,8 +1118,8 @@ impl MaybeUninit { /// /// # Unsafety /// - /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized - /// state, otherwise this will immediately cause undefined behavior. + /// It is up to the caller to guarantee that the `MaybeUninitialized` really is in an + /// initialized state, otherwise this will immediately cause undefined behavior. // FIXME(#53491): We currently rely on the above being incorrect, i.e., we have references // to uninitialized data (e.g., in `libcore/fmt/float.rs`). We should make // a final decision about the rules before stabilization. @@ -1127,7 +1130,7 @@ impl MaybeUninit { } /// Get a pointer to the contained value. Reading from this pointer will be undefined - /// behavior unless the `MaybeUninit` is initialized. + /// behavior unless the `MaybeUninitialized` is initialized. #[unstable(feature = "maybe_uninit", issue = "53491")] #[inline(always)] pub fn as_ptr(&self) -> *const T { @@ -1135,7 +1138,7 @@ impl MaybeUninit { } /// Get a mutable pointer to the contained value. Reading from this pointer will be undefined - /// behavior unless the `MaybeUninit` is initialized. + /// behavior unless the `MaybeUninitialized` is initialized. #[unstable(feature = "maybe_uninit", issue = "53491")] #[inline(always)] pub fn as_mut_ptr(&mut self) -> *mut T { diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 79ca600b4a57f..63fcacf3a78e6 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -79,7 +79,7 @@ use ops::{CoerceUnsized, DispatchFromDyn}; use fmt; use hash; use marker::{PhantomData, Unsize}; -use mem::{self, MaybeUninit}; +use mem::{self, MaybeUninitialized}; use nonzero::NonZero; use cmp::Ordering::{self, Less, Equal, Greater}; @@ -306,8 +306,8 @@ pub const fn null_mut() -> *mut T { 0 as *mut T } #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn swap(x: *mut T, y: *mut T) { // Give ourselves some scratch space to work with. - // We do not have to worry about drops: `MaybeUninit` does nothing when dropped. - let mut tmp = MaybeUninit::::uninitialized(); + // We do not have to worry about drops: `MaybeUninitialized` does nothing when dropped. + let mut tmp = MaybeUninitialized::::uninitialized(); // Perform the swap copy_nonoverlapping(x, tmp.as_mut_ptr(), 1); @@ -399,7 +399,7 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) { while i + block_size <= len { // Create some uninitialized memory as scratch space // Declaring `t` here avoids aligning the stack when this loop is unused - let mut t = mem::MaybeUninit::::uninitialized(); + let mut t = mem::MaybeUninitialized::::uninitialized(); let t = t.as_mut_ptr() as *mut u8; let x = x.add(i); let y = y.add(i); @@ -414,7 +414,7 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) { if i < len { // Swap any remaining bytes - let mut t = mem::MaybeUninit::::uninitialized(); + let mut t = mem::MaybeUninitialized::::uninitialized(); let rem = len - i; let t = t.as_mut_ptr() as *mut u8; @@ -582,7 +582,7 @@ pub unsafe fn replace(dst: *mut T, mut src: T) -> T { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn read(src: *const T) -> T { - let mut tmp = MaybeUninit::::uninitialized(); + let mut tmp = MaybeUninitialized::::uninitialized(); copy_nonoverlapping(src, tmp.as_mut_ptr(), 1); tmp.into_inner() } @@ -649,7 +649,7 @@ pub unsafe fn read(src: *const T) -> T { #[inline] #[stable(feature = "ptr_unaligned", since = "1.17.0")] pub unsafe fn read_unaligned(src: *const T) -> T { - let mut tmp = MaybeUninit::::uninitialized(); + let mut tmp = MaybeUninitialized::::uninitialized(); copy_nonoverlapping(src as *const u8, tmp.as_mut_ptr() as *mut u8, mem::size_of::()); diff --git a/src/libcore/slice/rotate.rs b/src/libcore/slice/rotate.rs index 07153735300b8..67d627b6eefc1 100644 --- a/src/libcore/slice/rotate.rs +++ b/src/libcore/slice/rotate.rs @@ -9,7 +9,7 @@ // except according to those terms. use cmp; -use mem::{self, MaybeUninit}; +use mem::{self, MaybeUninitialized}; use ptr; /// Rotation is much faster if it has access to a little bit of memory. This @@ -82,7 +82,7 @@ pub unsafe fn ptr_rotate(mut left: usize, mid: *mut T, mut right: usize) { } } - let mut rawarray = MaybeUninit::>::uninitialized(); + let mut rawarray = MaybeUninitialized::>::uninitialized(); let buf = &mut (*rawarray.as_mut_ptr()).typed as *mut [T; 2] as *mut T; let dim = mid.sub(left).add(right); diff --git a/src/libcore/slice/sort.rs b/src/libcore/slice/sort.rs index affe84fbef91f..6e8fe34b8ed77 100644 --- a/src/libcore/slice/sort.rs +++ b/src/libcore/slice/sort.rs @@ -17,7 +17,7 @@ //! stable sorting implementation. use cmp; -use mem::{self, MaybeUninit}; +use mem::{self, MaybeUninitialized}; use ptr; /// When dropped, copies from `src` into `dest`. @@ -226,14 +226,14 @@ fn partition_in_blocks(v: &mut [T], pivot: &T, is_less: &mut F) -> usize let mut block_l = BLOCK; let mut start_l = ptr::null_mut(); let mut end_l = ptr::null_mut(); - let mut offsets_l = MaybeUninit::<[u8; BLOCK]>::uninitialized(); + let mut offsets_l = MaybeUninitialized::<[u8; BLOCK]>::uninitialized(); // The current block on the right side (from `r.sub(block_r)` to `r`). let mut r = unsafe { l.add(v.len()) }; let mut block_r = BLOCK; let mut start_r = ptr::null_mut(); let mut end_r = ptr::null_mut(); - let mut offsets_r = MaybeUninit::<[u8; BLOCK]>::uninitialized(); + let mut offsets_r = MaybeUninitialized::<[u8; BLOCK]>::uninitialized(); // FIXME: When we get VLAs, try creating one array of length `min(v.len(), 2 * BLOCK)` rather // than two fixed-size arrays of length `BLOCK`. VLAs might be more cache-efficient. diff --git a/src/librustc_mir/interpret/visitor.rs b/src/librustc_mir/interpret/visitor.rs index 4773f5627d716..861581819aa2b 100644 --- a/src/librustc_mir/interpret/visitor.rs +++ b/src/librustc_mir/interpret/visitor.rs @@ -310,7 +310,7 @@ macro_rules! make_value_visitor { }, layout::FieldPlacement::Arbitrary { ref offsets, .. } => { // Special handling needed for generators: All but the first field - // (which is the state) are actually implicitly `MaybeUninit`, i.e., + // (which is the state) are actually implicitly `MaybeUninitialized`, i.e., // they may or may not be initialized, so we cannot visit them. match v.layout().ty.sty { ty::Generator(..) => { diff --git a/src/libstd/sys/windows/mutex.rs b/src/libstd/sys/windows/mutex.rs index 2bd5dee63e883..09005c17be761 100644 --- a/src/libstd/sys/windows/mutex.rs +++ b/src/libstd/sys/windows/mutex.rs @@ -30,7 +30,7 @@ //! detect recursive locks. use cell::UnsafeCell; -use mem::{self, MaybeUninit}; +use mem::{self, MaybeUninitialized}; use sync::atomic::{AtomicUsize, Ordering}; use sys::c; use sys::compat; @@ -157,14 +157,14 @@ fn kind() -> Kind { return ret; } -pub struct ReentrantMutex { inner: UnsafeCell> } +pub struct ReentrantMutex { inner: UnsafeCell> } unsafe impl Send for ReentrantMutex {} unsafe impl Sync for ReentrantMutex {} impl ReentrantMutex { pub fn uninitialized() -> ReentrantMutex { - ReentrantMutex { inner: UnsafeCell::new(MaybeUninit::uninitialized()) } + ReentrantMutex { inner: UnsafeCell::new(MaybeUninitialized::uninitialized()) } } pub unsafe fn init(&mut self) { diff --git a/src/test/codegen/box-maybe-uninit.rs b/src/test/codegen/box-maybe-uninit.rs index 168e1a3eba0c5..599f235d5788d 100644 --- a/src/test/codegen/box-maybe-uninit.rs +++ b/src/test/codegen/box-maybe-uninit.rs @@ -12,12 +12,12 @@ #![crate_type="lib"] #![feature(maybe_uninit)] -use std::mem::MaybeUninit; +use std::mem::MaybeUninitialized; -// Boxing a `MaybeUninit` value should not copy junk from the stack +// Boxing a `MaybeUninitialized` value should not copy junk from the stack #[no_mangle] -pub fn box_uninitialized() -> Box> { +pub fn box_uninitialized() -> Box> { // CHECK-LABEL: @box_uninitialized // CHECK-NOT: store - Box::new(MaybeUninit::uninitialized()) + Box::new(MaybeUninitialized::uninitialized()) } diff --git a/src/test/debuginfo/nil-enum.rs b/src/test/debuginfo/nil-enum.rs index ab42b2eff99f8..a020027c7c45c 100644 --- a/src/test/debuginfo/nil-enum.rs +++ b/src/test/debuginfo/nil-enum.rs @@ -35,7 +35,7 @@ #![feature(maybe_uninit)] #![omit_gdb_pretty_printer_section] -use std::mem::MaybeUninit; +use std::mem::MaybeUninitialized; enum ANilEnum {} enum AnotherNilEnum {} @@ -45,8 +45,8 @@ enum AnotherNilEnum {} // The error from gdbr is expected since nil enums are not supposed to exist. fn main() { unsafe { - let first: ANilEnum = MaybeUninit::uninitialized().into_inner(); - let second: AnotherNilEnum = MaybeUninit::uninitialized().into_inner(); + let first: ANilEnum = MaybeUninitialized::uninitialized().into_inner(); + let second: AnotherNilEnum = MaybeUninitialized::uninitialized().into_inner(); zzz(); // #break }