Skip to content

Commit e37d6d3

Browse files
committed
Revert "Auto merge of rust-lang#53508 - japaric:maybe-uninit, r=RalfJung"
This reverts commit c6e3d7f, reversing changes made to 4591a24.
1 parent 6622172 commit e37d6d3

File tree

20 files changed

+85
-350
lines changed

20 files changed

+85
-350
lines changed

src/etc/gdb_rust_pretty_printing.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,8 @@ def to_string(self):
322322
def children(self):
323323
(length, data_ptr) = \
324324
rustpp.extract_length_and_ptr_from_std_btreeset(self.__val)
325-
leaf_node = GdbValue(data_ptr.get_wrapped_value().dereference())
326-
maybe_uninit_keys = leaf_node.get_child_at_index(3)
327-
manually_drop_keys = maybe_uninit_keys.get_child_at_index(1)
328-
keys = manually_drop_keys.get_child_at_index(0)
329-
gdb_ptr = keys.get_wrapped_value()
325+
val = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(3)
326+
gdb_ptr = val.get_wrapped_value()
330327
for index in xrange(length):
331328
yield (str(index), gdb_ptr[index])
332329

@@ -348,14 +345,9 @@ def to_string(self):
348345
def children(self):
349346
(length, data_ptr) = \
350347
rustpp.extract_length_and_ptr_from_std_btreemap(self.__val)
351-
leaf_node = GdbValue(data_ptr.get_wrapped_value().dereference())
352-
maybe_uninit_keys = leaf_node.get_child_at_index(3)
353-
manually_drop_keys = maybe_uninit_keys.get_child_at_index(1)
354-
keys = manually_drop_keys.get_child_at_index(0)
348+
keys = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(3)
355349
keys_ptr = keys.get_wrapped_value()
356-
maybe_uninit_vals = leaf_node.get_child_at_index(4)
357-
manually_drop_vals = maybe_uninit_vals.get_child_at_index(1)
358-
vals = manually_drop_vals.get_child_at_index(0)
350+
vals = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(4)
359351
vals_ptr = vals.get_wrapped_value()
360352
for index in xrange(length):
361353
yield (str(index), keys_ptr[index])

src/liballoc/collections/btree/node.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
// This implies that even an empty internal node has at least one edge.
4343

4444
use core::marker::PhantomData;
45-
use core::mem::{self, MaybeUninit};
45+
use core::mem;
4646
use core::ptr::{self, Unique, NonNull};
4747
use core::slice;
4848

