about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTobias Bucher <tobiasbucher5991@gmail.com>2014-08-08 22:45:50 +0200
committerTobias Bucher <tobiasbucher5991@gmail.com>2014-08-08 22:45:50 +0200
commitcd6eb122707f5f6dddffd871e9e54c4561e4e5f0 (patch)
treec5af4b97240c2e0f8864f07227111899caeea72e
parent3b1f983584218fb9c2d1274e0361bca89c25e8a9 (diff)
downloadrust-cd6eb122707f5f6dddffd871e9e54c4561e4e5f0.tar.gz
rust-cd6eb122707f5f6dddffd871e9e54c4561e4e5f0.zip
Add division by zero case to the `CheckedDiv` comment
-rw-r--r--src/libcore/num/mod.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs
index 2b7249aca12..42f74ab429a 100644
--- a/src/libcore/num/mod.rs
+++ b/src/libcore/num/mod.rs
@@ -1345,10 +1345,11 @@ checked_impl!(CheckedMul, checked_mul, i16, intrinsics::i16_mul_with_overflow)
 checked_impl!(CheckedMul, checked_mul, i32, intrinsics::i32_mul_with_overflow)
 checked_impl!(CheckedMul, checked_mul, i64, intrinsics::i64_mul_with_overflow)
 
-/// Performs division that returns `None` instead of wrapping around on underflow or overflow.
+/// Performs division that returns `None` instead of failing on division by zero and instead of
+/// wrapping around on underflow and overflow.
 pub trait CheckedDiv: Div<Self, Self> {
-    /// Divides two numbers, checking for underflow or overflow. If underflow or overflow happens,
-    /// `None` is returned.
+    /// Divides two numbers, checking for underflow, overflow and division by zero. If any of that
+    /// happens, / `None` is returned.
     ///
     /// # Example
     ///
@@ -1356,6 +1357,7 @@ pub trait CheckedDiv: Div<Self, Self> {
     /// use std::num::CheckedDiv;
     /// assert_eq!((-127i8).checked_div(&-1), Some(127));
     /// assert_eq!((-128i8).checked_div(&-1), None);
+    /// assert_eq!((1i8).checked_div(&0), None);
     /// ```
     fn checked_div(&self, v: &Self) -> Option<Self>;
 }