Skip to content

Commit d16a5cd

Browse files
committed
auto merge of #16364 : tbu-/rust/pr_checkeddiv0, r=alexcrichton
2 parents dee8313 + cd6eb12 commit d16a5cd

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/libcore/num/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1345,17 +1345,19 @@ checked_impl!(CheckedMul, checked_mul, i16, intrinsics::i16_mul_with_overflow)
13451345
checked_impl!(CheckedMul, checked_mul, i32, intrinsics::i32_mul_with_overflow)
13461346
checked_impl!(CheckedMul, checked_mul, i64, intrinsics::i64_mul_with_overflow)
13471347

1348-
/// Performs division that returns `None` instead of wrapping around on underflow or overflow.
1348+
/// Performs division that returns `None` instead of failing on division by zero and instead of
1349+
/// wrapping around on underflow and overflow.
13491350
pub trait CheckedDiv: Div<Self, Self> {
1350-
/// Divides two numbers, checking for underflow or overflow. If underflow or overflow happens,
1351-
/// `None` is returned.
1351+
/// Divides two numbers, checking for underflow, overflow and division by zero. If any of that
1352+
/// happens, / `None` is returned.
13521353
///
13531354
/// # Example
13541355
///
13551356
/// ```rust
13561357
/// use std::num::CheckedDiv;
13571358
/// assert_eq!((-127i8).checked_div(&-1), Some(127));
13581359
/// assert_eq!((-128i8).checked_div(&-1), None);
1360+
/// assert_eq!((1i8).checked_div(&0), None);
13591361
/// ```
13601362
fn checked_div(&self, v: &Self) -> Option<Self>;
13611363
}

0 commit comments

Comments
 (0)