]> git.lizzy.rs Git - rust.git/commitdiff
Revert "Auto merge of #53508 - japaric:maybe-uninit, r=RalfJung"
authorRalf Jung <post@ralfj.de>
Tue, 25 Sep 2018 13:07:27 +0000 (15:07 +0200)
committerRalf Jung <post@ralfj.de>
Sat, 29 Sep 2018 07:50:50 +0000 (09:50 +0200)
This reverts commit c6e3d7fa3113aaa64602507f39d4627c427742ff, reversing
changes made to 4591a245c7eec9f70d668982b1383cd2a6854af5.

20 files changed:
src/etc/gdb_rust_pretty_printing.py
src/liballoc/collections/btree/node.rs
src/liballoc/lib.rs
src/libcore/fmt/float.rs
src/libcore/lib.rs
src/libcore/mem.rs
src/libcore/ptr.rs
src/libcore/slice/rotate.rs
src/libcore/slice/sort.rs
src/librustc/ty/layout.rs
src/librustc_codegen_llvm/debuginfo/mod.rs
src/librustc_codegen_llvm/declare.rs
src/librustc_codegen_llvm/mir/block.rs
src/librustc_codegen_llvm/mir/place.rs
src/librustc_codegen_llvm/mir/rvalue.rs
src/librustc_mir/interpret/operand.rs
src/librustc_target/abi/mod.rs
src/test/codegen/box-maybe-uninit.rs [deleted file]
src/test/debuginfo/nil-enum.rs
src/test/run-pass/panic-uninitialized-zeroed.rs [deleted file]

index b1252f386df364dcd18708dc5bc6139fe465e0dd..216915dba5fe7c03116d1cf2906afd7bbafe392f 100755 (executable)
@@ -322,11 +322,8 @@ class RustStdBTreeSetPrinter(object):
     def children(self):
         (length, data_ptr) = \
             rustpp.extract_length_and_ptr_from_std_btreeset(self.__val)
-        leaf_node = GdbValue(data_ptr.get_wrapped_value().dereference())
-        maybe_uninit_keys = leaf_node.get_child_at_index(3)
-        manually_drop_keys = maybe_uninit_keys.get_child_at_index(1)
-        keys = manually_drop_keys.get_child_at_index(0)
-        gdb_ptr = keys.get_wrapped_value()
+        val = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(3)
+        gdb_ptr = val.get_wrapped_value()
         for index in xrange(length):
             yield (str(index), gdb_ptr[index])
 
@@ -348,14 +345,9 @@ class RustStdBTreeMapPrinter(object):
     def children(self):
         (length, data_ptr) = \
             rustpp.extract_length_and_ptr_from_std_btreemap(self.__val)
-        leaf_node = GdbValue(data_ptr.get_wrapped_value().dereference())
-        maybe_uninit_keys = leaf_node.get_child_at_index(3)
-        manually_drop_keys = maybe_uninit_keys.get_child_at_index(1)
-        keys = manually_drop_keys.get_child_at_index(0)
+        keys = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(3)
         keys_ptr = keys.get_wrapped_value()
-        maybe_uninit_vals = leaf_node.get_child_at_index(4)
-        manually_drop_vals = maybe_uninit_vals.get_child_at_index(1)
-        vals = manually_drop_vals.get_child_at_index(0)
+        vals = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(4)
         vals_ptr = vals.get_wrapped_value()
         for index in xrange(length):
             yield (str(index), keys_ptr[index])
index c86278fc5ddaacc10ecd0175d52860a3c75d20de..0315545262b6bc0a295953f22b4328070223356b 100644 (file)
@@ -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;
 use core::ptr::{self, Unique, NonNull};
 use core::slice;
 
@@ -73,7 +73,7 @@ struct LeafNode<K, V> {
     /// 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 nonnull.
-    parent_idx: MaybeUninit<u16>,
+    parent_idx: u16,
 
     /// The number of keys and values this node stores.
     ///
@@ -83,8 +83,8 @@ struct LeafNode<K, V> {
 
     /// 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: [K; CAPACITY],
+    vals: [V; CAPACITY],
 }
 
 impl<K, V> LeafNode<K, V> {
@@ -94,10 +94,10 @@ unsafe fn new() -> Self {
         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: mem::uninitialized(),
+            vals: mem::uninitialized(),
             parent: ptr::null(),
-            parent_idx: MaybeUninit::uninitialized(),
+            parent_idx: mem::uninitialized(),
             len: 0
         }
     }
@@ -115,10 +115,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: 0,
     len: 0,
-    keys: MaybeUninit::uninitialized(),
-    vals: MaybeUninit::uninitialized(),
+    keys: [(); CAPACITY],
+    vals: [(); CAPACITY],
 };
 
 /// The underlying representation of internal nodes. As with `LeafNode`s, these should be hidden
