@@ -365,6 +365,12 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
365
365
unsafe { self . ptr . as_ref ( ) }
366
366
}
367
367
368
+ #[ inline]
369
+ fn into_inner_with_allocator ( this : Self ) -> ( NonNull < RcBox < T > > , A ) {
370
+ let this = mem:: ManuallyDrop :: new ( this) ;
371
+ ( this. ptr , unsafe { ptr:: read ( & this. alloc ) } )
372
+ }
373
+
368
374
#[ inline]
369
375
unsafe fn from_inner_in ( ptr : NonNull < RcBox < T > > , alloc : A ) -> Self {
370
376
Self { ptr, phantom : PhantomData , alloc }
@@ -1136,8 +1142,8 @@ impl<T, A: Allocator> Rc<mem::MaybeUninit<T>, A> {
1136
1142
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
1137
1143
#[ inline]
1138
1144
pub unsafe fn assume_init ( self ) -> Rc < T , A > {
1139
- let ( ptr, alloc) = Self :: into_raw_with_allocator ( self ) ;
1140
- unsafe { Rc :: from_raw_in ( ptr. cast ( ) , alloc) }
1145
+ let ( ptr, alloc) = Self :: into_inner_with_allocator ( self ) ;
1146
+ unsafe { Rc :: from_inner_in ( ptr. cast ( ) , alloc) }
1141
1147
}
1142
1148
}
1143
1149
@@ -1177,8 +1183,8 @@ impl<T, A: Allocator> Rc<[mem::MaybeUninit<T>], A> {
1177
1183
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
1178
1184
#[ inline]
1179
1185
pub unsafe fn assume_init ( self ) -> Rc < [ T ] , A > {
1180
- let ( ptr, alloc) = Self :: into_raw_with_allocator ( self ) ;
1181
- unsafe { Rc :: from_raw_in ( ptr as * const [ T ] , alloc) }
1186
+ let ( ptr, alloc) = Self :: into_inner_with_allocator ( self ) ;
1187
+ unsafe { Rc :: from_ptr_in ( ptr. as_ptr ( ) as _ , alloc) }
1182
1188
}
1183
1189
}
1184
1190
@@ -1892,11 +1898,8 @@ impl<A: Allocator> Rc<dyn Any, A> {
1892
1898
#[ stable( feature = "rc_downcast" , since = "1.29.0" ) ]
1893
1899
pub fn downcast < T : Any > ( self ) -> Result < Rc < T , A > , Self > {
1894
1900
if ( * self ) . is :: < T > ( ) {
1895
- let this = mem:: ManuallyDrop :: new ( self ) ;
1896
- let ptr = this. ptr . cast :: < RcBox < T > > ( ) ;
1897
- // Safety: `this` is ManuallyDrop so the allocator will not be double-dropped
1898
- let alloc = unsafe { ptr:: read ( & this. alloc ) } ;
1899
- unsafe { Ok ( Rc :: from_inner_in ( ptr, alloc) ) }
1901
+ let ( ptr, alloc) = Rc :: into_inner_with_allocator ( self ) ;
1902
+ unsafe { Ok ( Rc :: from_inner_in ( ptr. cast ( ) , alloc) ) }
1900
1903
} else {
1901
1904
Err ( self )
1902
1905
}
@@ -1931,11 +1934,8 @@ impl<A: Allocator> Rc<dyn Any, A> {
1931
1934
#[ inline]
1932
1935
#[ unstable( feature = "downcast_unchecked" , issue = "90850" ) ]
1933
1936
pub unsafe fn downcast_unchecked < T : Any > ( self ) -> Rc < T , A > {
1934
- let this = mem:: ManuallyDrop :: new ( self ) ;
1935
- let ptr = this. ptr . cast :: < RcBox < T > > ( ) ;
1936
- // Safety: `this` is ManuallyDrop so the allocator will not be double-dropped
1937
- let alloc = unsafe { ptr:: read ( & this. alloc ) } ;
1938
- unsafe { Rc :: from_inner_in ( ptr, alloc) }
1937
+ let ( ptr, alloc) = Rc :: into_inner_with_allocator ( self ) ;
1938
+ unsafe { Rc :: from_inner_in ( ptr. cast ( ) , alloc) }
1939
1939
}
1940
1940
}
1941
1941
@@ -2688,8 +2688,8 @@ impl<T, A: Allocator, const N: usize> TryFrom<Rc<[T], A>> for Rc<[T; N], A> {
2688
2688
2689
2689
fn try_from ( boxed_slice : Rc < [ T ] , A > ) -> Result < Self , Self :: Error > {
2690
2690
if boxed_slice. len ( ) == N {
2691
- let ( ptr, alloc) = Rc :: into_raw_with_allocator ( boxed_slice) ;
2692
- Ok ( unsafe { Rc :: from_raw_in ( ptr as * mut [ T ; N ] , alloc) } )
2691
+ let ( ptr, alloc) = Rc :: into_inner_with_allocator ( boxed_slice) ;
2692
+ Ok ( unsafe { Rc :: from_inner_in ( ptr. cast ( ) , alloc) } )
2693
2693
} else {
2694
2694
Err ( boxed_slice)
2695
2695
}
0 commit comments