@@ -10,6 +10,16 @@ use crate::intrinsics;
10
10
use crate :: mem;
11
11
use crate :: str:: FromStr ;
12
12
13
+ // Used because the `?` operator is not allowed in a const context.
14
+ macro_rules! try_opt {
15
+ ( $e: expr) => {
16
+ match $e {
17
+ Some ( x) => x,
18
+ None => return None ,
19
+ }
20
+ } ;
21
+ }
22
+
13
23
macro_rules! impl_nonzero_fmt {
14
24
( #[ $stability: meta] ( $( $Trait: ident ) ,+ ) for $Ty: ident ) => {
15
25
$(
@@ -1000,17 +1010,17 @@ $EndFeature, "
1000
1010
1001
1011
while exp > 1 {
1002
1012
if ( exp & 1 ) == 1 {
1003
- acc = acc. checked_mul( base) ? ;
1013
+ acc = try_opt! ( acc. checked_mul( base) ) ;
1004
1014
}
1005
1015
exp /= 2 ;
1006
- base = base. checked_mul( base) ? ;
1016
+ base = try_opt! ( base. checked_mul( base) ) ;
1007
1017
}
1008
1018
1009
1019
// Deal with the final bit of the exponent separately, since
1010
1020
// squaring the base afterwards is not necessary and may cause a
1011
1021
// needless overflow.
1012
1022
if exp == 1 {
1013
- acc = acc. checked_mul( base) ? ;
1023
+ acc = try_opt! ( acc. checked_mul( base) ) ;
1014
1024
}
1015
1025
1016
1026
Some ( acc)
@@ -3126,17 +3136,17 @@ assert_eq!(", stringify!($SelfT), "::max_value().checked_pow(2), None);", $EndFe
3126
3136
3127
3137
while exp > 1 {
3128
3138
if ( exp & 1 ) == 1 {
3129
- acc = acc. checked_mul( base) ? ;
3139
+ acc = try_opt! ( acc. checked_mul( base) ) ;
3130
3140
}
3131
3141
exp /= 2 ;
3132
- base = base. checked_mul( base) ? ;
3142
+ base = try_opt! ( base. checked_mul( base) ) ;
3133
3143
}
3134
3144
3135
3145
// Deal with the final bit of the exponent separately, since
3136
3146
// squaring the base afterwards is not necessary and may cause a
3137
3147
// needless overflow.
3138
3148
if exp == 1 {
3139
- acc = acc. checked_mul( base) ? ;
3149
+ acc = try_opt! ( acc. checked_mul( base) ) ;
3140
3150
}
3141
3151
3142
3152
Some ( acc)
0 commit comments