@@ -430,7 +430,7 @@ pub fn ascend(self) -> Result<
                     root: self.root,
                     _marker: PhantomData
                 },
-                idx: unsafe { usize::from(*self.as_leaf().parent_idx.get_ref()) },
+                idx: self.as_leaf().parent_idx as usize,
                 _marker: PhantomData
             })
         } else {
@@ -567,7 +567,7 @@ fn into_key_slice(self) -> &'a [K] {
             // the node, which is allowed by LLVM.
             unsafe {
                 slice::from_raw_parts(
-                    self.as_leaf().keys.as_ptr() as *const K,
+                    self.as_leaf().keys.as_ptr(),
                     self.len()
                 )
             }
@@ -578,7 +578,7 @@ fn into_val_slice(self) -> &'a [V] {
         debug_assert!(!self.is_shared_root());
         unsafe {
             slice::from_raw_parts(
-                self.as_leaf().vals.as_ptr() as *const V,
+                self.as_leaf().vals.as_ptr(),
                 self.len()
             )
         }
@@ -605,7 +605,7 @@ fn into_key_slice_mut(mut self) -> &'a mut [K] {
         } else {
             unsafe {
                 slice::from_raw_parts_mut(
-                    self.as_leaf_mut().keys.get_mut() as *mut [K] as *mut K,
+                    &mut self.as_leaf_mut().keys as *mut [K] as *mut K,
                     self.len()
                 )
             }
@@ -616,7 +616,7 @@ fn into_val_slice_mut(mut self) -> &'a mut [V] {
         debug_assert!(!self.is_shared_root());
         unsafe {
             slice::from_raw_parts_mut(
-                self.as_leaf_mut().vals.get_mut() as *mut [V] as *mut V,
+                &mut self.as_leaf_mut().vals as *mut [V] as *mut V,
                 self.len()
             )
         }
@@ -1013,7 +1013,7 @@ fn correct_parent_link(mut self) {
         let ptr = self.node.as_internal_mut() as *mut _;
         let mut child = self.descend();
         child.as_leaf_mut().parent = ptr;
-        child.as_leaf_mut().parent_idx.set(idx);
+        child.as_leaf_mut().parent_idx = idx;
     }
 
     /// Unsafely asserts to the compiler some static information about whether the underlying
@@ -1152,12 +1152,12 @@ pub fn split(mut self)
 
             ptr::copy_nonoverlapping(
                 self.node.keys().as_ptr().add(self.idx + 1),
-                new_node.keys.as_mut_ptr() as *mut K,
+                new_node.keys.as_mut_ptr(),
                 new_len
             );
             ptr::copy_nonoverlapping(
                 self.node.vals().as_ptr().add(self.idx + 1),
-                new_node.vals.as_mut_ptr() as *mut V,
+                new_node.vals.as_mut_ptr(),
                 new_len
             );
 
@@ -1210,12 +1210,12 @@ pub fn split(mut self)
 
             ptr::copy_nonoverlapping(
                 self.node.keys().as_ptr().add(self.idx + 1),
-                new_node.data.keys.as_mut_ptr() as *mut K,
+                new_node.data.keys.as_mut_ptr(),
                 new_len
             );
             ptr::copy_nonoverlapping(
                 self.node.vals().as_ptr().add(self.idx + 1),
-                new_node.data.vals.as_mut_ptr() as *mut V,
+                new_node.data.vals.as_mut_ptr(),
                 new_len
             );
             ptr::copy_nonoverlapping(
index 7960936dad6bfd385da503ba556e9e852bd96539..f92075cc84e509a739ad3ef8984c77d2f1f27437 100644 (file)
 #![feature(rustc_const_unstable)]
 #![feature(const_vec_new)]
 #![feature(slice_partition_dedup)]
-#![feature(maybe_uninit)]
 
 // Allow testing this library
 
index d01cd012031db45cbb99f4d51c008d8eba174fc1..03e7a9a49d8a763da0c6772b678ab23cba06ceb6 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 use fmt::{Formatter, Result, LowerExp, UpperExp, Display, Debug};
-use mem::MaybeUninit;
+use mem;
 use num::flt2dec;
 
 // Don't inline this so callers don't use the stack space this function
@@ -20,11 +20,11 @@ fn float_to_decimal_common_exact<T>(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: [u8; 1024] = mem::uninitialized(); // enough for f32 and f64
+        let mut parts: [flt2dec::Part; 4] = mem::uninitialized();
         let formatted = flt2dec::to_exact_fixed_str(flt2dec::strategy::grisu::format_exact,
                                                     *num, sign, precision,
-                                                    false, buf.get_mut(), parts.get_mut());
+                                                    false, &mut buf, &mut parts);
         fmt.pad_formatted_parts(&formatted)
     }
 }
