@@ -909,6 +909,8 @@ trait RcBoxPtr<T> {
909909 fn inc_strong ( & self ) {
910910 let strong = self . strong ( ) ;
911911 // The reference count is always at least one unless we're about to drop the type
912+ // This allows the bulk of the destructor to be omitted in cases where we know that
913+ // the reference count must be > 0.
912914 unsafe { assume ( strong > 0 ) ; }
913915 self . inner ( ) . strong . set ( strong + 1 ) ;
914916 }
@@ -917,6 +919,8 @@ trait RcBoxPtr<T> {
917919 fn dec_strong ( & self ) {
918920 let strong = self . strong ( ) ;
919921 // The reference count is always at least one unless we're about to drop the type
922+ // This allows the bulk of the destructor to be omitted in cases where we know that
923+ // the reference count must be > 0
920924 unsafe { assume ( strong > 0 ) ; }
921925 self . inner ( ) . strong . set ( strong - 1 ) ;
922926 }
@@ -936,7 +940,9 @@ impl<T> RcBoxPtr<T> for Rc<T> {
936940 fn inner ( & self ) -> & RcBox < T > {
937941 unsafe {
938942 // Safe to assume this here, as if it weren't true, we'd be breaking
939- // the contract anyway
943+ // the contract anyway.
944+ // This allows the null check to be elided in the destructor if we
945+ // manipulated the reference count in the same function.
940946 assume ( !self . _ptr . is_null ( ) ) ;
941947 & ( * * self . _ptr )
942948 }
@@ -949,6 +955,8 @@ impl<T> RcBoxPtr<T> for Weak<T> {
949955 unsafe {
950956 // Safe to assume this here, as if it weren't true, we'd be breaking
951957 // the contract anyway
958+ // This allows the null check to be elided in the destructor if we
959+ // manipulated the reference count in the same function.
952960 assume ( !self . _ptr . is_null ( ) ) ;
953961 & ( * * self . _ptr )
954962 }
0 commit comments