Skip to content

Commit a3fe31f

Browse files
Darksonnfbq
authored andcommitted
rust: stop using ptr_metadata feature
The `byte_sub` method was stabilized in Rust 1.75.0. By using that method, we no longer need the unstable `ptr_metadata` feature for implementing `Arc::from_raw`. This brings us one step closer towards not using unstable compiler features. Signed-off-by: Alice Ryhl <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 69b901c commit a3fe31f

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

rust/kernel/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#![feature(dispatch_from_dyn)]
1818
#![feature(new_uninit)]
1919
#![feature(offset_of)]
20-
#![feature(ptr_metadata)]
2120
#![feature(receiver_trait)]
2221
#![feature(unsize)]
2322

rust/kernel/sync/arc.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use core::{
3030
mem::{ManuallyDrop, MaybeUninit},
3131
ops::{Deref, DerefMut},
3232
pin::Pin,
33-
ptr::{NonNull, Pointee},
33+
ptr::NonNull,
3434
};
3535
use macros::pin_data;
3636

@@ -239,18 +239,16 @@ impl<T: ?Sized> Arc<T> {
239239
// binary, so its layout is not so large that it can trigger arithmetic overflow.
240240
let val_offset = unsafe { refcount_layout.extend(val_layout).unwrap_unchecked().1 };
241241

242-
let metadata: <T as Pointee>::Metadata = core::ptr::metadata(ptr);
243242
// SAFETY: The metadata of `T` and `ArcInner<T>` is the same because `ArcInner` is a struct
244243
// with `T` as its last field.
245244
//
246245
// This is documented at:
247246
// <https://doc.rust-lang.org/std/ptr/trait.Pointee.html>.
248-
let metadata: <ArcInner<T> as Pointee>::Metadata =
249-
unsafe { core::mem::transmute_copy(&metadata) };
247+
let ptr = ptr as *mut ArcInner<T>;
248+
250249
// SAFETY: The pointer is in-bounds of an allocation both before and after offsetting the
251250
// pointer, since it originates from a previous call to `Arc::into_raw` and is still valid.
252-
let ptr = unsafe { (ptr as *mut u8).sub(val_offset) as *mut () };
253-
let ptr = core::ptr::from_raw_parts_mut(ptr, metadata);
251+
let ptr = unsafe { ptr.byte_sub(val_offset) };
254252

255253
// SAFETY: By the safety requirements we know that `ptr` came from `Arc::into_raw`, so the
256254
// reference count held then will be owned by the new `Arc` object.

0 commit comments

Comments
 (0)