about summary refs log tree commit diff
path: root/src/libcore/alloc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-04-23 18:36:59 +0000
committerbors <bors@rust-lang.org>2020-04-23 18:36:59 +0000
commit14b15521c52549ebbb113173b4abecd124b5a823 (patch)
tree5e5d52670664d8541e938acf9b390aad4c8a341e /src/libcore/alloc
parent413a12909f3b149af17d75268ed4a136afb82c36 (diff)
parentb107eb5ea4bdf1bc3f6ce7637a9d1980f8045117 (diff)
downloadrust-14b15521c52549ebbb113173b4abecd124b5a823.tar.gz
rust-14b15521c52549ebbb113173b4abecd124b5a823.zip
Auto merge of #71483 - Dylan-DPC:rollup-c2h9s8b, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #70633 (Confusing suggestion on incorrect closing `}`)
 - #71404 (Don't fuse Chain in its second iterator)
 - #71408 (Check code blocks tags)
 - #71442 (Add a "by reference" adaptor for `AllocRef`)
 - #71446 (Only use read_unaligned in transmute_copy if necessary)
 - #71470 (Fix doc links)
 - #71479 (add back Scalar::null_ptr)

Failed merges:

r? @ghost
Diffstat (limited to 'src/libcore/alloc')
-rw-r--r--src/libcore/alloc/mod.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/libcore/alloc/mod.rs b/src/libcore/alloc/mod.rs
index 86a6fa7f8ba..1346fbd4810 100644
--- a/src/libcore/alloc/mod.rs
+++ b/src/libcore/alloc/mod.rs
@@ -364,4 +364,51 @@ pub unsafe trait AllocRef {
             }
         }
     }
+
+    /// Creates a "by reference" adaptor for this instance of `AllocRef`.
+    ///
+    /// The returned adaptor also implements `AllocRef` and will simply borrow this.
+    #[inline(always)]
+    fn by_ref(&mut self) -> &mut Self {
+        self
+    }
+}
+
+#[unstable(feature = "allocator_api", issue = "32838")]
+unsafe impl<A> AllocRef for &mut A
+where
+    A: AllocRef + ?Sized,
+{
+    #[inline]
+    fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocErr> {
+        (**self).alloc(layout, init)
+    }
+
+    #[inline]
+    unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
+        (**self).dealloc(ptr, layout)
+    }
+
+    #[inline]
+    unsafe fn grow(
+        &mut self,
+        ptr: NonNull<u8>,
+        layout: Layout,
+        new_size: usize,
+        placement: ReallocPlacement,
+        init: AllocInit,
+    ) -> Result<MemoryBlock, AllocErr> {
+        (**self).grow(ptr, layout, new_size, placement, init)
+    }
+
+    #[inline]
+    unsafe fn shrink(
+        &mut self,
+        ptr: NonNull<u8>,
+        layout: Layout,
+        new_size: usize,
+        placement: ReallocPlacement,
+    ) -> Result<MemoryBlock, AllocErr> {
+        (**self).shrink(ptr, layout, new_size, placement)
+    }
 }