Skip to content

Commit

Permalink
Rollup merge of #71589 - RalfJung:unique-no-shr, r=SimonSapin
Browse files Browse the repository at this point in the history
remove Unique::from for shared pointer types

r? @SimonSapin
  • Loading branch information
Dylan-DPC authored Apr 27, 2020
2 parents ac62dce + 7aebdb6 commit cddbed0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/liballoc/collections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>> {
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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);
}

Expand Down
17 changes: 0 additions & 17 deletions src/libcore/ptr/unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()) }
}
}

0 comments on commit cddbed0

Please sign in to comment.