@@ -279,6 +279,12 @@ impl<T: ?Sized> Arc<T> {
279
279
}
280
280
281
281
impl < T : ?Sized , A : Allocator > Arc < T , A > {
282
+ #[ inline]
283
+ fn internal_into_inner_with_allocator ( self ) -> ( NonNull < ArcInner < T > > , A ) {
284
+ let this = mem:: ManuallyDrop :: new ( self ) ;
285
+ ( this. ptr , unsafe { ptr:: read ( & this. alloc ) } )
286
+ }
287
+
282
288
#[ inline]
283
289
unsafe fn from_inner_in ( ptr : NonNull < ArcInner < T > > , alloc : A ) -> Self {
284
290
Self { ptr, phantom : PhantomData , alloc }
@@ -1271,12 +1277,9 @@ impl<T, A: Allocator> Arc<mem::MaybeUninit<T>, A> {
1271
1277
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
1272
1278
#[ must_use = "`self` will be dropped if the result is not used" ]
1273
1279
#[ inline]
1274
- pub unsafe fn assume_init ( self ) -> Arc < T , A >
1275
- where
1276
- A : Clone ,
1277
- {
1278
- let md_self = mem:: ManuallyDrop :: new ( self ) ;
1279
- unsafe { Arc :: from_inner_in ( md_self. ptr . cast ( ) , md_self. alloc . clone ( ) ) }
1280
+ pub unsafe fn assume_init ( self ) -> Arc < T , A > {
1281
+ let ( ptr, alloc) = self . internal_into_inner_with_allocator ( ) ;
1282
+ unsafe { Arc :: from_inner_in ( ptr. cast ( ) , alloc) }
1280
1283
}
1281
1284
}
1282
1285
@@ -1316,12 +1319,9 @@ impl<T, A: Allocator> Arc<[mem::MaybeUninit<T>], A> {
1316
1319
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
1317
1320
#[ must_use = "`self` will be dropped if the result is not used" ]
1318
1321
#[ inline]
1319
- pub unsafe fn assume_init ( self ) -> Arc < [ T ] , A >
1320
- where
1321
- A : Clone ,
1322
- {
1323
- let md_self = mem:: ManuallyDrop :: new ( self ) ;
1324
- unsafe { Arc :: from_ptr_in ( md_self. ptr . as_ptr ( ) as _ , md_self. alloc . clone ( ) ) }
1322
+ pub unsafe fn assume_init ( self ) -> Arc < [ T ] , A > {
1323
+ let ( ptr, alloc) = self . internal_into_inner_with_allocator ( ) ;
1324
+ unsafe { Arc :: from_ptr_in ( ptr. as_ptr ( ) as _ , alloc) }
1325
1325
}
1326
1326
}
1327
1327
@@ -2409,7 +2409,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Arc<T, A> {
2409
2409
}
2410
2410
}
2411
2411
2412
- impl < A : Allocator + Clone > Arc < dyn Any + Send + Sync , A > {
2412
+ impl < A : Allocator > Arc < dyn Any + Send + Sync , A > {
2413
2413
/// Attempt to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type.
2414
2414
///
2415
2415
/// # Examples
@@ -2436,10 +2436,8 @@ impl<A: Allocator + Clone> Arc<dyn Any + Send + Sync, A> {
2436
2436
{
2437
2437
if ( * self ) . is :: < T > ( ) {
2438
2438
unsafe {
2439
- let ptr = self . ptr . cast :: < ArcInner < T > > ( ) ;
2440
- let alloc = self . alloc . clone ( ) ;
2441
- mem:: forget ( self ) ;
2442
- Ok ( Arc :: from_inner_in ( ptr, alloc) )
2439
+ let ( ptr, alloc) = self . internal_into_inner_with_allocator ( ) ;
2440
+ Ok ( Arc :: from_inner_in ( ptr. cast ( ) , alloc) )
2443
2441
}
2444
2442
} else {
2445
2443
Err ( self )
@@ -2479,10 +2477,8 @@ impl<A: Allocator + Clone> Arc<dyn Any + Send + Sync, A> {
2479
2477
T : Any + Send + Sync ,
2480
2478
{
2481
2479
unsafe {
2482
- let ptr = self . ptr . cast :: < ArcInner < T > > ( ) ;
2483
- let alloc = self . alloc . clone ( ) ;
2484
- mem:: forget ( self ) ;
2485
- Arc :: from_inner_in ( ptr, alloc)
2480
+ let ( ptr, alloc) = self . internal_into_inner_with_allocator ( ) ;
2481
+ Arc :: from_inner_in ( ptr. cast ( ) , alloc)
2486
2482
}
2487
2483
}
2488
2484
}
@@ -3443,8 +3439,8 @@ impl<T, A: Allocator + Clone, const N: usize> TryFrom<Arc<[T], A>> for Arc<[T; N
3443
3439
3444
3440
fn try_from ( boxed_slice : Arc < [ T ] , A > ) -> Result < Self , Self :: Error > {
3445
3441
if boxed_slice. len ( ) == N {
3446
- let alloc = boxed_slice. alloc . clone ( ) ;
3447
- Ok ( unsafe { Arc :: from_raw_in ( Arc :: into_raw ( boxed_slice ) as * mut [ T ; N ] , alloc) } )
3442
+ let ( ptr , alloc) = boxed_slice. internal_into_inner_with_allocator ( ) ;
3443
+ Ok ( unsafe { Arc :: from_inner_in ( ptr . cast ( ) , alloc) } )
3448
3444
} else {
3449
3445
Err ( boxed_slice)
3450
3446
}
0 commit comments