Skip to content

Commit 27929b0

Browse files
authored
Rollup merge of rust-lang#59284 - RalfJung:maybe-uninit, r=sfackler
adjust MaybeUninit API to discussions uninitialized -> uninit into_initialized -> assume_init read_initialized -> read set -> write
2 parents 0f46923 + 853ae8d commit 27929b0

File tree

12 files changed

+110
-73
lines changed

12 files changed

+110
-73
lines changed

src/liballoc/collections/btree/node.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<K, V> LeafNode<K, V> {
109109
keys: uninitialized_array![_; CAPACITY],
110110
vals: uninitialized_array![_; CAPACITY],
111111
parent: ptr::null(),
112-
parent_idx: MaybeUninit::uninitialized(),
112+
parent_idx: MaybeUninit::uninit(),
113113
len: 0
114114
}
115115
}
@@ -129,7 +129,7 @@ unsafe impl Sync for NodeHeader<(), ()> {}
129129
// ever take a pointer past the first key.
130130
static EMPTY_ROOT_NODE: NodeHeader<(), ()> = NodeHeader {
131131
parent: ptr::null(),
132-
parent_idx: MaybeUninit::uninitialized(),
132+
parent_idx: MaybeUninit::uninit(),
133133
len: 0,
134134
keys_start: [],
135135
};
@@ -261,7 +261,7 @@ impl<K, V> Root<K, V> {
261261
-> NodeRef<marker::Mut<'_>, K, V, marker::Internal> {
262262
debug_assert!(!self.is_shared_root());
263263
let mut new_node = Box::new(unsafe { InternalNode::new() });
264-
new_node.edges[0].set(unsafe { BoxedNode::from_ptr(self.node.as_ptr()) });
264+
new_node.edges[0].write(unsafe { BoxedNode::from_ptr(self.node.as_ptr()) });
265265

266266
self.node = BoxedNode::from_internal(new_node);
267267
self.height += 1;
@@ -737,7 +737,7 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
737737
unsafe {
738738
ptr::write(self.keys_mut().get_unchecked_mut(idx), key);
739739
ptr::write(self.vals_mut().get_unchecked_mut(idx), val);
740-
self.as_internal_mut().edges.get_unchecked_mut(idx + 1).set(edge.node);
740+
self.as_internal_mut().edges.get_unchecked_mut(idx + 1).write(edge.node);
741741

742742
(*self.as_leaf_mut()).len += 1;
743743

@@ -1080,7 +1080,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
10801080
let mut child = self.descend();
10811081
unsafe {
10821082
(*child.as_leaf_mut()).parent = ptr;
1083-
(*child.as_leaf_mut()).parent_idx.set(idx);
1083+
(*child.as_leaf_mut()).parent_idx.write(idx);
10841084
}
10851085
}
10861086

src/libcore/fmt/float.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter, num: &T,
1010
where T: flt2dec::DecodableFloat
1111
{
1212
unsafe {
13-
let mut buf = MaybeUninit::<[u8; 1024]>::uninitialized(); // enough for f32 and f64
14-
let mut parts = MaybeUninit::<[flt2dec::Part; 4]>::uninitialized();
13+
let mut buf = MaybeUninit::<[u8; 1024]>::uninit(); // enough for f32 and f64
14+
let mut parts = MaybeUninit::<[flt2dec::Part; 4]>::uninit();
1515
// FIXME(#53491): Technically, this is calling `get_mut` on an uninitialized
1616
// `MaybeUninit` (here and elsewhere in this file). Revisit this once
1717
// we decided whether that is valid or not.
@@ -32,8 +32,8 @@ fn float_to_decimal_common_shortest<T>(fmt: &mut Formatter, num: &T,
3232
{
3333
unsafe {
3434
// enough for f32 and f64
35-
let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninitialized();
36-
let mut parts = MaybeUninit::<[flt2dec::Part; 4]>::uninitialized();
35+
let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninit();
36+
let mut parts = MaybeUninit::<[flt2dec::Part; 4]>::uninit();
3737
// FIXME(#53491)
3838
let formatted = flt2dec::to_shortest_str(flt2dec::strategy::grisu::format_shortest, *num,
3939
sign, precision, false, buf.get_mut(),
@@ -71,8 +71,8 @@ fn float_to_exponential_common_exact<T>(fmt: &mut Formatter, num: &T,
7171
where T: flt2dec::DecodableFloat
7272
{
7373
unsafe {
74-
let mut buf = MaybeUninit::<[u8; 1024]>::uninitialized(); // enough for f32 and f64
75-
let mut parts = MaybeUninit::<[flt2dec::Part; 6]>::uninitialized();
74+
let mut buf = MaybeUninit::<[u8; 1024]>::uninit(); // enough for f32 and f64
75+
let mut parts = MaybeUninit::<[flt2dec::Part; 6]>::uninit();
7676
// FIXME(#53491)
7777
let formatted = flt2dec::to_exact_exp_str(flt2dec::strategy::grisu::format_exact,
7878
*num, sign, precision,
@@ -91,8 +91,8 @@ fn float_to_exponential_common_shortest<T>(fmt: &mut Formatter,
9191
{
9292
unsafe {
9393
// enough for f32 and f64
94-
let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninitialized();
95-
let mut parts = MaybeUninit::<[flt2dec::Part; 6]>::uninitialized();
94+
let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninit();
95+
let mut parts = MaybeUninit::<[flt2dec::Part; 6]>::uninit();
9696
// FIXME(#53491)
9797
let formatted = flt2dec::to_shortest_exp_str(flt2dec::strategy::grisu::format_shortest,
9898
*num, sign, (0, 0), upper,

src/libcore/fmt/num.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ trait GenericRadix {
6060
for byte in buf.iter_mut().rev() {
6161
let n = x % base; // Get the current place value.
6262
x = x / base; // Deaccumulate the number.
63-
byte.set(Self::digit(n.to_u8())); // Store the digit in the buffer.
63+
byte.write(Self::digit(n.to_u8())); // Store the digit in the buffer.
6464
curr -= 1;
6565
if x == zero {
6666
// No more digits left to accumulate.
@@ -72,7 +72,7 @@ trait GenericRadix {
7272
for byte in buf.iter_mut().rev() {
7373
let n = zero - (x % base); // Get the current place value.
7474
x = x / base; // Deaccumulate the number.
75-
byte.set(Self::digit(n.to_u8())); // Store the digit in the buffer.
75+
byte.write(Self::digit(n.to_u8())); // Store the digit in the buffer.
7676
curr -= 1;
7777
if x == zero {
7878
// No more digits left to accumulate.

src/libcore/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,12 @@ macro_rules! todo {
626626
#[macro_export]
627627
#[unstable(feature = "maybe_uninit_array", issue = "53491")]
628628
macro_rules! uninitialized_array {
629-
// This `into_initialized` is safe because an array of `MaybeUninit` does not
629+
// This `assume_init` is safe because an array of `MaybeUninit` does not
630630
// require initialization.
631631
// FIXME(#49147): Could be replaced by an array initializer, once those can
632632
// be any const expression.
633633
($t:ty; $size:expr) => (unsafe {
634-
MaybeUninit::<[MaybeUninit<$t>; $size]>::uninitialized().into_initialized()
634+
MaybeUninit::<[MaybeUninit<$t>; $size]>::uninit().assume_init()
635635
});
636636
}
637637

0 commit comments

Comments
 (0)