diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2018-03-23 09:27:06 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-03-23 09:27:06 -0500 |
| commit | 7cf4cb5a7be38fcb3831204eb32ad6e2ef0a9e25 (patch) | |
| tree | 9997fb91ff9e2a46755aabf8fb2ae2c141eae380 /src/liballoc | |
| parent | 55e1104dd918a809d2751d325c11d59c85485a2e (diff) | |
| parent | a23f685296b2edd59acc998411340184b958ec82 (diff) | |
| download | rust-7cf4cb5a7be38fcb3831204eb32ad6e2ef0a9e25.tar.gz rust-7cf4cb5a7be38fcb3831204eb32ad6e2ef0a9e25.zip | |
Rollup merge of #48265 - SimonSapin:nonzero, r=KodrAus
Add 12 num::NonZero* types for primitive integers, deprecate core::nonzero RFC: https://github.com/rust-lang/rfcs/pull/2307 Tracking issue: ~~https://github.com/rust-lang/rust/issues/27730~~ https://github.com/rust-lang/rust/issues/49137 Fixes https://github.com/rust-lang/rust/issues/27730
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/btree/node.rs | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/liballoc/btree/node.rs b/src/liballoc/btree/node.rs index c1618043ce6..464f8f2f4ec 100644 --- a/src/liballoc/btree/node.rs +++ b/src/liballoc/btree/node.rs @@ -43,8 +43,7 @@ use core::marker::PhantomData; use core::mem; -use core::nonzero::NonZero; -use core::ptr::{self, Unique}; +use core::ptr::{self, Unique, NonNull}; use core::slice; use boxed::Box; @@ -149,14 +148,12 @@ impl<K, V> BoxedNode<K, V> { } } - unsafe fn from_ptr(ptr: NonZero<*const LeafNode<K, V>>) -> Self { - BoxedNode { ptr: Unique::new_unchecked(ptr.get() as *mut LeafNode<K, V>) } + unsafe fn from_ptr(ptr: NonNull<LeafNode<K, V>>) -> Self { + BoxedNode { ptr: Unique::from(ptr) } } - fn as_ptr(&self) -> NonZero<*const LeafNode<K, V>> { - unsafe { - NonZero::from(self.ptr.as_ref()) - } + fn as_ptr(&self) -> NonNull<LeafNode<K, V>> { + NonNull::from(self.ptr) } } @@ -276,7 +273,7 @@ impl<K, V> Root<K, V> { /// `NodeRef` could be pointing to either type of node. pub struct NodeRef<BorrowType, K, V, Type> { height: usize, - node: NonZero<*const LeafNode<K, V>>, + node: NonNull<LeafNode<K, V>>, // This is null unless the borrow type is `Mut` root: *const Root<K, V>, _marker: PhantomData<(BorrowType, Type)> @@ -302,7 +299,7 @@ unsafe impl<K: Send, V: Send, Type> Send impl<BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Internal> { fn as_internal(&self) -> &InternalNode<K, V> { unsafe { - &*(self.node.get() as *const InternalNode<K, V>) + &*(self.node.as_ptr() as *mut InternalNode<K, V>) } } } @@ -310,7 +307,7 @@ impl<BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Internal> { impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> { fn as_internal_mut(&mut self) -> &mut InternalNode<K, V> { unsafe { - &mut *(self.node.get() as *mut InternalNode<K, V>) + &mut *(self.node.as_ptr() as *mut InternalNode<K, V>) } } } @@ -352,7 +349,7 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> { fn as_leaf(&self) -> &LeafNode<K, V> { unsafe { - &*self.node.get() + self.node.as_ref() } } @@ -382,7 +379,8 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> { >, Self > { - if let Some(non_zero) = NonZero::new(self.as_leaf().parent as *const LeafNode<K, V>) { + let parent_as_leaf = self.as_leaf().parent as *const LeafNode<K, V>; + if let Some(non_zero) = NonNull::new(parent_as_leaf as *mut _) { Ok(Handle { node: NodeRef { height: self.height + 1, @@ -498,7 +496,7 @@ impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> { fn as_leaf_mut(&mut self) -> &mut LeafNode<K, V> { unsafe { - &mut *(self.node.get() as *mut LeafNode<K, V>) + self.node.as_mut() } } @@ -1241,12 +1239,12 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker:: } Heap.dealloc( - right_node.node.get() as *mut u8, + right_node.node.as_ptr() as *mut u8, Layout::new::<InternalNode<K, V>>(), ); } else { Heap.dealloc( - right_node.node.get() as *mut u8, + right_node.node.as_ptr() as *mut u8, Layout::new::<LeafNode<K, V>>(), ); } |
