Skip to content

Commit

Permalink
Rust 1.72 compat
Browse files Browse the repository at this point in the history
Signed-off-by: Asahi Lina <lina@asahilina.net>
  • Loading branch information
asahilina committed Sep 9, 2023
1 parent dee6928 commit 9c6bcb8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions rust/alloc/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
}
}

#[cfg(not(version("1.72")))]
#[cfg_attr(not(test), lang = "box_free")]
#[inline]
// This signature has to be the same as `Box`, otherwise an ICE will happen.
Expand Down
14 changes: 14 additions & 0 deletions rust/alloc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,9 +1217,23 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {

#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
#[cfg(not(version("1.72")))]
fn drop(&mut self) {
// FIXME: Do nothing, drop is currently performed by compiler.
}

#[cfg(version("1.72"))]
#[inline]
fn drop(&mut self) {
// the T in the Box is dropped by the compiler before the destructor is run

let ptr = self.0;

unsafe {
let layout = Layout::for_value_raw(ptr.as_ptr());
self.1.deallocate(From::from(ptr.cast()), layout)
}
}
}

#[cfg(not(no_global_oom_handling))]
Expand Down

0 comments on commit 9c6bcb8

Please sign in to comment.