about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-01-07 02:36:01 +0800
committerGitHub <noreply@github.com>2018-01-07 02:36:01 +0800
commitd9d5c667d819ce400fc7adb09dcd6482b0aa519e (patch)
treea8744dbcd1b848017387e82cfd161d9fa3d576c4
parent72176cf96cb79a0ebf62972b76dbe68c933bef4d (diff)
parentf2c5472ed5dd2b38711375c469c54536e51e9cf3 (diff)
Rollup merge of #46947 - tspiteri:checked-div-rem-none, r=frewsxcv
doc: improve None condition doc for `checked_div` and `checked_rem`

This commit improves the condition mentioned in the docs for which `checked_div` and `checked_rem` return `None`.

For signed division, the commit changes "the operation results in overflow" to "the division results in overflow", otherwise there is room for misinterpretation for `checked_rem`: Without considering overflow, `MIN % -1` would be simply zero, allowing the misinterpretation that "the operation" does not result in overflow in this case. This ambiguity is removed using "when the division results in overflow".

For unsigned division, the condition for `None` should be simply when `rhs == 0`, as no other overflow is possible.
-rw-r--r--src/libcore/num/mod.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs
index b89aa134e73..b5d24203b5e 100644
--- a/src/libcore/num/mod.rs
+++ b/src/libcore/num/mod.rs
@@ -439,7 +439,7 @@ macro_rules! int_impl {
         }
 
         /// Checked integer division. Computes `self / rhs`, returning `None`
-        /// if `rhs == 0` or the operation results in overflow.
+        /// if `rhs == 0` or the division results in overflow.
         ///
         /// # Examples
         ///
@@ -461,7 +461,7 @@ macro_rules! int_impl {
         }
 
         /// Checked integer remainder. Computes `self % rhs`, returning `None`
-        /// if `rhs == 0` or the operation results in overflow.
+        /// if `rhs == 0` or the division results in overflow.
         ///
         /// # Examples
         ///
@@ -1607,7 +1607,7 @@ macro_rules! uint_impl {
         }
 
         /// Checked integer division. Computes `self / rhs`, returning `None`
-        /// if `rhs == 0` or the operation results in overflow.
+        /// if `rhs == 0`.
         ///
         /// # Examples
         ///
@@ -1627,7 +1627,7 @@ macro_rules! uint_impl {
         }
 
         /// Checked integer remainder. Computes `self % rhs`, returning `None`
-        /// if `rhs == 0` or the operation results in overflow.
+        /// if `rhs == 0`.
         ///
         /// # Examples
         ///