@@ -160,6 +160,7 @@ use core::option::Option::{Some, None};
160
160
use core:: ptr:: { self , PtrExt } ;
161
161
use core:: result:: Result ;
162
162
use core:: result:: Result :: { Ok , Err } ;
163
+ use core:: intrinsics:: assume;
163
164
164
165
use heap:: deallocate;
165
166
@@ -769,12 +770,34 @@ trait RcBoxPtr<T> {
769
770
770
771
impl < T > RcBoxPtr < T > for Rc < T > {
771
772
#[ 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
+ }
773
785
}
774
786
775
787
impl < T > RcBoxPtr < T > for Weak < T > {
776
788
#[ 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
+ }
778
801
}
779
802
780
803
#[ cfg( test) ]
0 commit comments