diff options
| author | bors <bors@rust-lang.org> | 2020-04-23 18:36:59 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-04-23 18:36:59 +0000 |
| commit | 14b15521c52549ebbb113173b4abecd124b5a823 (patch) | |
| tree | 5e5d52670664d8541e938acf9b390aad4c8a341e /src/libcore/alloc | |
| parent | 413a12909f3b149af17d75268ed4a136afb82c36 (diff) | |
| parent | b107eb5ea4bdf1bc3f6ce7637a9d1980f8045117 (diff) | |
| download | rust-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.rs | 47 |
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) + } } |
