Skip to content

Commit 0a4d8da

Browse files
hoshinolinamarcan
authored andcommitted
Rust 1.72 compat
Signed-off-by: Asahi Lina <[email protected]>
1 parent fbfeca1 commit 0a4d8da

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

rust/alloc/alloc.rs

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

342+
#[cfg(not(version("1.72")))]
342343
#[cfg_attr(not(test), lang = "box_free")]
343344
#[inline]
344345
// 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
@@ -1215,9 +1215,23 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12151215

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

12231237
#[cfg(not(no_global_oom_handling))]

rust/alloc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
#![feature(ascii_char)]
107107
#![feature(assert_matches)]
108108
#![feature(async_iterator)]
109+
#![feature(cfg_version)]
109110
#![feature(coerce_unsized)]
110111
#![feature(const_align_of_val)]
111112
#![feature(const_box)]

0 commit comments

Comments
 (0)