Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion library/alloc/src/collections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ struct LeafNode<K, V> {

impl<K, V> LeafNode<K, V> {
/// Initializes a new `LeafNode` in-place.
///
/// # Safety
///
/// The caller must ensure that `this` points to a (possibly uninitialized) `LeafNode`
unsafe fn init(this: *mut Self) {
// 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.
Expand All @@ -79,9 +83,11 @@ impl<K, V> LeafNode<K, V> {

/// Creates a new boxed `LeafNode`.
fn new<A: Allocator + Clone>(alloc: A) -> Box<Self, A> {
let mut leaf = Box::new_uninit_in(alloc);
unsafe {
let mut leaf = Box::new_uninit_in(alloc);
// SAFETY: `leaf` points to a `LeafNode`
LeafNode::init(leaf.as_mut_ptr());
// SAFETY: `leaf` was just initialized
leaf.assume_init()
}
}
Expand Down
Loading