From 2f215b61b6368dad7b10295267a8f1a5a1bfafe8 Mon Sep 17 00:00:00 2001 From: Tim Diekmann Date: Wed, 25 Mar 2020 18:26:38 +0100 Subject: [PATCH] Use `NonNull` instead of `Unique` in `MemoryBlock` --- src/libcore/alloc/mod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libcore/alloc/mod.rs b/src/libcore/alloc/mod.rs index e693f50846b..4af1a8254a3 100644 --- a/src/libcore/alloc/mod.rs +++ b/src/libcore/alloc/mod.rs @@ -47,7 +47,7 @@ pub enum AllocInit { #[unstable(feature = "allocator_api", issue = "32838")] #[must_use = "`MemoryBlock` should be passed to `AllocRef::dealloc`"] pub struct MemoryBlock { - ptr: Unique, + ptr: NonNull, layout: Layout, } @@ -63,15 +63,14 @@ impl MemoryBlock { #[inline] #[unstable(feature = "allocator_api", issue = "32838")] pub const unsafe fn new(ptr: NonNull, layout: Layout) -> Self { - Self { ptr: Unique::new_unchecked(ptr.as_ptr()), layout } + Self { ptr, layout } } /// Acquires the underlying `NonNull` pointer. #[inline] #[unstable(feature = "allocator_api", issue = "32838")] pub const fn ptr(&self) -> NonNull { - // SAFETY: Unique is always non-null - unsafe { NonNull::new_unchecked(self.ptr.as_ptr()) } + self.ptr } /// Returns the layout describing the memory block. -- 2.44.0