about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-06-17 16:10:57 +0000
committerbors <bors@rust-lang.org>2023-06-17 16:10:57 +0000
commit876a7d8d6fa1c18b8a652836b22f0d362784c685 (patch)
tree655fb751864af9e001c4d91a2a5893db34c9b66b
parent9176f51a9b67be197c5b8c9da3f5bf6eaf114f03 (diff)
parentec100514f892bcdd02780c7a2181ecc8b3cb3cd9 (diff)
downloadrust-876a7d8d6fa1c18b8a652836b22f0d362784c685.tar.gz
rust-876a7d8d6fa1c18b8a652836b22f0d362784c685.zip
Auto merge of #100036 - DrMeepster:box_free_free_box, r=oli-obk
Remove `box_free` lang item

This PR removes the `box_free` lang item, replacing it with `Box`'s `Drop` impl. Box dropping is still slightly magic because the contained value is still dropped by the compiler.
-rw-r--r--example/mini_core.rs8
1 files changed, 2 insertions, 6 deletions
diff --git a/example/mini_core.rs b/example/mini_core.rs
index 637b8dc53fe..c27b610f2ab 100644
--- a/example/mini_core.rs
+++ b/example/mini_core.rs
@@ -490,7 +490,8 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> fo
 
 impl<T: ?Sized, A: Allocator> Drop for Box<T, A> {
     fn drop(&mut self) {
-        // drop is currently performed by compiler.
+        // inner value is dropped by compiler
+        libc::free(self.pointer.0 as *mut u8);
     }
 }
 
@@ -507,11 +508,6 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
     libc::malloc(size)
 }
 
-#[lang = "box_free"]
-unsafe fn box_free<T: ?Sized>(ptr: Unique<T>, _alloc: ()) {
-    libc::free(ptr.pointer.0 as *mut u8);
-}
-
 #[lang = "drop"]
 pub trait Drop {
     fn drop(&mut self);