@@ -38,11 +38,10 @@ fn float_to_decimal_common_shortest<T>(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: [u8; flt2dec::MAX_SIG_DIGITS] = mem::uninitialized();
+        let mut parts: [flt2dec::Part; 4] = mem::uninitialized();
         let formatted = flt2dec::to_shortest_str(flt2dec::strategy::grisu::format_shortest, *num,
-                                                 sign, precision, false, buf.get_mut(),
-                                                 parts.get_mut());
+                                                 sign, precision, false, &mut buf, &mut parts);
         fmt.pad_formatted_parts(&formatted)
     }
 }
@@ -76,11 +75,11 @@ fn float_to_exponential_common_exact<T>(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: [u8; 1024] = mem::uninitialized(); // enough for f32 and f64
+        let mut parts: [flt2dec::Part; 6] = mem::uninitialized();
         let formatted = flt2dec::to_exact_exp_str(flt2dec::strategy::grisu::format_exact,
                                                   *num, sign, precision,
-                                                  upper, buf.get_mut(), parts.get_mut());
+                                                  upper, &mut buf, &mut parts);
         fmt.pad_formatted_parts(&formatted)
     }
 }
@@ -95,11 +94,11 @@ fn float_to_exponential_common_shortest<T>(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: [u8; flt2dec::MAX_SIG_DIGITS] = mem::uninitialized();
+        let mut parts: [flt2dec::Part; 6] = mem::uninitialized();
         let formatted = flt2dec::to_shortest_exp_str(flt2dec::strategy::grisu::format_shortest,
                                                      *num, sign, (0, 0), upper,
-                                                     buf.get_mut(), parts.get_mut());
+                                                     &mut buf, &mut parts);
         fmt.pad_formatted_parts(&formatted)
     }
 }
index 3b7646fa2686f600ee759b3b2798a964f8cf3932..675e73e952cc2ca011c055a949d38c75e99b18e2 100644 (file)
 #[allow(unused_macros)]
 macro_rules! vector_impl { ($([$f:ident, $($args:tt)*]),*) => { $($f!($($args)*);)* } }
 #[path = "../stdsimd/coresimd/mod.rs"]
-// replacing uses of mem::{uninitialized,zeroed} with MaybeUninit needs to be in the stdsimd repo
-#[allow(deprecated)]
 #[allow(missing_docs, missing_debug_implementations, dead_code, unused_imports)]
 #[unstable(feature = "stdsimd", issue = "48556")]
 #[cfg(not(stage0))] // allow changes to how stdsimd works in stage0
index c99c9f96f12d67d712b0fef3a413440d57e67245..1803adee3c18e04de03142700875c3d38e544502 100644 (file)
@@ -514,7 +514,6 @@ pub fn needs_drop<T>() -> bool {
 /// assert_eq!(0, x);
 /// ```
 #[inline]
-#[rustc_deprecated(since = "2.0.0", reason = "use `mem::MaybeUninit::zeroed` instead")]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub unsafe fn zeroed<T>() -> T {
     intrinsics::init()
@@ -609,7 +608,6 @@ pub unsafe fn zeroed<T>() -> 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")]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub unsafe fn uninitialized<T>() -> T {
     intrinsics::uninit()
@@ -1026,97 +1024,3 @@ fn deref_mut(&mut self) -> &mut Self::Target {
         &mut self.value
     }
 }
