]> git.lizzy.rs Git - rust.git/commitdiff
Use `NonNull` instead of `Unique` in `MemoryBlock`
authorTim Diekmann <tim.diekmann@3dvision.de>
Wed, 25 Mar 2020 17:26:38 +0000 (18:26 +0100)
committerTim Diekmann <tim.diekmann@3dvision.de>
Thu, 26 Mar 2020 16:12:12 +0000 (17:12 +0100)
src/libcore/alloc/mod.rs

index e693f50846bdbb2b27c8d43bf4c0a93be266fb33..4af1a8254a3dbb6a5344dc718b1ca57364a13bfc 100644 (file)
@@ -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<u8>,
+    ptr: NonNull<u8>,
     layout: Layout,
 }
 
@@ -63,15 +63,14 @@ impl MemoryBlock {
     #[inline]
     #[unstable(feature = "allocator_api", issue = "32838")]
     pub const unsafe fn new(ptr: NonNull<u8>, layout: Layout) -> Self {
-        Self { ptr: Unique::new_unchecked(ptr.as_ptr()), layout }
+        Self { ptr, layout }
     }
 
     /// Acquires the underlying `NonNull<u8>` pointer.
     #[inline]
     #[unstable(feature = "allocator_api", issue = "32838")]
     pub const fn ptr(&self) -> NonNull<u8> {
-        // SAFETY: Unique<T> is always non-null
-        unsafe { NonNull::new_unchecked(self.ptr.as_ptr()) }
+        self.ptr
     }
 
     /// Returns the layout describing the memory block.