File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -2539,9 +2539,13 @@ macro_rules! uint_impl {
25392539 pub const fn borrowing_sub( self , rhs: Self , borrow: bool ) -> ( Self , bool ) {
25402540 // note: longer-term this should be done via an intrinsic, but this has been shown
25412541 // to generate optimal code for now, and LLVM doesn't have an equivalent intrinsic
2542- let ( a, b) = self . overflowing_sub( rhs) ;
2543- let ( c, d) = a. overflowing_sub( borrow as $SelfT) ;
2544- ( c, b | d)
2542+ let ( a, c1) = self . overflowing_sub( rhs) ;
2543+ let ( b, c2) = a. overflowing_sub( borrow as $SelfT) ;
2544+ // SAFETY: Only one of `c1` and `c2` can be set.
2545+ // For c1 to be set we need to have underflowed, but if we did then
2546+ // `a` is nonzero, which means that `c2` cannot possibly
2547+ // underflow because it's subtracting at most `1` (since it came from `bool`)
2548+ ( b, unsafe { intrinsics:: disjoint_bitor( c1, c2) } )
25452549 }
25462550
25472551 /// Calculates `self` - `rhs` with a signed `rhs`
You can’t perform that action at this time.
0 commit comments