From fd6548ee0cf94d1629e616d78ab99c2b374abe37 Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Mon, 15 Feb 2021 02:36:48 -0500 Subject: [PATCH] Implement `Allocator` for `!` Useful to represent situations where something will never actually allocate, such as immutable version of a copy-on-write type. --- library/core/src/alloc/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 06a761531b676..4946d140d4cc6 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -404,3 +404,16 @@ where unsafe { (**self).shrink(ptr, old_layout, new_layout) } } } + +#[unstable(feature = "allocator_api", issue = "32838")] +unsafe impl Allocator for ! { + #[inline] + fn allocate(&self, _: Layout) -> Result, AllocError> { + *self + } + + #[inline] + unsafe fn deallocate(&self, _: NonNull, _: Layout) { + *self + } +}