@@ -73,7 +73,7 @@ struct LeafNode<K, V> {
7373
/// This node's index into the parent node's `edges` array.
7474
/// `*node.parent.edges[node.parent_idx]` should be the same thing as `node`.
7575
/// This is only guaranteed to be initialized when `parent` is nonnull.
76-
parent_idx: MaybeUninit<u16>,
76+
parent_idx: u16,
7777

7878
/// The number of keys and values this node stores.
7979
///
@@ -83,8 +83,8 @@ struct LeafNode<K, V> {
8383

8484
/// The arrays storing the actual data of the node. Only the first `len` elements of each
8585
/// array are initialized and valid.
86-
keys: MaybeUninit<[K; CAPACITY]>,
87-
vals: MaybeUninit<[V; CAPACITY]>,
86+
keys: [K; CAPACITY],
87+
vals: [V; CAPACITY],
8888
}
8989

9090
impl<K, V> LeafNode<K, V> {
@@ -94,10 +94,10 @@ impl<K, V> LeafNode<K, V> {
9494
LeafNode {
9595
// As a general policy, we leave fields uninitialized if they can be, as this should
9696
// be both slightly faster and easier to track in Valgrind.
97-
keys: MaybeUninit::uninitialized(),
98-
vals: MaybeUninit::uninitialized(),
97+
keys: mem::uninitialized(),
98+
vals: mem::uninitialized(),
9999
parent: ptr::null(),
100-
parent_idx: MaybeUninit::uninitialized(),
100+
parent_idx: mem::uninitialized(),
101101
len: 0
102102
}
103103
}
@@ -115,10 +115,10 @@ unsafe impl Sync for LeafNode<(), ()> {}
115115
// ever take a pointer past the first key.
116116
static EMPTY_ROOT_NODE: LeafNode<(), ()> = LeafNode {
117117
parent: ptr::null(),
118-
parent_idx: MaybeUninit::uninitialized(),
118+
parent_idx: 0,
119119
len: 0,
120-
keys: MaybeUninit::uninitialized(),
121-
vals: MaybeUninit::uninitialized(),
120+
keys: [(); CAPACITY],
121+
vals: [(); CAPACITY],
122122
};
123123

124124
/// The underlying representation of internal nodes. As with `LeafNode`s, these should be hidden
@@ -430,7 +430,7 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
430430
root: self.root,
431431
_marker: PhantomData
432432
},
433-
idx: unsafe { usize::from(*self.as_leaf().parent_idx.get_ref()) },
433+
idx: self.as_leaf().parent_idx as usize,
434434
_marker: PhantomData
435435
})
436436
} else {
@@ -567,7 +567,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> {
567567
// the node, which is allowed by LLVM.
568568
unsafe {
569569
slice::from_raw_parts(
570-
self.as_leaf().keys.as_ptr() as *const K,
570+
self.as_leaf().keys.as_ptr(),
571571
self.len()
572572
)
573573
}
@@ -578,7 +578,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> {
578578
debug_assert!(!self.is_shared_root());
579579
unsafe {
580580
slice::from_raw_parts(
581-
self.as_leaf().vals.as_ptr() as *const V,
581+
self.as_leaf().vals.as_ptr(),
582582
self.len()
583583
)
584584
}
@@ -605,7 +605,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
605605
} else {
606606
unsafe {
607607
slice::from_raw_parts_mut(
608-
self.as_leaf_mut().keys.get_mut() as *mut [K] as *mut K,
608+
&mut self.as_leaf_mut().keys as *mut [K] as *mut K,
609609
self.len()
610610
)
611611
}
@@ -616,7 +616,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
616616
debug_assert!(!self.is_shared_root());
617617
unsafe {
618618
slice::from_raw_parts_mut(
619-
self.as_leaf_mut().vals.get_mut() as *mut [V] as *mut V,
619+
&mut self.as_leaf_mut().vals as *mut [V] as *mut V,
620620
self.len()
621621
)
622622
}
@@ -1013,7 +1013,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
10131013
let ptr = self.node.as_internal_mut() as *mut _;
10141014
let mut child = self.descend();
10151015
child.as_leaf_mut().parent = ptr;
1016-
child.as_leaf_mut().parent_idx.set(idx);
1016+
child.as_leaf_mut().parent_idx = idx;
10171017
}
10181018

10191019
/// Unsafely asserts to the compiler some static information about whether the underlying
@@ -1152,12 +1152,12 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::KV>
11521152

11531153
ptr::copy_nonoverlapping(
11541154
self.node.keys().as_ptr().add(self.idx + 1),
1155-
new_node.keys.as_mut_ptr() as *mut K,
1155+
new_node.keys.as_mut_ptr(),
11561156
new_len
11571157
);
11581158
ptr::copy_nonoverlapping(
11591159
self.node.vals().as_ptr().add(self.idx + 1),
1160-
new_node.vals.as_mut_ptr() as *mut V,
1160+
new_node.vals.as_mut_ptr(),
11611161
new_len
11621162
);
11631163

@@ -1210,12 +1210,12 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
12101210

12111211
ptr::copy_nonoverlapping(
12121212
self.node.keys().as_ptr().add(self.idx + 1),
1213-
new_node.data.keys.as_mut_ptr() as *mut K,
1213+
new_node.data.keys.as_mut_ptr(),
12141214
new_len
12151215
);
12161216
ptr::copy_nonoverlapping(
12171217
self.node.vals().as_ptr().add(self.idx + 1),
1218-
new_node.data.vals.as_mut_ptr() as *mut V,
1218+
new_node.data.vals.as_mut_ptr(),
12191219
new_len
12201220
);
12211221
ptr::copy_nonoverlapping(

src/liballoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
#![feature(rustc_const_unstable)]
121121
#![feature(const_vec_new)]
122122
#![feature(slice_partition_dedup)]
123-
#![feature(maybe_uninit)]
124123

125124
// Allow testing this library
126125

src/libcore/fmt/float.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use fmt::{Formatter, Result, LowerExp, UpperExp, Display, Debug};
12-
use mem::MaybeUninit;
12+
use mem;
1313
use num::flt2dec;
1414

1515
// 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,
2020
where T: flt2dec::DecodableFloat
2121
{
2222
unsafe {
23-
let mut buf = MaybeUninit::<[u8; 1024]>::uninitialized(); // enough for f32 and f64
24-
let mut parts = MaybeUninit::<[flt2dec::Part; 4]>::uninitialized();
23+
let mut buf: [u8; 1024] = mem::uninitialized(); // enough for f32 and f64
24+
let mut parts: [flt2dec::Part; 4] = mem::uninitialized();
2525
let formatted = flt2dec::to_exact_fixed_str(flt2dec::strategy::grisu::format_exact,
2626
*num, sign, precision,
27-
false, buf.get_mut(), parts.get_mut());
27+
false, &mut buf, &mut parts);
2828
fmt.pad_formatted_parts(&formatted)
2929
}
3030
}
@@ -38,11 +38,10 @@ fn float_to_decimal_common_shortest<T>(fmt: &mut Formatter, num: &T,
3838
{
3939
unsafe {
4040
// enough for f32 and f64
41-
let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninitialized();
42-
let mut parts = MaybeUninit::<[flt2dec::Part; 4]>::uninitialized();
41+
let mut buf: [u8; flt2dec::MAX_SIG_DIGITS] = mem::uninitialized();
42+
let mut parts: [flt2dec::Part; 4] = mem::uninitialized();
4343
let formatted = flt2dec::to_shortest_str(flt2dec::strategy::grisu::format_shortest, *num,
44-
sign, precision, false, buf.get_mut(),
45-
parts.get_mut());
44+
sign, precision, false, &mut buf, &mut parts);
4645
fmt.pad_formatted_parts(&formatted)
4746
}
4847
}
@@ -76,11 +75,11 @@ fn float_to_exponential_common_exact<T>(fmt: &mut Formatter, num: &T,
7675
where T: flt2dec::DecodableFloat
7776
{
7877
unsafe {
79-
let mut buf = MaybeUninit::<[u8; 1024]>::uninitialized(); // enough for f32 and f64
80-
let mut parts = MaybeUninit::<[flt2dec::Part; 6]>::uninitialized();
78+
let mut buf: [u8; 1024] = mem::uninitialized(); // enough for f32 and f64
79+
let mut parts: [flt2dec::Part; 6] = mem::uninitialized();
8180
let formatted = flt2dec::to_exact_exp_str(flt2dec::strategy::grisu::format_exact,
8281
*num, sign, precision,
83-
upper, buf.get_mut(), parts.get_mut());
82+
upper, &mut buf, &mut parts);
8483
fmt.pad_formatted_parts(&formatted)
8584
}
8685
}
@@ -95,11 +94,11 @@ fn float_to_exponential_common_shortest<T>(fmt: &mut Formatter,
9594
{
9695
unsafe {
9796
// enough for f32 and f64
98-
let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninitialized();
99-
let mut parts = MaybeUninit::<[flt2dec::Part; 6]>::uninitialized();
97+
let mut buf: [u8; flt2dec::MAX_SIG_DIGITS] = mem::uninitialized();
98+
let mut parts: [flt2dec::Part; 6] = mem::uninitialized();
10099
let formatted = flt2dec::to_shortest_exp_str(flt2dec::strategy::grisu::format_shortest,
101100
*num, sign, (0, 0), upper,
102-
buf.get_mut(), parts.get_mut());
101+
&mut buf, &mut parts);
103102
fmt.pad_formatted_parts(&formatted)
104103
}
105104
}

src/libcore/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ macro_rules! test_v512 { ($item:item) => {}; }
246246
#[allow(unused_macros)]
247247
macro_rules! vector_impl { ($([$f:ident, $($args:tt)*]),*) => { $($f!($($args)*);)* } }
248248
#[path = "../stdsimd/coresimd/mod.rs"]
249-
// replacing uses of mem::{uninitialized,zeroed} with MaybeUninit needs to be in the stdsimd repo
250-
#[allow(deprecated)]
251249
#[allow(missing_docs, missing_debug_implementations, dead_code, unused_imports)]
252250
#[unstable(feature = "stdsimd", issue = "48556")]
253251
#[cfg(not(stage0))] // allow changes to how stdsimd works in stage0

src/libcore/mem.rs

-96
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,6 @@ pub fn needs_drop<T>() -> bool {
514514
/// assert_eq!(0, x);
515515
/// ```
516516
#[inline]
517-
#[rustc_deprecated(since = "2.0.0", reason = "use `mem::MaybeUninit::zeroed` instead")]
518517
#[stable(feature = "rust1", since = "1.0.0")]
519518
pub unsafe fn zeroed<T>() -> T {
520519
intrinsics::init()
@@ -609,7 +608,6 @@ pub unsafe fn zeroed<T>() -> T {
609608
/// [copy_no]: ../intrinsics/fn.copy_nonoverlapping.html
610609
/// [`Drop`]: ../ops/trait.Drop.html
611610
#[inline]
612-
#[rustc_deprecated(since = "2.0.0", reason = "use `mem::MaybeUninit::uninitialized` instead")]
613611
#[stable(feature = "rust1", since = "1.0.0")]
614612
pub unsafe fn uninitialized<T>() -> T {
615613
intrinsics::uninit()
@@ -1026,97 +1024,3 @@ impl<T: ?Sized> DerefMut for ManuallyDrop<T> {
10261024
&mut self.value
10271025
}
10281026
}
1029-
1030-
/// A newtype to construct uninitialized instances of `T`
1031-
#[allow(missing_debug_implementations)]
1032-
#[unstable(feature = "maybe_uninit", issue = "53491")]
1033-
// NOTE after stabilizing `MaybeUninit` proceed to deprecate `mem::{uninitialized,zeroed}`
1034-
pub union MaybeUninit<T> {
1035-
uninit: (),
1036-
value: ManuallyDrop<T>,
1037-
}
1038-
1039-
impl<T> MaybeUninit<T> {
1040-
/// Create a new `MaybeUninit` in an uninitialized state.
1041-
///
1042-
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.
1043-
/// It is your responsibility to make sure `T` gets dropped if it got initialized.
1044-
#[unstable(feature = "maybe_uninit", issue = "53491")]
1045-
pub const fn uninitialized() -> MaybeUninit<T> {
1046-
MaybeUninit { uninit: () }
1047-
}
1048-
1049-
/// Create a new `MaybeUninit` in an uninitialized state, with the memory being
1050-
/// filled with `0` bytes. It depends on `T` whether that already makes for
1051-
/// proper initialization. For example, `MaybeUninit<usize>::zeroed()` is initialized,
1052-
/// but `MaybeUninit<&'static i32>::zeroed()` is not because references must not
1053-
/// be null.
1054-
///
1055-
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.
1056-
/// It is your responsibility to make sure `T` gets dropped if it got initialized.
1057-
#[unstable(feature = "maybe_uninit", issue = "53491")]
1058-
pub fn zeroed() -> MaybeUninit<T> {
1059-
let mut u = MaybeUninit::<T>::uninitialized();
1060-
unsafe {
1061-
u.as_mut_ptr().write_bytes(0u8, 1);
1062-
}
1063-
u
1064-
}
1065-
1066-
/// Set the value of the `MaybeUninit`. This overwrites any previous value without dropping it.
1067-
#[unstable(feature = "maybe_uninit", issue = "53491")]
1068-
pub fn set(&mut self, val: T) {
1069-
unsafe {
1070-
self.value = ManuallyDrop::new(val);
1071-
}
1072-
}
1073-
1074-
/// Extract the value from the `MaybeUninit` container. This is a great way
1075-
/// to ensure that the data will get dropped, because the resulting `T` is
1076-
/// subject to the usual drop handling.
1077-
///
1078-
/// # Unsafety
1079-
///
1080-
/// It is up to the caller to guarantee that the the `MaybeUninit` really is in an initialized
1081-
/// state, otherwise this will immediately cause undefined behavior.
1082-
#[unstable(feature = "maybe_uninit", issue = "53491")]
1083-
pub unsafe fn into_inner(self) -> T {
1084-
ManuallyDrop::into_inner(self.value)
1085-
}
1086-
1087-
/// Get a reference to the contained value.
1088-
///
1089-
/// # Unsafety
1090-
///
1091-
/// It is up to the caller to guarantee that the the `MaybeUninit` really is in an initialized
1092-
/// state, otherwise this will immediately cause undefined behavior.
1093-
#[unstable(feature = "maybe_uninit", issue = "53491")]
1094-
pub unsafe fn get_ref(&self) -> &T {
1095-
&*self.value
1096-
}
1097-
1098-
/// Get a mutable reference to the contained value.
1099-
///
1100-
/// # Unsafety
1101-
///
1102-
/// It is up to the caller to guarantee that the the `MaybeUninit` really is in an initialized
1103-
/// state, otherwise this will immediately cause undefined behavior.
1104-
#[unstable(feature = "maybe_uninit", issue = "53491")]
1105-
pub unsafe fn get_mut(&mut self) -> &mut T {
1106-
&mut *self.value
1107-
}
1108-
1109-
/// Get a pointer to the contained value. Reading from this pointer will be undefined
1110-
/// behavior unless the `MaybeUninit` is initialized.
1111-
#[unstable(feature = "maybe_uninit", issue = "53491")]
1112-
pub fn as_ptr(&self) -> *const T {
1113-
unsafe { &*self.value as *const T }
1114-
}
1115-
1116-
/// Get a mutable pointer to the contained value. Reading from this pointer will be undefined
1117-
/// behavior unless the `MaybeUninit` is initialized.
1118-
#[unstable(feature = "maybe_uninit", issue = "53491")]
1119-
pub fn as_mut_ptr(&mut self) -> *mut T {
1120-
unsafe { &mut *self.value as *mut T }
1121-
}
1122-
}

0 commit comments

Comments
 (0)