@@ -710,6 +710,23 @@ $EndFeature, "
710
710
}
711
711
}
712
712
713
+ doc_comment! {
714
+ concat!( "Unchecked integer addition. Computes `self + rhs, assuming overflow
715
+ cannot occur. This results in undefined behavior when `self + rhs > " , stringify!( $SelfT) ,
716
+ "::max_value()` or `self + rhs < " , stringify!( $SelfT) , "::min_value()`." ) ,
717
+ #[ unstable(
718
+ feature = "unchecked_math" ,
719
+ reason = "niche optimization path" ,
720
+ issue = "none" ,
721
+ ) ]
722
+ #[ must_use = "this returns the result of the operation, \
723
+ without modifying the original"]
724
+ #[ inline]
725
+ pub unsafe fn unchecked_add( self , rhs: Self ) -> Self {
726
+ intrinsics:: unchecked_add( self , rhs)
727
+ }
728
+ }
729
+
713
730
doc_comment! {
714
731
concat!( "Checked integer subtraction. Computes `self - rhs`, returning `None` if
715
732
overflow occurred.
@@ -734,6 +751,23 @@ $EndFeature, "
734
751
}
735
752
}
736
753
754
+ doc_comment! {
755
+ concat!( "Unchecked integer subtraction. Computes `self - rhs, assuming overflow
756
+ cannot occur. This results in undefined behavior when `self - rhs > " , stringify!( $SelfT) ,
757
+ "::max_value()` or `self - rhs < " , stringify!( $SelfT) , "::min_value()`." ) ,
758
+ #[ unstable(
759
+ feature = "unchecked_math" ,
760
+ reason = "niche optimization path" ,
761
+ issue = "none" ,
762
+ ) ]
763
+ #[ must_use = "this returns the result of the operation, \
764
+ without modifying the original"]
765
+ #[ inline]
766
+ pub unsafe fn unchecked_sub( self , rhs: Self ) -> Self {
767
+ intrinsics:: unchecked_sub( self , rhs)
768
+ }
769
+ }
770
+
737
771
doc_comment! {
738
772
concat!( "Checked integer multiplication. Computes `self * rhs`, returning `None` if
739
773
overflow occurred.
@@ -758,6 +792,23 @@ $EndFeature, "
758
792
}
759
793
}
760
794
795
+ doc_comment! {
796
+ concat!( "Unchecked integer multiplication. Computes `self * rhs, assuming overflow
797
+ cannot occur. This results in undefined behavior when `self * rhs > " , stringify!( $SelfT) ,
798
+ "::max_value()` or `self * rhs < " , stringify!( $SelfT) , "::min_value()`." ) ,
799
+ #[ unstable(
800
+ feature = "unchecked_math" ,
801
+ reason = "niche optimization path" ,
802
+ issue = "none" ,
803
+ ) ]
804
+ #[ must_use = "this returns the result of the operation, \
805
+ without modifying the original"]
806
+ #[ inline]
807
+ pub unsafe fn unchecked_mul( self , rhs: Self ) -> Self {
808
+ intrinsics:: unchecked_mul( self , rhs)
809
+ }
810
+ }
811
+
761
812
doc_comment! {
762
813
concat!( "Checked integer division. Computes `self / rhs`, returning `None` if `rhs == 0`
763
814
or the division results in overflow.
@@ -2856,6 +2907,23 @@ assert_eq!((", stringify!($SelfT), "::max_value() - 2).checked_add(3), None);",
2856
2907
}
2857
2908
}
2858
2909
2910
+ doc_comment! {
2911
+ concat!( "Unchecked integer addition. Computes `self + rhs, assuming overflow
2912
+ cannot occur. This results in undefined behavior when `self + rhs > " , stringify!( $SelfT) ,
2913
+ "::max_value()` or `self + rhs < " , stringify!( $SelfT) , "::min_value()`." ) ,
2914
+ #[ unstable(
2915
+ feature = "unchecked_math" ,
2916
+ reason = "niche optimization path" ,
2917
+ issue = "none" ,
2918
+ ) ]
2919
+ #[ must_use = "this returns the result of the operation, \
2920
+ without modifying the original"]
2921
+ #[ inline]
2922
+ pub unsafe fn unchecked_add( self , rhs: Self ) -> Self {
2923
+ intrinsics:: unchecked_add( self , rhs)
2924
+ }
2925
+ }
2926
+
2859
2927
doc_comment! {
2860
2928
concat!( "Checked integer subtraction. Computes `self - rhs`, returning
2861
2929
`None` if overflow occurred.
@@ -2878,6 +2946,23 @@ assert_eq!(0", stringify!($SelfT), ".checked_sub(1), None);", $EndFeature, "
2878
2946
}
2879
2947
}
2880
2948
2949
+ doc_comment! {
2950
+ concat!( "Unchecked integer subtraction. Computes `self - rhs, assuming overflow
2951
+ cannot occur. This results in undefined behavior when `self - rhs > " , stringify!( $SelfT) ,
2952
+ "::max_value()` or `self - rhs < " , stringify!( $SelfT) , "::min_value()`." ) ,
2953
+ #[ unstable(
2954
+ feature = "unchecked_math" ,
2955
+ reason = "niche optimization path" ,
2956
+ issue = "none" ,
2957
+ ) ]
2958
+ #[ must_use = "this returns the result of the operation, \
2959
+ without modifying the original"]
2960
+ #[ inline]
2961
+ pub unsafe fn unchecked_sub( self , rhs: Self ) -> Self {
2962
+ intrinsics:: unchecked_sub( self , rhs)
2963
+ }
2964
+ }
2965
+
2881
2966
doc_comment! {
2882
2967
concat!( "Checked integer multiplication. Computes `self * rhs`, returning
2883
2968
`None` if overflow occurred.
@@ -2900,6 +2985,23 @@ assert_eq!(", stringify!($SelfT), "::max_value().checked_mul(2), None);", $EndFe
2900
2985
}
2901
2986
}
2902
2987
2988
+ doc_comment! {
2989
+ concat!( "Unchecked integer multiplication. Computes `self * rhs, assuming overflow
2990
+ cannot occur. This results in undefined behavior when `self * rhs > " , stringify!( $SelfT) ,
2991
+ "::max_value()` or `self * rhs < " , stringify!( $SelfT) , "::min_value()`." ) ,
2992
+ #[ unstable(
2993
+ feature = "unchecked_math" ,
2994
+ reason = "niche optimization path" ,
2995
+ issue = "none" ,
2996
+ ) ]
2997
+ #[ must_use = "this returns the result of the operation, \
2998
+ without modifying the original"]
2999
+ #[ inline]
3000
+ pub unsafe fn unchecked_mul( self , rhs: Self ) -> Self {
3001
+ intrinsics:: unchecked_mul( self , rhs)
3002
+ }
3003
+ }
3004
+
2903
3005
doc_comment! {
2904
3006
concat!( "Checked integer division. Computes `self / rhs`, returning `None`
2905
3007
if `rhs == 0`.
0 commit comments