@@ -2533,15 +2533,20 @@ macro_rules! uint_impl {
2533
2533
#[ doc = concat!( "assert_eq!((diff1, diff0), (3, " , stringify!( $SelfT) , "::MAX));" ) ]
2534
2534
/// ```
2535
2535
#[ unstable( feature = "bigint_helper_methods" , issue = "85532" ) ]
2536
+ #[ rustc_const_unstable( feature = "bigint_helper_methods" , issue = "85532" ) ]
2536
2537
#[ must_use = "this returns the result of the operation, \
2537
2538
without modifying the original"]
2538
2539
#[ inline]
2539
2540
pub const fn borrowing_sub( self , rhs: Self , borrow: bool ) -> ( Self , bool ) {
2540
2541
// note: longer-term this should be done via an intrinsic, but this has been shown
2541
2542
// 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)
2543
+ let ( a, c1) = self . overflowing_sub( rhs) ;
2544
+ let ( b, c2) = a. overflowing_sub( borrow as $SelfT) ;
2545
+ // SAFETY: Only one of `c1` and `c2` can be set.
2546
+ // For c1 to be set we need to have underflowed, but if we did then
2547
+ // `a` is nonzero, which means that `c2` cannot possibly
2548
+ // underflow because it's subtracting at most `1` (since it came from `bool`)
2549
+ ( b, unsafe { intrinsics:: disjoint_bitor( c1, c2) } )
2545
2550
}
2546
2551
2547
2552
/// Calculates `self` - `rhs` with a signed `rhs`
0 commit comments