@@ -556,7 +556,7 @@ macro_rules! uint_impl {
556
556
pub const fn strict_add( self , rhs: Self ) -> Self {
557
557
let ( a, b) = self . overflowing_add( rhs) ;
558
558
if b { overflow_panic:: add( ) } else { a }
559
- }
559
+ }
560
560
561
561
/// Unchecked integer addition. Computes `self + rhs`, assuming overflow
562
562
/// cannot occur.
@@ -653,7 +653,7 @@ macro_rules! uint_impl {
653
653
pub const fn strict_add_signed( self , rhs: $SignedT) -> Self {
654
654
let ( a, b) = self . overflowing_add_signed( rhs) ;
655
655
if b { overflow_panic:: add( ) } else { a }
656
- }
656
+ }
657
657
658
658
/// Checked integer subtraction. Computes `self - rhs`, returning
659
659
/// `None` if overflow occurred.
@@ -713,7 +713,7 @@ macro_rules! uint_impl {
713
713
pub const fn strict_sub( self , rhs: Self ) -> Self {
714
714
let ( a, b) = self . overflowing_sub( rhs) ;
715
715
if b { overflow_panic:: sub( ) } else { a }
716
- }
716
+ }
717
717
718
718
/// Unchecked integer subtraction. Computes `self - rhs`, assuming overflow
719
719
/// cannot occur.
@@ -805,6 +805,43 @@ macro_rules! uint_impl {
805
805
}
806
806
}
807
807
808
+ /// Strict subtraction with a signed integer. Computes `self - rhs`,
809
+ /// panicking if overflow occurred.
810
+ ///
811
+ /// # Panics
812
+ ///
813
+ /// ## Overflow behavior
814
+ ///
815
+ /// This function will always panic on overflow, regardless of whether overflow checks are enabled.
816
+ ///
817
+ /// # Examples
818
+ ///
819
+ /// ```
820
+ /// #![feature(strict_overflow_ops)]
821
+ #[ doc = concat!( "assert_eq!(3" , stringify!( $SelfT) , ".strict_sub_signed(2), 1);" ) ]
822
+ /// ```
823
+ ///
824
+ /// The following panic because of overflow:
825
+ ///
826
+ /// ```should_panic
827
+ /// #![feature(strict_overflow_ops)]
828
+ #[ doc = concat!( "let _ = 1" , stringify!( $SelfT) , ".strict_sub_signed(2);" ) ]
829
+ /// ```
830
+ ///
831
+ /// ```should_panic
832
+ /// #![feature(strict_overflow_ops)]
833
+ #[ doc = concat!( "let _ = (" , stringify!( $SelfT) , "::MAX).strict_sub_signed(-1);" ) ]
834
+ /// ```
835
+ #[ unstable( feature = "strict_overflow_ops" , issue = "118260" ) ]
836
+ #[ must_use = "this returns the result of the operation, \
837
+ without modifying the original"]
838
+ #[ inline]
839
+ #[ track_caller]
840
+ pub const fn strict_sub_signed( self , rhs: $SignedT) -> Self {
841
+ let ( a, b) = self . overflowing_sub_signed( rhs) ;
842
+ if b { overflow_panic:: sub( ) } else { a }
843
+ }
844
+
808
845
#[ doc = concat!(
809
846
"Checked integer subtraction. Computes `self - rhs` and checks if the result fits into an [`" ,
810
847
stringify!( $SignedT) , "`], returning `None` if overflow occurred."
@@ -913,7 +950,7 @@ macro_rules! uint_impl {
913
950
pub const fn strict_mul( self , rhs: Self ) -> Self {
914
951
let ( a, b) = self . overflowing_mul( rhs) ;
915
952
if b { overflow_panic:: mul( ) } else { a }
916
- }
953
+ }
917
954
918
955
/// Unchecked integer multiplication. Computes `self * rhs`, assuming overflow
919
956
/// cannot occur.
0 commit comments