@@ -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 }
@@ -1275,12 +1281,9 @@ impl<T, A: Allocator> Arc<mem::MaybeUninit<T>, A> {
12751281 #[ unstable( feature = "new_uninit" , issue = "63291" ) ]
12761282 #[ must_use = "`self` will be dropped if the result is not used" ]
12771283 #[ 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) }
12841287 }
12851288}
12861289
@@ -1320,12 +1323,9 @@ impl<T, A: Allocator> Arc<[mem::MaybeUninit<T>], A> {
13201323 #[ unstable( feature = "new_uninit" , issue = "63291" ) ]
13211324 #[ must_use = "`self` will be dropped if the result is not used" ]
13221325 #[ 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) }
13291329 }
13301330}
13311331
@@ -2413,7 +2413,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Arc<T, A> {
24132413 }
24142414}
24152415
2416- impl < A : Allocator + Clone > Arc < dyn Any + Send + Sync , A > {
2416+ impl < A : Allocator > Arc < dyn Any + Send + Sync , A > {
24172417 /// Attempt to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type.
24182418 ///
24192419 /// # Examples
@@ -2440,10 +2440,8 @@ impl<A: Allocator + Clone> Arc<dyn Any + Send + Sync, A> {
24402440 {
24412441 if ( * self ) . is :: < T > ( ) {
24422442 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) )
24472445 }
24482446 } else {
24492447 Err ( self )
@@ -2483,10 +2481,8 @@ impl<A: Allocator + Clone> Arc<dyn Any + Send + Sync, A> {
24832481 T : Any + Send + Sync ,
24842482 {
24852483 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)
24902486 }
24912487 }
24922488}
@@ -3442,13 +3438,13 @@ impl From<Arc<str>> for Arc<[u8]> {
34423438}
34433439
34443440#[ 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 > {
34463442 type Error = Arc < [ T ] , A > ;
34473443
34483444 fn try_from ( boxed_slice : Arc < [ T ] , A > ) -> Result < Self , Self :: Error > {
34493445 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) } )
34523448 } else {
34533449 Err ( boxed_slice)
34543450 }
0 commit comments