File tree Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Expand file tree Collapse file tree 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 {
21662166
21672167 let r = try_opt!( self . checked_rem( rhs) ) ;
21682168 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
21702171 } else {
21712172 r
21722173 } ;
21732174
21742175 if m == 0 {
21752176 Some ( self )
21762177 } 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)
21782180 }
21792181 }
21802182
Original file line number Diff line number Diff line change @@ -2119,7 +2119,8 @@ macro_rules! uint_impl {
21192119 pub const fn checked_next_multiple_of( self , rhs: Self ) -> Option <Self > {
21202120 match try_opt!( self . checked_rem( rhs) ) {
21212121 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)
21232124 }
21242125 }
21252126
You can’t perform that action at this time.
0 commit comments