about summary refs log tree commit diff
path: root/src/liballoc/alloc.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-04-27 12:24:17 +0000
committerbors <bors@rust-lang.org>2018-04-27 12:24:17 +0000
commit71d3dac4a86d192c2c80948621859da3b363fa50 (patch)
tree4dd89c80c24cfe5f9aa0e1de1e46ed295be22e4d /src/liballoc/alloc.rs
parentada45fd49a2dfcf2a163e1f4641ac34f2803eb9b (diff)
parentbd8c177d49c95d94f163e9bb3c3397f38ab72640 (diff)
downloadrust-71d3dac4a86d192c2c80948621859da3b363fa50.tar.gz
rust-71d3dac4a86d192c2c80948621859da3b363fa50.zip
Auto merge of #50097 - glandium:box_free, r=nikomatsakis
Partial future-proofing for Box<T, A>

In some ways, this is similar to @eddyb's PR #47043 that went stale, but doesn't cover everything. Notably, this still leaves Box internalized as a pointer in places, so practically speaking, only ZSTs can be practically added to the Box type with the changes here (the compiler ICEs otherwise).

The Box type is not changed here, that's left for the future because I want to test that further first, but this puts things in place in a way that hopefully will make things easier.
Diffstat (limited to 'src/liballoc/alloc.rs')
-rw-r--r--src/liballoc/alloc.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs
index c0372d24ed5..f59c9f7fd61 100644
--- a/src/liballoc/alloc.rs
+++ b/src/liballoc/alloc.rs
@@ -16,7 +16,7 @@
             issue = "32838")]
 
 use core::intrinsics::{min_align_of_val, size_of_val};
-use core::ptr::NonNull;
+use core::ptr::{NonNull, Unique};
 use core::usize;
 
 #[doc(inline)]
@@ -152,9 +152,17 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
     }
 }
 
-#[cfg_attr(not(test), lang = "box_free")]
+#[cfg(stage0)]
+#[lang = "box_free"]
+#[inline]
+unsafe fn old_box_free<T: ?Sized>(ptr: *mut T) {
+    box_free(Unique::new_unchecked(ptr))
+}
+
+#[cfg_attr(not(any(test, stage0)), lang = "box_free")]
 #[inline]
-pub(crate) unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
+pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) {
+    let ptr = ptr.as_ptr();
     let size = size_of_val(&*ptr);
     let align = min_align_of_val(&*ptr);
     // We do not allocate for Box<T> when T is ZST, so deallocation is also not necessary.