File tree 2 files changed +6
-3
lines changed
2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -2166,15 +2166,17 @@ macro_rules! int_impl {
2166
2166
2167
2167
let r = try_opt!( self . checked_rem( rhs) ) ;
2168
2168
let m = if ( r > 0 && rhs < 0 ) || ( r < 0 && rhs > 0 ) {
2169
- try_opt!( r. checked_add( rhs) )
2169
+ // r + rhs cannot overflow because they have opposite signs
2170
+ r + rhs
2170
2171
} else {
2171
2172
r
2172
2173
} ;
2173
2174
2174
2175
if m == 0 {
2175
2176
Some ( self )
2176
2177
} else {
2177
- self . checked_add( try_opt!( rhs. checked_sub( m) ) )
2178
+ // rhs - m cannot overflow because m has the same sign as rhs
2179
+ self . checked_add( rhs - m)
2178
2180
}
2179
2181
}
2180
2182
Original file line number Diff line number Diff line change @@ -2119,7 +2119,8 @@ macro_rules! uint_impl {
2119
2119
pub const fn checked_next_multiple_of( self , rhs: Self ) -> Option <Self > {
2120
2120
match try_opt!( self . checked_rem( rhs) ) {
2121
2121
0 => Some ( self ) ,
2122
- r => self . checked_add( try_opt!( rhs. checked_sub( r) ) )
2122
+ // rhs - r cannot overflow because r is smaller than rhs
2123
+ r => self . checked_add( rhs - r)
2123
2124
}
2124
2125
}
2125
2126
You can’t perform that action at this time.
0 commit comments