@@ -279,6 +279,12 @@ impl<T: ?Sized> Arc<T> {
279279}
280280
281281impl < 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+
282288 #[ inline]
283289 unsafe fn from_inner_in ( ptr : NonNull < ArcInner < T > > , alloc : A ) -> Self {
284290 Self { ptr, phantom : PhantomData , alloc }
@@ -1271,12 +1277,9 @@ impl<T, A: Allocator> Arc<mem::MaybeUninit<T>, A> {
12711277 #[ unstable( feature = "new_uninit" , issue = "63291" ) ]
12721278 #[ must_use = "`self` will be dropped if the result is not used" ]
12731279 #[ 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) }
12801283 }
12811284}
12821285
@@ -1316,12 +1319,9 @@ impl<T, A: Allocator> Arc<[mem::MaybeUninit<T>], A> {
13161319 #[ unstable( feature = "new_uninit" , issue = "63291" ) ]
13171320 #[ must_use = "`self` will be dropped if the result is not used" ]
13181321 #[ 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) }
13251325 }
13261326}
13271327
@@ -2409,7 +2409,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Arc<T, A> {
24092409 }
24102410}
24112411
2412- impl < A : Allocator + Clone > Arc < dyn Any + Send + Sync , A > {
2412+ impl < A : Allocator > Arc < dyn Any + Send + Sync , A > {
24132413 /// Attempt to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type.
24142414 ///
24152415 /// # Examples
@@ -2436,10 +2436,8 @@ impl<A: Allocator + Clone> Arc<dyn Any + Send + Sync, A> {
24362436 {
24372437 if ( * self ) . is :: < T > ( ) {
24382438 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) )
24432441 }
24442442 } else {
24452443 Err ( self )
@@ -2479,10 +2477,8 @@ impl<A: Allocator + Clone> Arc<dyn Any + Send + Sync, A> {
24792477 T : Any + Send + Sync ,
24802478 {
24812479 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)
24862482 }
24872483 }
24882484}
@@ -3438,13 +3434,13 @@ impl From<Arc<str>> for Arc<[u8]> {
34383434}
34393435
34403436#[ stable( feature = "boxed_slice_try_from" , since = "1.43.0" ) ]
3441- impl < T , A : Allocator + Clone , const N : usize > TryFrom < Arc < [ T ] , A > > for Arc < [ T ; N ] , A > {
3437+ impl < T , A : Allocator , const N : usize > TryFrom < Arc < [ T ] , A > > for Arc < [ T ; N ] , A > {
34423438 type Error = Arc < [ T ] , A > ;
34433439
34443440 fn try_from ( boxed_slice : Arc < [ T ] , A > ) -> Result < Self , Self :: Error > {
34453441 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) } )
34483444 } else {
34493445 Err ( boxed_slice)
34503446 }
0 commit comments