Skip to content

Commit

Permalink
Auto merge of #100036 - DrMeepster:box_free_free_box, r=oli-obk
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jun 17, 2023
2 parents 9176f51 + ec10051 commit 876a7d8
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
Expand Down

0 comments on commit 876a7d8

Please sign in to comment.