Skip to content

Commit 938552a

Browse files
committed
Use checked NonZero constructor instead of explicit null check in btree
1 parent a4edae9 commit 938552a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/liballoc/btree/node.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,21 +382,19 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
382382
>,
383383
Self
384384
> {
385-
if self.as_leaf().parent.is_null() {
386-
Err(self)
387-
} else {
385+
if let Some(non_zero) = NonZero::new(self.as_leaf().parent as *const LeafNode<K, V>) {
388386
Ok(Handle {
389387
node: NodeRef {
390388
height: self.height + 1,
391-
node: unsafe {
392-
NonZero::new_unchecked(self.as_leaf().parent as *mut LeafNode<K, V>)
393-
},
389+
node: non_zero,
394390
root: self.root,
395391
_marker: PhantomData
396392
},
397393
idx: self.as_leaf().parent_idx as usize,
398394
_marker: PhantomData
399395
})
396+
} else {
397+
Err(self)
400398
}
401399
}
402400

0 commit comments

Comments
 (0)