@@ -697,6 +697,23 @@ $EndFeature, "
697
697
}
698
698
}
699
699
700
+ doc_comment! {
701
+ concat!( "Unchecked integer addition. Computes `self + rhs, assuming overflow
702
+ cannot occur. This results in undefined behavior when `self + rhs > " , stringify!( $SelfT) ,
703
+ "::max_value()` or `self + rhs < " , stringify!( $SelfT) , "::min_value()`." ) ,
704
+ #[ unstable(
705
+ feature = "unchecked_math" ,
706
+ reason = "niche optimization path" ,
707
+ issue = "none" ,
708
+ ) ]
709
+ #[ must_use = "this returns the result of the operation, \
710
+ without modifying the original"]
711
+ #[ inline]
712
+ pub unsafe fn unchecked_add( self , rhs: Self ) -> Self {
713
+ intrinsics:: unchecked_add( self , rhs)
714
+ }
715
+ }
716
+
700
717
doc_comment! {
701
718
concat!( "Checked integer subtraction. Computes `self - rhs`, returning `None` if
702
719
overflow occurred.
@@ -722,6 +739,23 @@ $EndFeature, "
722
739
}
723
740
}
724
741
742
+ doc_comment! {
743
+ concat!( "Unchecked integer subtraction. Computes `self - rhs, assuming overflow
744
+ cannot occur. This results in undefined behavior when `self - rhs > " , stringify!( $SelfT) ,
745
+ "::max_value()` or `self - rhs < " , stringify!( $SelfT) , "::min_value()`." ) ,
746
+ #[ unstable(
747
+ feature = "unchecked_math" ,
748
+ reason = "niche optimization path" ,
749
+ issue = "none" ,
750
+ ) ]
751
+ #[ must_use = "this returns the result of the operation, \
752
+ without modifying the original"]
753
+ #[ inline]
754
+ pub unsafe fn unchecked_sub( self , rhs: Self ) -> Self {
755
+ intrinsics:: unchecked_sub( self , rhs)
756
+ }
757
+ }
758
+
725
759
doc_comment! {
726
760
concat!( "Checked integer multiplication. Computes `self * rhs`, returning `None` if
727
761
overflow occurred.
@@ -747,6 +781,23 @@ $EndFeature, "
747
781
}
748
782
}
749
783
784
+ doc_comment! {
785
+ concat!( "Unchecked integer multiplication. Computes `self * rhs, assuming overflow
786
+ cannot occur. This results in undefined behavior when `self * rhs > " , stringify!( $SelfT) ,
787
+ "::max_value()` or `self * rhs < " , stringify!( $SelfT) , "::min_value()`." ) ,
788
+ #[ unstable(
789
+ feature = "unchecked_math" ,
790
+ reason = "niche optimization path" ,
791
+ issue = "none" ,
792
+ ) ]
793
+ #[ must_use = "this returns the result of the operation, \
794
+ without modifying the original"]
795
+ #[ inline]
796
+ pub unsafe fn unchecked_mul( self , rhs: Self ) -> Self {
797
+ intrinsics:: unchecked_mul( self , rhs)
798
+ }
799
+ }
800
+
750
801
doc_comment! {
751
802
concat!( "Checked integer division. Computes `self / rhs`, returning `None` if `rhs == 0`
752
803
or the division results in overflow.
@@ -2884,6 +2935,23 @@ assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);", $EndFeat
2884
2935
}
2885
2936
}
2886
2937
2938
+ doc_comment! {
2939
+ concat!( "Unchecked integer addition. Computes `self + rhs, assuming overflow
2940
+ cannot occur. This results in undefined behavior when `self + rhs > " , stringify!( $SelfT) ,
2941
+ "::max_value()` or `self + rhs < " , stringify!( $SelfT) , "::min_value()`." ) ,
2942
+ #[ unstable(
2943
+ feature = "unchecked_math" ,
2944
+ reason = "niche optimization path" ,
2945
+ issue = "none" ,
2946
+ ) ]
2947
+ #[ must_use = "this returns the result of the operation, \
2948
+ without modifying the original"]
2949
+ #[ inline]
2950
+ pub unsafe fn unchecked_add( self , rhs: Self ) -> Self {
2951
+ intrinsics:: unchecked_add( self , rhs)
2952
+ }
2953
+ }
2954
+
2887
2955
doc_comment! {
2888
2956
concat!( "Checked integer subtraction. Computes `self - rhs`, returning
2889
2957
`None` if overflow occurred.
@@ -2907,6 +2975,23 @@ assert_eq!(0", stringify!($SelfT), ".checked_sub(1), None);", $EndFeature, "
2907
2975
}
2908
2976
}
2909
2977
2978
+ doc_comment! {
2979
+ concat!( "Unchecked integer subtraction. Computes `self - rhs, assuming overflow
2980
+ cannot occur. This results in undefined behavior when `self - rhs > " , stringify!( $SelfT) ,
2981
+ "::max_value()` or `self - rhs < " , stringify!( $SelfT) , "::min_value()`." ) ,
2982
+ #[ unstable(
2983
+ feature = "unchecked_math" ,
2984
+ reason = "niche optimization path" ,
2985
+ issue = "none" ,
2986
+ ) ]
2987
+ #[ must_use = "this returns the result of the operation, \
2988
+ without modifying the original"]
2989
+ #[ inline]
2990
+ pub unsafe fn unchecked_sub( self , rhs: Self ) -> Self {
2991
+ intrinsics:: unchecked_sub( self , rhs)
2992
+ }
2993
+ }
2994
+
2910
2995
doc_comment! {
2911
2996
concat!( "Checked integer multiplication. Computes `self * rhs`, returning
2912
2997
`None` if overflow occurred.
@@ -2930,6 +3015,23 @@ assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(2), None);", $EndFeature, "
2930
3015
}
2931
3016
}
2932
3017
3018
+ doc_comment! {
3019
+ concat!( "Unchecked integer multiplication. Computes `self * rhs, assuming overflow
3020
+ cannot occur. This results in undefined behavior when `self * rhs > " , stringify!( $SelfT) ,
3021
+ "::max_value()` or `self * rhs < " , stringify!( $SelfT) , "::min_value()`." ) ,
3022
+ #[ unstable(
3023
+ feature = "unchecked_math" ,
3024
+ reason = "niche optimization path" ,
3025
+ issue = "none" ,
3026
+ ) ]
3027
+ #[ must_use = "this returns the result of the operation, \
3028
+ without modifying the original"]
3029
+ #[ inline]
3030
+ pub unsafe fn unchecked_mul( self , rhs: Self ) -> Self {
3031
+ intrinsics:: unchecked_mul( self , rhs)
3032
+ }
3033
+ }
3034
+
2933
3035
doc_comment! {
2934
3036
concat!( "Checked integer division. Computes `self / rhs`, returning `None`
2935
3037
if `rhs == 0`.
0 commit comments