Skip to content

Commit 77166d0

Browse files
committed
Rust 1.72 compat
Signed-off-by: Asahi Lina <[email protected]>
1 parent dee6928 commit 77166d0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

rust/alloc/alloc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
329329
}
330330
}
331331

332+
#[cfg(not(version("1.72")))]
332333
#[cfg_attr(not(test), lang = "box_free")]
333334
#[inline]
334335
// This signature has to be the same as `Box`, otherwise an ICE will happen.

rust/alloc/boxed.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,9 +1217,23 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12171217

12181218
#[stable(feature = "rust1", since = "1.0.0")]
12191219
unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
1220+
#[cfg(not(version("1.71")))]
12201221
fn drop(&mut self) {
12211222
// FIXME: Do nothing, drop is currently performed by compiler.
12221223
}
1224+
1225+
#[cfg(version("1.71"))]
1226+
#[inline]
1227+
fn drop(&mut self) {
1228+
// the T in the Box is dropped by the compiler before the destructor is run
1229+
1230+
let ptr = self.0;
1231+
1232+
unsafe {
1233+
let layout = Layout::for_value_raw(ptr.as_ptr());
1234+
self.1.deallocate(From::from(ptr.cast()), layout)
1235+
}
1236+
}
12231237
}
12241238

12251239
#[cfg(not(no_global_oom_handling))]

0 commit comments

Comments
 (0)