Rollup merge of #71589 - RalfJung:unique-no-shr, r=SimonSapin

remove Unique::from for shared pointer types

r? @SimonSapin
This commit is contained in:
Dylan DPC 2020-04-27 03:26:18 +02:00 committed by GitHub
commit cddbed0003
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 20 deletions

View File

@ -131,7 +131,7 @@ impl<K, V> BoxedNode<K, V> {
}
unsafe fn from_ptr(ptr: NonNull<LeafNode<K, V>>) -> Self {
BoxedNode { ptr: Unique::from(ptr) }
BoxedNode { ptr: Unique::new_unchecked(ptr.as_ptr()) }
}
fn as_ptr(&self) -> NonNull<LeafNode<K, V>> {

View File

@ -151,7 +151,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
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<T, A: AllocRef> RawVec<T, A> {
}
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);
}

View File

@ -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<T: ?Sized> From<&mut T> for Unique<T> {
unsafe { Unique { pointer: reference as *mut T, _marker: PhantomData } }
}
}
#[unstable(feature = "ptr_internals", issue = "none")]
impl<T: ?Sized> From<&T> for Unique<T> {
#[inline]
fn from(reference: &T) -> Self {
unsafe { Unique { pointer: reference as *const T, _marker: PhantomData } }
}
}
#[unstable(feature = "ptr_internals", issue = "none")]
impl<T: ?Sized> From<NonNull<T>> for Unique<T> {
#[inline]
fn from(p: NonNull<T>) -> Self {
unsafe { Unique::new_unchecked(p.as_ptr()) }
}
}