File tree 2 files changed +6
-17
lines changed
2 files changed +6
-17
lines changed Original file line number Diff line number Diff line change @@ -1001,14 +1001,9 @@ impl Arc<Any + Send + Sync> {
1001
1001
T : Any + Send + Sync + ' static ,
1002
1002
{
1003
1003
if ( * self ) . is :: < T > ( ) {
1004
- unsafe {
1005
- let raw: * const ArcInner < Any + Send + Sync > = self . ptr . as_ptr ( ) ;
1006
- mem:: forget ( self ) ;
1007
- Ok ( Arc {
1008
- ptr : NonNull :: new_unchecked ( raw as * const ArcInner < T > as * mut _ ) ,
1009
- phantom : PhantomData ,
1010
- } )
1011
- }
1004
+ let ptr = self . ptr . cast :: < ArcInner < T > > ( ) ;
1005
+ mem:: forget ( self ) ;
1006
+ Ok ( Arc { ptr, phantom : PhantomData } )
1012
1007
} else {
1013
1008
Err ( self )
1014
1009
}
Original file line number Diff line number Diff line change @@ -644,15 +644,9 @@ impl Rc<Any> {
644
644
/// ```
645
645
pub fn downcast < T : Any > ( self ) -> Result < Rc < T > , Rc < Any > > {
646
646
if ( * self ) . is :: < T > ( ) {
647
- // avoid the pointer arithmetic in from_raw
648
- unsafe {
649
- let raw: * const RcBox < Any > = self . ptr . as_ptr ( ) ;
650
- forget ( self ) ;
651
- Ok ( Rc {
652
- ptr : NonNull :: new_unchecked ( raw as * const RcBox < T > as * mut _ ) ,
653
- phantom : PhantomData ,
654
- } )
655
- }
647
+ let ptr = self . ptr . cast :: < RcBox < T > > ( ) ;
648
+ forget ( self ) ;
649
+ Ok ( Rc { ptr, phantom : PhantomData } )
656
650
} else {
657
651
Err ( self )
658
652
}
You can’t perform that action at this time.
0 commit comments