From 7aebdb639ade703a2a9f55a83df21a79fbbd9f69 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 26 Apr 2020 19:00:57 +0200 Subject: [PATCH] remove Unique::from for shared pointer types --- src/liballoc/collections/btree/node.rs | 2 +- src/liballoc/raw_vec.rs | 4 ++-- src/libcore/ptr/unique.rs | 17 ----------------- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs index 84d34db2d45..5569c293e2f 100644 --- a/src/liballoc/collections/btree/node.rs +++ b/src/liballoc/collections/btree/node.rs @@ -131,7 +131,7 @@ impl BoxedNode { } unsafe fn from_ptr(ptr: NonNull>) -> Self { - BoxedNode { ptr: Unique::from(ptr) } + BoxedNode { ptr: Unique::new_unchecked(ptr.as_ptr()) } } fn as_ptr(&self) -> NonNull> { diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index 0780b33e53a..ca165b61e26 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -151,7 +151,7 @@ impl RawVec { let memory = alloc.alloc(layout, init).unwrap_or_else(|_| handle_alloc_error(layout)); Self { - ptr: memory.ptr.cast().into(), + ptr: unsafe { Unique::new_unchecked(memory.ptr.cast().as_ptr()) }, cap: Self::capacity_from_bytes(memory.size), alloc, } @@ -469,7 +469,7 @@ impl RawVec { } fn set_memory(&mut self, memory: MemoryBlock) { - self.ptr = memory.ptr.cast().into(); + self.ptr = unsafe { Unique::new_unchecked(memory.ptr.cast().as_ptr()) }; self.cap = Self::capacity_from_bytes(memory.size); } diff --git a/src/libcore/ptr/unique.rs b/src/libcore/ptr/unique.rs index 87b56d951c6..d93dc1f3262 100644 --- a/src/libcore/ptr/unique.rs +++ b/src/libcore/ptr/unique.rs @@ -3,7 +3,6 @@ use crate::fmt; use crate::marker::{PhantomData, Unsize}; use crate::mem; use crate::ops::{CoerceUnsized, DispatchFromDyn}; -use crate::ptr::NonNull; // ignore-tidy-undocumented-unsafe @@ -171,19 +170,3 @@ impl From<&mut T> for Unique { unsafe { Unique { pointer: reference as *mut T, _marker: PhantomData } } } } - -#[unstable(feature = "ptr_internals", issue = "none")] -impl From<&T> for Unique { - #[inline] - fn from(reference: &T) -> Self { - unsafe { Unique { pointer: reference as *const T, _marker: PhantomData } } - } -} - -#[unstable(feature = "ptr_internals", issue = "none")] -impl From> for Unique { - #[inline] - fn from(p: NonNull) -> Self { - unsafe { Unique::new_unchecked(p.as_ptr()) } - } -}