diff options
| author | bors <bors@rust-lang.org> | 2025-09-19 21:41:28 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-09-19 21:41:28 +0000 |
| commit | ec38671075266e9cee0348701da2e133379e7c6c (patch) | |
| tree | fc62fa32e29fc87285f63413758be4b5fe6f5ad7 /library/alloc/src | |
| parent | 0be8e16088894483a7012c5026c3247c14a0c3c2 (diff) | |
| parent | 6f9e6c9935a77e4ff2a732255b20b5270ef2a36d (diff) | |
Auto merge of #146797 - matthiaskrgr:rollup-xy0g8n7, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang/rust#146690 (add `[const] PartialEq` bound to `PartialOrd`) - rust-lang/rust#146776 (fixes for numerous clippy warnings) - rust-lang/rust#146777 (fix ./x readdir logic when CDPATH is set) - rust-lang/rust#146781 (mbe: Fix feature gate for `macro_derive`) - rust-lang/rust#146785 (btree: safety comments for init and new) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/collections/btree/node.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/library/alloc/src/collections/btree/node.rs b/library/alloc/src/collections/btree/node.rs index 37f784a322c..b233e1740b7 100644 --- a/library/alloc/src/collections/btree/node.rs +++ b/library/alloc/src/collections/btree/node.rs @@ -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. @@ -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() } } |
