@@ -160,6 +160,7 @@ use core::option::Option::{Some, None};
160160use core:: ptr:: { self , PtrExt } ;
161161use core:: result:: Result ;
162162use core:: result:: Result :: { Ok , Err } ;
163+ use core:: intrinsics:: assume;
163164
164165use heap:: deallocate;
165166
@@ -769,12 +770,34 @@ trait RcBoxPtr<T> {
769770
770771impl < T > RcBoxPtr < T > for Rc < T > {
771772 #[ inline( always) ]
772- fn inner ( & self ) -> & RcBox < T > { unsafe { & ( * * self . _ptr ) } }
773+ fn inner ( & self ) -> & RcBox < T > {
774+ unsafe {
775+ // Safe to assume this here, as if it weren't true, we'd be breaking
776+ // the contract anyway.
777+ // This allows the null check to be elided in the destructor if we
778+ // manipulated the reference count in the same function.
779+ if cfg ! ( not( stage0) ) { // NOTE remove cfg after next snapshot
780+ assume ( !self . _ptr . is_null ( ) ) ;
781+ }
782+ & ( * * self . _ptr )
783+ }
784+ }
773785}
774786
775787impl < T > RcBoxPtr < T > for Weak < T > {
776788 #[ inline( always) ]
777- fn inner ( & self ) -> & RcBox < T > { unsafe { & ( * * self . _ptr ) } }
789+ fn inner ( & self ) -> & RcBox < T > {
790+ unsafe {
791+ // Safe to assume this here, as if it weren't true, we'd be breaking
792+ // the contract anyway.
793+ // This allows the null check to be elided in the destructor if we
794+ // manipulated the reference count in the same function.
795+ if cfg ! ( not( stage0) ) { // NOTE remove cfg after next snapshot
796+ assume ( !self . _ptr . is_null ( ) ) ;
797+ }
798+ & ( * * self . _ptr )
799+ }
800+ }
778801}
779802
780803#[ cfg( test) ]
0 commit comments