Skip to content

Commit 1119d33

Browse files
authored
Rollup merge of rust-lang#146846 - hkBst:btree-2, r=tgross35
btree InternalNode::new safety comments
2 parents b2866fc + 2dfcd09 commit 1119d33

File tree

1 file changed

+3
-2
lines changed
  • library/alloc/src/collections/btree

1 file changed

+3
-2
lines changed

library/alloc/src/collections/btree/node.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ impl<K, V> InternalNode<K, V> {
117117
/// initialized and valid edge. This function does not set up
118118
/// such an edge.
119119
unsafe fn new<A: Allocator + Clone>(alloc: A) -> Box<Self, A> {
120+
let mut node = Box::<Self, _>::new_uninit_in(alloc);
120121
unsafe {
121-
let mut node = Box::<Self, _>::new_uninit_in(alloc);
122-
// We only need to initialize the data; the edges are MaybeUninit.
122+
// SAFETY: argument points to the `node.data` `LeafNode`
123123
LeafNode::init(&raw mut (*node.as_mut_ptr()).data);
124+
// SAFETY: `node.data` was just initialized and `node.edges` is MaybeUninit.
124125
node.assume_init()
125126
}
126127
}

0 commit comments

Comments
 (0)