@@ -882,17 +882,38 @@ $EndFeature, "
882882```" ) ,
883883 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
884884 #[ inline]
885+ #[ cfg( stage0) ]
885886 pub fn saturating_add( self , rhs: Self ) -> Self {
886- #[ cfg( stage0) ]
887887 match self . checked_add( rhs) {
888888 Some ( x) => x,
889889 None if rhs >= 0 => Self :: max_value( ) ,
890890 None => Self :: min_value( ) ,
891891 }
892- #[ cfg( not( stage0) ) ]
893- {
894- intrinsics:: saturating_add( self , rhs)
895- }
892+ }
893+
894+ }
895+
896+ doc_comment! {
897+ concat!( "Saturating integer addition. Computes `self + rhs`, saturating at the numeric
898+ bounds instead of overflowing.
899+
900+ # Examples
901+
902+ Basic usage:
903+
904+ ```
905+ " , $Feature, "assert_eq!(100" , stringify!( $SelfT) , ".saturating_add(1), 101);
906+ assert_eq!(" , stringify!( $SelfT) , "::max_value().saturating_add(100), " , stringify!( $SelfT) ,
907+ "::max_value());" ,
908+ $EndFeature, "
909+ ```" ) ,
910+
911+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
912+ #[ rustc_const_unstable( feature = "const_saturating_int_methods" ) ]
913+ #[ inline]
914+ #[ cfg( not( stage0) ) ]
915+ pub const fn saturating_add( self , rhs: Self ) -> Self {
916+ intrinsics:: saturating_add( self , rhs)
896917 }
897918 }
898919
@@ -912,17 +933,36 @@ $EndFeature, "
912933```" ) ,
913934 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
914935 #[ inline]
936+ #[ cfg( stage0) ]
915937 pub fn saturating_sub( self , rhs: Self ) -> Self {
916- #[ cfg( stage0) ]
917938 match self . checked_sub( rhs) {
918939 Some ( x) => x,
919940 None if rhs >= 0 => Self :: min_value( ) ,
920941 None => Self :: max_value( ) ,
921942 }
922- #[ cfg( not( stage0) ) ]
923- {
924- intrinsics:: saturating_sub( self , rhs)
925- }
943+ }
944+ }
945+
946+ doc_comment! {
947+ concat!( "Saturating integer subtraction. Computes `self - rhs`, saturating at the
948+ numeric bounds instead of overflowing.
949+
950+ # Examples
951+
952+ Basic usage:
953+
954+ ```
955+ " , $Feature, "assert_eq!(100" , stringify!( $SelfT) , ".saturating_sub(127), -27);
956+ assert_eq!(" , stringify!( $SelfT) , "::min_value().saturating_sub(100), " , stringify!( $SelfT) ,
957+ "::min_value());" ,
958+ $EndFeature, "
959+ ```" ) ,
960+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
961+ #[ rustc_const_unstable( feature = "const_saturating_int_methods" ) ]
962+ #[ inline]
963+ #[ cfg( not( stage0) ) ]
964+ pub const fn saturating_sub( self , rhs: Self ) -> Self {
965+ intrinsics:: saturating_sub( self , rhs)
926966 }
927967 }
928968
@@ -2753,16 +2793,34 @@ assert_eq!(200u8.saturating_add(127), 255);", $EndFeature, "
27532793```" ) ,
27542794 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
27552795 #[ inline]
2796+ #[ cfg( stage0) ]
27562797 pub fn saturating_add( self , rhs: Self ) -> Self {
2757- #[ cfg( stage0) ]
27582798 match self . checked_add( rhs) {
27592799 Some ( x) => x,
27602800 None => Self :: max_value( ) ,
27612801 }
2762- #[ cfg( not( stage0) ) ]
2763- {
2764- intrinsics:: saturating_add( self , rhs)
2765- }
2802+ }
2803+ }
2804+
2805+ doc_comment! {
2806+ concat!( "Saturating integer addition. Computes `self + rhs`, saturating at
2807+ the numeric bounds instead of overflowing.
2808+
2809+ # Examples
2810+
2811+ Basic usage:
2812+
2813+ ```
2814+ " , $Feature, "assert_eq!(100" , stringify!( $SelfT) , ".saturating_add(1), 101);
2815+ assert_eq!(200u8.saturating_add(127), 255);" , $EndFeature, "
2816+ ```" ) ,
2817+
2818+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2819+ #[ rustc_const_unstable( feature = "const_saturating_int_methods" ) ]
2820+ #[ inline]
2821+ #[ cfg( not( stage0) ) ]
2822+ pub const fn saturating_add( self , rhs: Self ) -> Self {
2823+ intrinsics:: saturating_add( self , rhs)
27662824 }
27672825 }
27682826
@@ -2780,16 +2838,33 @@ assert_eq!(13", stringify!($SelfT), ".saturating_sub(127), 0);", $EndFeature, "
27802838```" ) ,
27812839 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
27822840 #[ inline]
2841+ #[ cfg( stage0) ]
27832842 pub fn saturating_sub( self , rhs: Self ) -> Self {
2784- #[ cfg( stage0) ]
27852843 match self . checked_sub( rhs) {
27862844 Some ( x) => x,
27872845 None => Self :: min_value( ) ,
27882846 }
2789- #[ cfg( not( stage0) ) ]
2790- {
2791- intrinsics:: saturating_sub( self , rhs)
2792- }
2847+ }
2848+ }
2849+
2850+ doc_comment! {
2851+ concat!( "Saturating integer subtraction. Computes `self - rhs`, saturating
2852+ at the numeric bounds instead of overflowing.
2853+
2854+ # Examples
2855+
2856+ Basic usage:
2857+
2858+ ```
2859+ " , $Feature, "assert_eq!(100" , stringify!( $SelfT) , ".saturating_sub(27), 73);
2860+ assert_eq!(13" , stringify!( $SelfT) , ".saturating_sub(127), 0);" , $EndFeature, "
2861+ ```" ) ,
2862+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2863+ #[ rustc_const_unstable( feature = "const_saturating_int_methods" ) ]
2864+ #[ inline]
2865+ #[ cfg( not( stage0) ) ]
2866+ pub const fn saturating_sub( self , rhs: Self ) -> Self {
2867+ intrinsics:: saturating_sub( self , rhs)
27932868 }
27942869 }
27952870
0 commit comments