@@ -626,9 +626,9 @@ $EndFeature, "
626
626
#[ must_use = "this returns the result of the operation, \
627
627
without modifying the original"]
628
628
#[ inline]
629
- pub fn checked_add( self , rhs: Self ) -> Option <Self > {
629
+ pub const fn checked_add( self , rhs: Self ) -> Option <Self > {
630
630
let ( a, b) = self . overflowing_add( rhs) ;
631
- if b { None } else { Some ( a) }
631
+ [ Some ( a) , None ] [ b as usize ]
632
632
}
633
633
}
634
634
@@ -650,9 +650,9 @@ $EndFeature, "
650
650
#[ must_use = "this returns the result of the operation, \
651
651
without modifying the original"]
652
652
#[ inline]
653
- pub fn checked_sub( self , rhs: Self ) -> Option <Self > {
653
+ pub const fn checked_sub( self , rhs: Self ) -> Option <Self > {
654
654
let ( a, b) = self . overflowing_sub( rhs) ;
655
- if b { None } else { Some ( a) }
655
+ [ Some ( a) , None ] [ b as usize ]
656
656
}
657
657
}
658
658
@@ -674,9 +674,9 @@ $EndFeature, "
674
674
#[ must_use = "this returns the result of the operation, \
675
675
without modifying the original"]
676
676
#[ inline]
677
- pub fn checked_mul( self , rhs: Self ) -> Option <Self > {
677
+ pub const fn checked_mul( self , rhs: Self ) -> Option <Self > {
678
678
let ( a, b) = self . overflowing_mul( rhs) ;
679
- if b { None } else { Some ( a) }
679
+ [ Some ( a) , None ] [ b as usize ]
680
680
}
681
681
}
682
682
@@ -808,9 +808,9 @@ $EndFeature, "
808
808
```" ) ,
809
809
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
810
810
#[ inline]
811
- pub fn checked_neg( self ) -> Option <Self > {
811
+ pub const fn checked_neg( self ) -> Option <Self > {
812
812
let ( a, b) = self . overflowing_neg( ) ;
813
- if b { None } else { Some ( a) }
813
+ [ Some ( a) , None ] [ b as usize ]
814
814
}
815
815
}
816
816
@@ -831,9 +831,9 @@ $EndFeature, "
831
831
#[ must_use = "this returns the result of the operation, \
832
832
without modifying the original"]
833
833
#[ inline]
834
- pub fn checked_shl( self , rhs: u32 ) -> Option <Self > {
834
+ pub const fn checked_shl( self , rhs: u32 ) -> Option <Self > {
835
835
let ( a, b) = self . overflowing_shl( rhs) ;
836
- if b { None } else { Some ( a) }
836
+ [ Some ( a) , None ] [ b as usize ]
837
837
}
838
838
}
839
839
@@ -854,9 +854,9 @@ $EndFeature, "
854
854
#[ must_use = "this returns the result of the operation, \
855
855
without modifying the original"]
856
856
#[ inline]
857
- pub fn checked_shr( self , rhs: u32 ) -> Option <Self > {
857
+ pub const fn checked_shr( self , rhs: u32 ) -> Option <Self > {
858
858
let ( a, b) = self . overflowing_shr( rhs) ;
859
- if b { None } else { Some ( a) }
859
+ [ Some ( a) , None ] [ b as usize ]
860
860
}
861
861
}
862
862
@@ -2679,9 +2679,9 @@ assert_eq!((", stringify!($SelfT), "::max_value() - 2).checked_add(3), None);",
2679
2679
#[ must_use = "this returns the result of the operation, \
2680
2680
without modifying the original"]
2681
2681
#[ inline]
2682
- pub fn checked_add( self , rhs: Self ) -> Option <Self > {
2682
+ pub const fn checked_add( self , rhs: Self ) -> Option <Self > {
2683
2683
let ( a, b) = self . overflowing_add( rhs) ;
2684
- if b { None } else { Some ( a) }
2684
+ [ Some ( a) , None ] [ b as usize ]
2685
2685
}
2686
2686
}
2687
2687
@@ -2701,9 +2701,9 @@ assert_eq!(0", stringify!($SelfT), ".checked_sub(1), None);", $EndFeature, "
2701
2701
#[ must_use = "this returns the result of the operation, \
2702
2702
without modifying the original"]
2703
2703
#[ inline]
2704
- pub fn checked_sub( self , rhs: Self ) -> Option <Self > {
2704
+ pub const fn checked_sub( self , rhs: Self ) -> Option <Self > {
2705
2705
let ( a, b) = self . overflowing_sub( rhs) ;
2706
- if b { None } else { Some ( a) }
2706
+ [ Some ( a) , None ] [ b as usize ]
2707
2707
}
2708
2708
}
2709
2709
@@ -2723,9 +2723,9 @@ assert_eq!(", stringify!($SelfT), "::max_value().checked_mul(2), None);", $EndFe
2723
2723
#[ must_use = "this returns the result of the operation, \
2724
2724
without modifying the original"]
2725
2725
#[ inline]
2726
- pub fn checked_mul( self , rhs: Self ) -> Option <Self > {
2726
+ pub const fn checked_mul( self , rhs: Self ) -> Option <Self > {
2727
2727
let ( a, b) = self . overflowing_mul( rhs) ;
2728
- if b { None } else { Some ( a) }
2728
+ [ Some ( a) , None ] [ b as usize ]
2729
2729
}
2730
2730
}
2731
2731
@@ -2845,9 +2845,9 @@ assert_eq!(1", stringify!($SelfT), ".checked_neg(), None);", $EndFeature, "
2845
2845
```" ) ,
2846
2846
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
2847
2847
#[ inline]
2848
- pub fn checked_neg( self ) -> Option <Self > {
2848
+ pub const fn checked_neg( self ) -> Option <Self > {
2849
2849
let ( a, b) = self . overflowing_neg( ) ;
2850
- if b { None } else { Some ( a) }
2850
+ [ Some ( a) , None ] [ b as usize ]
2851
2851
}
2852
2852
}
2853
2853
@@ -2867,9 +2867,9 @@ assert_eq!(0x10", stringify!($SelfT), ".checked_shl(129), None);", $EndFeature,
2867
2867
#[ must_use = "this returns the result of the operation, \
2868
2868
without modifying the original"]
2869
2869
#[ inline]
2870
- pub fn checked_shl( self , rhs: u32 ) -> Option <Self > {
2870
+ pub const fn checked_shl( self , rhs: u32 ) -> Option <Self > {
2871
2871
let ( a, b) = self . overflowing_shl( rhs) ;
2872
- if b { None } else { Some ( a) }
2872
+ [ Some ( a) , None ] [ b as usize ]
2873
2873
}
2874
2874
}
2875
2875
@@ -2889,9 +2889,9 @@ assert_eq!(0x10", stringify!($SelfT), ".checked_shr(129), None);", $EndFeature,
2889
2889
#[ must_use = "this returns the result of the operation, \
2890
2890
without modifying the original"]
2891
2891
#[ inline]
2892
- pub fn checked_shr( self , rhs: u32 ) -> Option <Self > {
2892
+ pub const fn checked_shr( self , rhs: u32 ) -> Option <Self > {
2893
2893
let ( a, b) = self . overflowing_shr( rhs) ;
2894
- if b { None } else { Some ( a) }
2894
+ [ Some ( a) , None ] [ b as usize ]
2895
2895
}
2896
2896
}
2897
2897
0 commit comments