@@ -30,7 +30,7 @@ use core::{
30
30
mem:: { ManuallyDrop , MaybeUninit } ,
31
31
ops:: { Deref , DerefMut } ,
32
32
pin:: Pin ,
33
- ptr:: { NonNull , Pointee } ,
33
+ ptr:: NonNull ,
34
34
} ;
35
35
use macros:: pin_data;
36
36
@@ -258,22 +258,20 @@ impl<T: ?Sized> Arc<T> {
258
258
// binary, so its layout is not so large that it can trigger arithmetic overflow.
259
259
let val_offset = unsafe { refcount_layout. extend ( val_layout) . unwrap_unchecked ( ) . 1 } ;
260
260
261
- let metadata: <T as Pointee >:: Metadata = core:: ptr:: metadata ( ptr) ;
262
- // SAFETY: The metadata of `T` and `ArcInner<T>` is the same because `ArcInner` is a struct
263
- // with `T` as its last field.
261
+ // Pointer casts leave the metadata unchanged. This is okay because the metadata of `T` and
262
+ // `ArcInner<T>` is the same since `ArcInner` is a struct with `T` as its last field.
264
263
//
265
264
// This is documented at:
266
265
// <https://doc.rust-lang.org/std/ptr/trait.Pointee.html>.
267
- let metadata : < ArcInner < T > as Pointee > :: Metadata =
268
- unsafe { core :: mem :: transmute_copy ( & metadata ) } ;
266
+ let ptr = ptr as * const ArcInner < T > ;
267
+
269
268
// SAFETY: The pointer is in-bounds of an allocation both before and after offsetting the
270
269
// pointer, since it originates from a previous call to `Arc::into_raw` and is still valid.
271
- let ptr = unsafe { ( ptr as * mut u8 ) . sub ( val_offset) as * mut ( ) } ;
272
- let ptr = core:: ptr:: from_raw_parts_mut ( ptr, metadata) ;
270
+ let ptr = unsafe { ptr. byte_sub ( val_offset) } ;
273
271
274
272
// SAFETY: By the safety requirements we know that `ptr` came from `Arc::into_raw`, so the
275
273
// reference count held then will be owned by the new `Arc` object.
276
- unsafe { Self :: from_inner ( NonNull :: new_unchecked ( ptr) ) }
274
+ unsafe { Self :: from_inner ( NonNull :: new_unchecked ( ptr. cast_mut ( ) ) ) }
277
275
}
278
276
279
277
/// Returns an [`ArcBorrow`] from the given [`Arc`].
0 commit comments