@@ -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 }
@@ -1275,12 +1281,9 @@ impl<T, A: Allocator> Arc<mem::MaybeUninit<T>, A> {
1275
1281
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
1276
1282
#[ must_use = "`self` will be dropped if the result is not used" ]
1277
1283
#[ inline]
1278
- pub unsafe fn assume_init ( self ) -> Arc < T , A >
1279
- where
1280
- A : Clone ,
1281
- {
1282
- let md_self = mem:: ManuallyDrop :: new ( self ) ;
1283
- unsafe { Arc :: from_inner_in ( md_self. ptr . cast ( ) , md_self. alloc . clone ( ) ) }
1284
+ pub unsafe fn assume_init ( self ) -> Arc < T , A > {
1285
+ let ( ptr, alloc) = self . internal_into_inner_with_allocator ( ) ;
1286
+ unsafe { Arc :: from_inner_in ( ptr. cast ( ) , alloc) }
1284
1287
}
1285
1288
}
1286
1289
@@ -1320,12 +1323,9 @@ impl<T, A: Allocator> Arc<[mem::MaybeUninit<T>], A> {
1320
1323
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
1321
1324
#[ must_use = "`self` will be dropped if the result is not used" ]
1322
1325
#[ inline]
1323
- pub unsafe fn assume_init ( self ) -> Arc < [ T ] , A >
1324
- where
1325
- A : Clone ,
1326
- {
1327
- let md_self = mem:: ManuallyDrop :: new ( self ) ;
1328
- unsafe { Arc :: from_ptr_in ( md_self. ptr . as_ptr ( ) as _ , md_self. alloc . clone ( ) ) }
1326
+ pub unsafe fn assume_init ( self ) -> Arc < [ T ] , A > {
1327
+ let ( ptr, alloc) = self . internal_into_inner_with_allocator ( ) ;
1328
+ unsafe { Arc :: from_ptr_in ( ptr. as_ptr ( ) as _ , alloc) }
1329
1329
}
1330
1330
}
1331
1331
@@ -2413,7 +2413,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Arc<T, A> {
2413
2413
}
2414
2414
}
2415
2415
2416
- impl < A : Allocator + Clone > Arc < dyn Any + Send + Sync , A > {
2416
+ impl < A : Allocator > Arc < dyn Any + Send + Sync , A > {
2417
2417
/// Attempt to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type.
2418
2418
///
2419
2419
/// # Examples
@@ -2440,10 +2440,8 @@ impl<A: Allocator + Clone> Arc<dyn Any + Send + Sync, A> {
2440
2440
{
2441
2441
if ( * self ) . is :: < T > ( ) {
2442
2442
unsafe {
2443
- let ptr = self . ptr . cast :: < ArcInner < T > > ( ) ;
2444
- let alloc = self . alloc . clone ( ) ;
2445
- mem:: forget ( self ) ;
2446
- Ok ( Arc :: from_inner_in ( ptr, alloc) )
2443
+ let ( ptr, alloc) = self . internal_into_inner_with_allocator ( ) ;
2444
+ Ok ( Arc :: from_inner_in ( ptr. cast ( ) , alloc) )
2447
2445
}
2448
2446
} else {
2449
2447
Err ( self )
@@ -2483,10 +2481,8 @@ impl<A: Allocator + Clone> Arc<dyn Any + Send + Sync, A> {
2483
2481
T : Any + Send + Sync ,
2484
2482
{
2485
2483
unsafe {
2486
- let ptr = self . ptr . cast :: < ArcInner < T > > ( ) ;
2487
- let alloc = self . alloc . clone ( ) ;
2488
- mem:: forget ( self ) ;
2489
- Arc :: from_inner_in ( ptr, alloc)
2484
+ let ( ptr, alloc) = self . internal_into_inner_with_allocator ( ) ;
2485
+ Arc :: from_inner_in ( ptr. cast ( ) , alloc)
2490
2486
}
2491
2487
}
2492
2488
}
@@ -3442,13 +3438,13 @@ impl From<Arc<str>> for Arc<[u8]> {
3442
3438
}
3443
3439
3444
3440
#[ stable( feature = "boxed_slice_try_from" , since = "1.43.0" ) ]
3445
- impl < T , A : Allocator + Clone , const N : usize > TryFrom < Arc < [ T ] , A > > for Arc < [ T ; N ] , A > {
3441
+ impl < T , A : Allocator , const N : usize > TryFrom < Arc < [ T ] , A > > for Arc < [ T ; N ] , A > {
3446
3442
type Error = Arc < [ T ] , A > ;
3447
3443
3448
3444
fn try_from ( boxed_slice : Arc < [ T ] , A > ) -> Result < Self , Self :: Error > {
3449
3445
if boxed_slice. len ( ) == N {
3450
- let alloc = boxed_slice. alloc . clone ( ) ;
3451
- Ok ( unsafe { Arc :: from_raw_in ( Arc :: into_raw ( boxed_slice ) as * mut [ T ; N ] , alloc) } )
3446
+ let ( ptr , alloc) = boxed_slice. internal_into_inner_with_allocator ( ) ;
3447
+ Ok ( unsafe { Arc :: from_inner_in ( ptr . cast ( ) , alloc) } )
3452
3448
} else {
3453
3449
Err ( boxed_slice)
3454
3450
}
0 commit comments