-
-/// 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<T> {
-    uninit: (),
-    value: ManuallyDrop<T>,
-}
-
-impl<T> MaybeUninit<T> {
-    /// Create a new `MaybeUninit` in an uninitialized state.
-    ///
-    /// Note that dropping a `MaybeUninit` 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")]
-    pub const fn uninitialized() -> MaybeUninit<T> {
-        MaybeUninit { uninit: () }
-    }
-
-    /// Create a new `MaybeUninit` 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<usize>::zeroed()` is initialized,
-    /// but `MaybeUninit<&'static i32>::zeroed()` is not because references must not
-    /// be null.
-    ///
-    /// Note that dropping a `MaybeUninit` 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")]
-    pub fn zeroed() -> MaybeUninit<T> {
-        let mut u = MaybeUninit::<T>::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.
-    #[unstable(feature = "maybe_uninit", issue = "53491")]
-    pub fn set(&mut self, val: T) {
-        unsafe {
-            self.value = ManuallyDrop::new(val);
-        }
-    }
-
-    /// Extract the value from the `MaybeUninit` 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 the `MaybeUninit` really is in an initialized
-    /// state, otherwise this will immediately cause undefined behavior.
-    #[unstable(feature = "maybe_uninit", issue = "53491")]
-    pub unsafe fn into_inner(self) -> T {
-        ManuallyDrop::into_inner(self.value)
-    }
-
-    /// Get a reference to the contained value.
-    ///
-    /// # Unsafety
-    ///
-    /// It is up to the caller to guarantee that the the `MaybeUninit` really is in an initialized
-    /// state, otherwise this will immediately cause undefined behavior.
-    #[unstable(feature = "maybe_uninit", issue = "53491")]
-    pub unsafe fn get_ref(&self) -> &T {
-        &*self.value
-    }
-
-    /// Get a mutable reference to the contained value.
-    ///
-    /// # Unsafety
-    ///
-    /// It is up to the caller to guarantee that the the `MaybeUninit` really is in an initialized
-    /// state, otherwise this will immediately cause undefined behavior.
-    #[unstable(feature = "maybe_uninit", issue = "53491")]
-    pub unsafe fn get_mut(&mut self) -> &mut T {
-        &mut *self.value
-    }
-
-    /// Get a pointer to the contained value. Reading from this pointer will be undefined
-    /// behavior unless the `MaybeUninit` is initialized.
-    #[unstable(feature = "maybe_uninit", issue = "53491")]
-    pub fn as_ptr(&self) -> *const T {
-        unsafe { &*self.value as *const T }
-    }
-
-    /// Get a mutable pointer to the contained value. Reading from this pointer will be undefined
-    /// behavior unless the `MaybeUninit` is initialized.
-    #[unstable(feature = "maybe_uninit", issue = "53491")]
-    pub fn as_mut_ptr(&mut self) -> *mut T {
-        unsafe { &mut *self.value as *mut T }
-    }
-}
index b23b72c3720105f5aacde04707fe84bbbe37659a..14f2148a64e0ef299e1cebf7e295b3a6e1d0bc2d 100644 (file)
@@ -79,7 +79,7 @@
 use fmt;
 use hash;
 use marker::{PhantomData, Unsize};
-use mem::{self, MaybeUninit};
+use mem;
 use nonzero::NonZero;
 
 use cmp::Ordering::{self, Less, Equal, Greater};
@@ -294,12 +294,16 @@ pub const fn null_mut<T>() -> *mut T { 0 as *mut T }
 #[stable(feature = "rust1", since = "1.0.0")]
 pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
     // Give ourselves some scratch space to work with
-    let mut tmp = MaybeUninit::<T>::uninitialized();
+    let mut tmp: T = mem::uninitialized();
 
     // Perform the swap
-    copy_nonoverlapping(x, tmp.as_mut_ptr(), 1);
+    copy_nonoverlapping(x, &mut tmp, 1);
     copy(y, x, 1); // `x` and `y` may overlap
-    copy_nonoverlapping(tmp.get_ref(), y, 1);
+    copy_nonoverlapping(&tmp, y, 1);
+
+    // y and t now point to the same thing, but we need to completely forget `tmp`
+    // because it's no longer relevant.
+    mem::forget(tmp);
 }
 
 /// Swaps `count * size_of::<T>()` bytes between the two regions of memory
@@ -386,8 +390,8 @@ 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::<Block>::uninitialized();
-        let t = t.as_mut_ptr() as *mut u8;
+        let mut t: Block = mem::uninitialized();
+        let t = &mut t as *mut _ as *mut u8;
         let x = x.add(i);
         let y = y.add(i);
 
@@ -401,10 +405,10 @@ 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::<UnalignedBlock>::uninitialized();
+        let mut t: UnalignedBlock = mem::uninitialized();
         let rem = len - i;
 
