@@ -516,11 +516,10 @@ macro_rules! int_impl {
516
516
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
517
517
#[ inline]
518
518
pub fn checked_div( self , other: Self ) -> Option <Self > {
519
- if other == 0 {
519
+ if other == 0 || ( self == Self :: min_value ( ) && other == - 1 ) {
520
520
None
521
521
} else {
522
- let ( a, b) = self . overflowing_div( other) ;
523
- if b { None } else { Some ( a) }
522
+ Some ( unsafe { intrinsics:: unchecked_div( self , other) } )
524
523
}
525
524
}
526
525
@@ -541,11 +540,10 @@ macro_rules! int_impl {
541
540
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
542
541
#[ inline]
543
542
pub fn checked_rem( self , other: Self ) -> Option <Self > {
544
- if other == 0 {
543
+ if other == 0 || ( self == Self :: min_value ( ) && other == - 1 ) {
545
544
None
546
545
} else {
547
- let ( a, b) = self . overflowing_rem( other) ;
548
- if b { None } else { Some ( a) }
546
+ Some ( unsafe { intrinsics:: unchecked_rem( self , other) } )
549
547
}
550
548
}
551
549
@@ -1688,7 +1686,7 @@ macro_rules! uint_impl {
1688
1686
pub fn checked_div( self , other: Self ) -> Option <Self > {
1689
1687
match other {
1690
1688
0 => None ,
1691
- other => Some ( self / other) ,
1689
+ other => Some ( unsafe { intrinsics :: unchecked_div ( self , other) } ) ,
1692
1690
}
1693
1691
}
1694
1692
@@ -1709,7 +1707,7 @@ macro_rules! uint_impl {
1709
1707
if other == 0 {
1710
1708
None
1711
1709
} else {
1712
- Some ( self % other)
1710
+ Some ( unsafe { intrinsics :: unchecked_rem ( self , other) } )
1713
1711
}
1714
1712
}
1715
1713
0 commit comments