From: Tim Diekmann Date: Wed, 25 Mar 2020 17:26:38 +0000 (+0100) Subject: Use `NonNull` instead of `Unique` in `MemoryBlock` X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=2f215b61b6368dad7b10295267a8f1a5a1bfafe8;p=rust.git Use `NonNull` instead of `Unique` in `MemoryBlock` --- 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.