-        let t = t.as_mut_ptr() as *mut u8;
+        let t = &mut t as *mut _ as *mut u8;
         let x = x.add(i);
         let y = y.add(i);
 
@@ -569,9 +573,9 @@ pub unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
 #[inline]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub unsafe fn read<T>(src: *const T) -> T {
-    let mut tmp = MaybeUninit::<T>::uninitialized();
-    copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
-    tmp.into_inner()
+    let mut tmp: T = mem::uninitialized();
+    copy_nonoverlapping(src, &mut tmp, 1);
+    tmp
 }
 
 /// Reads the value from `src` without moving it. This leaves the
@@ -636,11 +640,11 @@ pub unsafe fn read<T>(src: *const T) -> T {
 #[inline]
 #[stable(feature = "ptr_unaligned", since = "1.17.0")]
 pub unsafe fn read_unaligned<T>(src: *const T) -> T {
-    let mut tmp = MaybeUninit::<T>::uninitialized();
+    let mut tmp: T = mem::uninitialized();
     copy_nonoverlapping(src as *const u8,
-                        tmp.as_mut_ptr() as *mut u8,
+                        &mut tmp as *mut T as *mut u8,
                         mem::size_of::<T>());
-    tmp.into_inner()
+    tmp
 }
 
 /// Overwrites a memory location with the given value without reading or
index 07153735300b89ccc376e472aac7f0bcbfb51f80..0d182b8497452e2bf7db6d6417b4b6e2092d3b34 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 use cmp;
-use mem::{self, MaybeUninit};
+use mem;
 use ptr;
 
 /// Rotation is much faster if it has access to a little bit of memory. This
@@ -26,6 +26,12 @@ union RawArray<T> {
 }
 
 impl<T> RawArray<T> {
+    fn new() -> Self {
+        unsafe { mem::uninitialized() }
+    }
+    fn ptr(&self) -> *mut T {
+        unsafe { &self.typed as *const T as *mut T }
+    }
     fn cap() -> usize {
         if mem::size_of::<T>() == 0 {
             usize::max_value()
@@ -82,8 +88,8 @@ pub unsafe fn ptr_rotate<T>(mut left: usize, mid: *mut T, mut right: usize) {
         }
     }
 
-    let mut rawarray = MaybeUninit::<RawArray<T>>::uninitialized();
-    let buf = &mut (*rawarray.as_mut_ptr()).typed as *mut [T; 2] as *mut T;
+    let rawarray = RawArray::new();
+    let buf = rawarray.ptr();
 
     let dim = mid.sub(left).add(right);
     if left <= right {
index affe84fbef91f2e6908385556b1e3b8d0d90c2dd..e4c1fd03f9eb384b1197e5a6d3b82ed14f85d349 100644 (file)
@@ -17,7 +17,7 @@
 //! stable sorting implementation.
 
 use cmp;
-use mem::{self, MaybeUninit};
+use mem;
 use ptr;
 
 /// When dropped, copies from `src` into `dest`.
@@ -226,14 +226,14 @@ fn partition_in_blocks<T, F>(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: [u8; BLOCK] = unsafe { mem::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: [u8; BLOCK] = unsafe { mem::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.
@@ -272,8 +272,8 @@ fn width<T>(l: *mut T, r: *mut T) -> usize {
 
         if start_l == end_l {
             // Trace `block_l` elements from the left side.
-            start_l = offsets_l.as_mut_ptr() as *mut u8;
-            end_l = offsets_l.as_mut_ptr() as *mut u8;
+            start_l = offsets_l.as_mut_ptr();
+            end_l = offsets_l.as_mut_ptr();
             let mut elem = l;
 
             for i in 0..block_l {
@@ -288,8 +288,8 @@ fn width<T>(l: *mut T, r: *mut T) -> usize {
 
         if start_r == end_r {
             // Trace `block_r` elements from the right side.
-            start_r = offsets_r.as_mut_ptr() as *mut u8;
-            end_r = offsets_r.as_mut_ptr() as *mut u8;
+            start_r = offsets_r.as_mut_ptr();
+            end_r = offsets_r.as_mut_ptr();
             let mut elem = r;
 
             for i in 0..block_r {
index 3d2088ea12e8efa69a0f4a8a058738901d5fd8ee..4e37a34a0c8a7f9af70d13a8f8d1cd8a790a3003 100644 (file)
@@ -449,7 +449,7 @@ enum StructKind {
                 }
             }
 
-            if sized && fields.iter().any(|f| f.abi.is_uninhabited()) {
+            if sized && fields.iter().any(|f| f.abi == Abi::Uninhabited) {
                 abi = Abi::Uninhabited;
             }
 
@@ -724,7 +724,7 @@ enum StructKind {
                 // See issue #49298 for more details on the need to leave space
                 // for non-ZST uninhabited data (mostly partial initialization).
                 let absent = |fields: &[TyLayout]| {
-                    let uninhabited = fields.iter().any(|f| f.abi.is_uninhabited());
+                    let uninhabited = fields.iter().any(|f| f.abi == Abi::Uninhabited);
                     let is_zst = fields.iter().all(|f| f.is_zst());
                     uninhabited && is_zst
                 };
@@ -872,7 +872,7 @@ enum StructKind {
                                 _ => Abi::Aggregate { sized: true },
                             };
 
-                            if st.iter().all(|v| v.abi.is_uninhabited()) {
+                            if st.iter().all(|v| v.abi == Abi::Uninhabited) {
                                 abi = Abi::Uninhabited;
                             }
 
@@ -900,7 +900,7 @@ enum StructKind {
                 let discr_type = def.repr.discr_type();
                 let bits = Integer::from_attr(tcx, discr_type).size().bits();
                 for (i, discr) in def.discriminants(tcx).enumerate() {
-                    if variants[i].iter().any(|f| f.abi.is_uninhabited()) {
+                    if variants[i].iter().any(|f| f.abi == Abi::Uninhabited) {
                         continue;
                     }
                     let mut x = discr.val as i128;
@@ -1096,7 +1096,7 @@ enum StructKind {
                     }
                 }
 
-                if layout_variants.iter().all(|v| v.abi.is_uninhabited()) {
+                if layout_variants.iter().all(|v| v.abi == Abi::Uninhabited) {
                     abi = Abi::Uninhabited;
                 }
 
index 7b0c413e857617b7ffbd5fd975285875ddf33579..99919a940b40511dcd605cea460440d5a1a9e05a 100644 (file)
@@ -279,7 +279,7 @@ pub fn create_function_debug_context(
         }
         None => {}
     };
-    if cx.layout_of(sig.output()).abi.is_uninhabited() {
+    if cx.layout_of(sig.output()).abi == ty::layout::Abi::Uninhabited {
         flags = flags | DIFlags::FlagNoReturn;
     }
 
index 7141c9ece89d7180ea0c7f85f22e1fb29afbf8e1..5e743ac51bc616ffebbf47aa31851f9911a243a7 100644 (file)
@@ -23,7 +23,7 @@
 use llvm;
 use llvm::AttributePlace::Function;
 use rustc::ty::{self, Ty};
-use rustc::ty::layout::LayoutOf;
+use rustc::ty::layout::{self, LayoutOf};
 use rustc::session::config::Sanitizer;
 use rustc_data_structures::small_c_str::SmallCStr;
 use rustc_target::spec::PanicStrategy;
@@ -137,7 +137,7 @@ pub fn declare_fn(
     let fty = FnType::new(cx, sig, &[]);
     let llfn = declare_raw_fn(cx, name, fty.llvm_cconv(), fty.llvm_type(cx));
 
-    if cx.layout_of(sig.output()).abi.is_uninhabited() {
+    if cx.layout_of(sig.output()).abi == layout::Abi::Uninhabited {
         llvm::Attribute::NoReturn.apply_llfn(Function, llfn);
     }
 
index 709fceb492509e9c88cddac93057e6d66d32c55c..a534b4e478fb793e4f96496e4621287c25eb0a24 100644 (file)
@@ -482,54 +482,6 @@ fn codegen_terminator(&mut self,
                     _ => FnType::new(bx.cx, sig, &extra_args)
                 };
 
-                // emit a panic instead of instantiating an uninhabited type
-                if (intrinsic == Some("init") || intrinsic == Some("uninit")) &&
-                    fn_ty.ret.layout.abi.is_uninhabited()
-                {
-                    let loc = bx.sess().source_map().lookup_char_pos(span.lo());
-                    let filename = Symbol::intern(&loc.file.name.to_string()).as_str();
-                    let filename = C_str_slice(bx.cx, filename);
-                    let line = C_u32(bx.cx, loc.line as u32);
-                    let col = C_u32(bx.cx, loc.col.to_usize() as u32 + 1);
-                    let align = tcx.data_layout.aggregate_align
-                        .max(tcx.data_layout.i32_align)
-                        .max(tcx.data_layout.pointer_align);
-
-                    let str = format!(
-                        "Attempted to instantiate uninhabited type {} using mem::{}",
-                        sig.output(),
-                        if intrinsic == Some("init") { "zeroed" } else { "uninitialized" }
-                    );
-                    let msg_str = Symbol::intern(&str).as_str();
-                    let msg_str = C_str_slice(bx.cx, msg_str);
-                    let msg_file_line_col = C_struct(bx.cx,
-                                                    &[msg_str, filename, line, col],
-                                                    false);
-                    let msg_file_line_col = consts::addr_of(bx.cx,
-                                                            msg_file_line_col,
-                                                            align,
-                                                            Some("panic_loc"));
-
-                    // Obtain the panic entry point.
-                    let def_id =
-                        common::langcall(bx.tcx(), Some(span), "", lang_items::PanicFnLangItem);
-                    let instance = ty::Instance::mono(bx.tcx(), def_id);
-                    let fn_ty = FnType::of_instance(bx.cx, &instance);
-                    let llfn = callee::get_fn(bx.cx, instance);
-
-                    // Codegen the actual panic invoke/call.
-                    do_call(
-                        self,
-                        bx,
-                        fn_ty,
-                        llfn,
-                        &[msg_file_line_col],
-                        destination.as_ref().map(|(_, bb)| (ReturnDest::Nothing, *bb)),
-                        cleanup,
-                    );
-                    return;
-                }
-
                 // The arguments we'll be passing. Plus one to account for outptr, if used.
                 let arg_count = fn_ty.args.len() + fn_ty.ret.is_indirect() as usize;
                 let mut llargs = Vec::with_capacity(arg_count);
index e7b6f5908a4d16a2c4fa9780d53bd5abbcd9d5ff..c781b456af6b284825e3048984aaebaff01ab28d 100644 (file)
@@ -275,7 +275,7 @@ pub fn project_field(self, bx: &Builder<'a, 'll, 'tcx>, ix: usize) -> PlaceRef<'
     /// Obtain the actual discriminant of a value.
     pub fn codegen_get_discr(self, bx: &Builder<'a, 'll, 'tcx>, cast_to: Ty<'tcx>) -> &'ll Value {
         let cast_to = bx.cx.layout_of(cast_to).immediate_llvm_type(bx.cx);
-        if self.layout.abi.is_uninhabited() {
+        if self.layout.abi == layout::Abi::Uninhabited {
             return C_undef(cast_to);
         }
         match self.layout.variants {
@@ -338,7 +338,7 @@ pub fn codegen_get_discr(self, bx: &Builder<'a, 'll, 'tcx>, cast_to: Ty<'tcx>) -
     /// Set the discriminant for a new value of the given case of the given
     /// representation.
     pub fn codegen_set_discr(&self, bx: &Builder<'a, 'll, 'tcx>, variant_index: usize) {
-        if self.layout.for_variant(bx.cx, variant_index).abi.is_uninhabited() {
+        if self.layout.for_variant(bx.cx, variant_index).abi == layout::Abi::Uninhabited {
             return;
         }
         match self.layout.variants {
index fa22bdff94dddbeb29fda3c9a0295e6c2100ea8b..c3ec347f60876c03dc846bbec04f75f546b8d75d 100644 (file)
@@ -290,7 +290,7 @@ pub fn codegen_rvalue_operand(&mut self,
                     mir::CastKind::Misc => {
                         assert!(cast.is_llvm_immediate());
                         let ll_t_out = cast.immediate_llvm_type(bx.cx);
-                        if operand.layout.abi.is_uninhabited() {
+                        if operand.layout.abi == layout::Abi::Uninhabited {
                             return (bx, OperandRef {
                                 val: OperandValue::Immediate(C_undef(ll_t_out)),
                                 layout: cast,
index a11150c47836e11bc11c591c326cfe132eb48c1f..fef2f916b415667652fbf123527509fd40d5257a 100644 (file)
@@ -514,7 +514,7 @@ pub fn read_discriminant(
         rval: OpTy<'tcx>,
     ) -> EvalResult<'tcx, (u128, usize)> {
         trace!("read_discriminant_value {:#?}", rval.layout);
-        if rval.layout.abi.is_uninhabited() {
+        if rval.layout.abi == layout::Abi::Uninhabited {
             return err!(Unreachable);
         }
 
index 96eb69163220e7b33c57287bd9ac35596ab6b589..5c4cd849f89bcd681e323d5db483f2d6764a874e 100644 (file)
@@ -802,14 +802,6 @@ pub fn is_signed(&self) -> bool {
             _ => false,
         }
     }
-
-    /// Returns true if this is an uninhabited type
-    pub fn is_uninhabited(&self) -> bool {
-        match *self {
-            Abi::Uninhabited => true,
-            _ => false,
-        }
-    }
 }
 
 #[derive(PartialEq, Eq, Hash, Debug)]
diff --git a/src/test/codegen/box-maybe-uninit.rs b/src/test/codegen/box-maybe-uninit.rs
deleted file mode 100644 (file)
index 168e1a3..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// compile-flags: -O
-#![crate_type="lib"]
-#![feature(maybe_uninit)]
-
-use std::mem::MaybeUninit;
-
-// Boxing a `MaybeUninit` value should not copy junk from the stack
-#[no_mangle]
-pub fn box_uninitialized() -> Box<MaybeUninit<usize>> {
-    // CHECK-LABEL: @box_uninitialized
-    // CHECK-NOT: store
-    Box::new(MaybeUninit::uninitialized())
-}
index ab9c7e2dd2758a5d4dec1827be9c915f7fef0848..94377421c0b0c9927a039b26970371581d959315 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// NOTE Instantiating an empty enum is UB. This test may break in the future.
-
 // LLDB can't handle zero-sized values
 // ignore-lldb
 
 
 #![allow(unused_variables)]
 #![feature(omit_gdb_pretty_printer_section)]
-#![feature(maybe_uninit)]
 #![omit_gdb_pretty_printer_section]
 
-use std::mem::MaybeUninit;
-
 enum ANilEnum {}
 enum AnotherNilEnum {}
 
@@ -40,8 +35,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 = ::std::mem::zeroed();
+        let second: AnotherNilEnum = ::std::mem::zeroed();
 
         zzz(); // #break
     }
diff --git a/src/test/run-pass/panic-uninitialized-zeroed.rs b/src/test/run-pass/panic-uninitialized-zeroed.rs
deleted file mode 100644 (file)
index 2972f6e..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// ignore-wasm32-bare always compiled as panic=abort right now and this requires unwinding
-// This test checks that instantiating an uninhabited type via `mem::{uninitialized,zeroed}` results
-// in a runtime panic.
-
-#![feature(never_type)]
-
-use std::{mem, panic};
-
-#[allow(dead_code)]
-struct Foo {
-    x: u8,
-    y: !,
-}
-
-enum Bar {}
-
-fn main() {
-    unsafe {
-        assert_eq!(
-            panic::catch_unwind(|| {
-                mem::uninitialized::<!>()
-            }).err().and_then(|a| a.downcast_ref::<String>().map(|s| {
-                s == "Attempted to instantiate uninhabited type ! using mem::uninitialized"
-            })),
-            Some(true)
-        );
-
-        assert_eq!(
-            panic::catch_unwind(|| {
-                mem::zeroed::<!>()
-            }).err().and_then(|a| a.downcast_ref::<String>().map(|s| {
-                s == "Attempted to instantiate uninhabited type ! using mem::zeroed"
-            })),
-            Some(true)
-        );
-
-        assert_eq!(
-            panic::catch_unwind(|| {
-                mem::uninitialized::<Foo>()
-            }).err().and_then(|a| a.downcast_ref::<String>().map(|s| {
-                s == "Attempted to instantiate uninhabited type Foo using mem::uninitialized"
-            })),
-            Some(true)
-        );
-
-        assert_eq!(
-            panic::catch_unwind(|| {
-                mem::zeroed::<Foo>()
-            }).err().and_then(|a| a.downcast_ref::<String>().map(|s| {
-                s == "Attempted to instantiate uninhabited type Foo using mem::zeroed"
-            })),
-            Some(true)
-        );
-
-        assert_eq!(
-            panic::catch_unwind(|| {
-                mem::uninitialized::<Bar>()
-            }).err().and_then(|a| a.downcast_ref::<String>().map(|s| {
-                s == "Attempted to instantiate uninhabited type Bar using mem::uninitialized"
-            })),
-            Some(true)
-        );
-
-        assert_eq!(
-            panic::catch_unwind(|| {
-                mem::zeroed::<Bar>()
-            }).err().and_then(|a| a.downcast_ref::<String>().map(|s| {
-                s == "Attempted to instantiate uninhabited type Bar using mem::zeroed"
-            })),
-            Some(true)
-        );
-    }
-}