提交 d9d5c667 编写于 作者: K kennytm 提交者: GitHub

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.
......@@ -439,7 +439,7 @@ pub fn checked_mul(self, rhs: Self) -> Option<Self> {
}
/// 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 @@ pub fn checked_div(self, rhs: Self) -> Option<Self> {
}
/// 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 @@ pub fn checked_mul(self, rhs: Self) -> Option<Self> {
}
/// 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 @@ pub fn checked_div(self, rhs: Self) -> Option<Self> {
}
/// Checked integer remainder. Computes `self % rhs`, returning `None`
/// if `rhs == 0` or the operation results in overflow.
/// if `rhs == 0`.
///
/// # Examples
///
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册