Skip to content

Commit e92f633

Browse files
committed
Fix checked operations documentation.
Remove the implication that wrapping is the default behaviour.
1 parent b1f3bda commit e92f633

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/ops/checked.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use core::ops::{Add, Div, Mul, Rem, Shl, Shr, Sub};
22

3-
/// Performs addition that returns `None` instead of wrapping around on
4-
/// overflow.
3+
/// Performs addition, returning `None` if overflow occurred.
54
pub trait CheckedAdd: Sized + Add<Self, Output = Self> {
65
/// Adds two numbers, checking for overflow. If overflow happens, `None` is
76
/// returned.
@@ -33,7 +32,7 @@ checked_impl!(CheckedAdd, checked_add, i64);
3332
checked_impl!(CheckedAdd, checked_add, isize);
3433
checked_impl!(CheckedAdd, checked_add, i128);
3534

36-
/// Performs subtraction that returns `None` instead of wrapping around on underflow.
35+
/// Performs subtraction, returning `None` if underflow occurred.
3736
pub trait CheckedSub: Sized + Sub<Self, Output = Self> {
3837
/// Subtracts two numbers, checking for underflow. If underflow happens,
3938
/// `None` is returned.
@@ -54,8 +53,8 @@ checked_impl!(CheckedSub, checked_sub, i64);
5453
checked_impl!(CheckedSub, checked_sub, isize);
5554
checked_impl!(CheckedSub, checked_sub, i128);
5655

57-
/// Performs multiplication that returns `None` instead of wrapping around on underflow or
58-
/// overflow.
56+
/// Performs multiplication, returning `None` if underflow or overflow
57+
/// occurred.
5958
pub trait CheckedMul: Sized + Mul<Self, Output = Self> {
6059
/// Multiplies two numbers, checking for underflow or overflow. If underflow
6160
/// or overflow happens, `None` is returned.
@@ -76,8 +75,8 @@ checked_impl!(CheckedMul, checked_mul, i64);
7675
checked_impl!(CheckedMul, checked_mul, isize);
7776
checked_impl!(CheckedMul, checked_mul, i128);
7877

79-
/// Performs division that returns `None` instead of panicking on division by zero and instead of
80-
/// wrapping around on underflow and overflow.
78+
/// Performs division, returning `None` on division by zero or if underflow or
79+
/// overflow occurred.
8180
pub trait CheckedDiv: Sized + Div<Self, Output = Self> {
8281
/// Divides two numbers, checking for underflow, overflow and division by
8382
/// zero. If any of that happens, `None` is returned.
@@ -98,8 +97,8 @@ checked_impl!(CheckedDiv, checked_div, i64);
9897
checked_impl!(CheckedDiv, checked_div, isize);
9998
checked_impl!(CheckedDiv, checked_div, i128);
10099

101-
/// Performs an integral remainder that returns `None` instead of panicking on division by zero and
102-
/// instead of wrapping around on underflow and overflow.
100+
/// Performs integral remainder, returning `None` on division by zero or if
101+
/// underflow or overflow occurred.
103102
pub trait CheckedRem: Sized + Rem<Self, Output = Self> {
104103
/// Finds the remainder of dividing two numbers, checking for underflow, overflow and division
105104
/// by zero. If any of that happens, `None` is returned.
@@ -148,7 +147,7 @@ macro_rules! checked_impl_unary {
148147
};
149148
}
150149

151-
/// Performs negation that returns `None` if the result can't be represented.
150+
/// Performs negation, returning `None` if the result can't be represented.
152151
pub trait CheckedNeg: Sized {
153152
/// Negates a number, returning `None` for results that can't be represented, like signed `MIN`
154153
/// values that can't be positive, or non-zero unsigned values that can't be negative.
@@ -183,8 +182,8 @@ checked_impl_unary!(CheckedNeg, checked_neg, i64);
183182
checked_impl_unary!(CheckedNeg, checked_neg, isize);
184183
checked_impl_unary!(CheckedNeg, checked_neg, i128);
185184

186-
/// Performs a left shift that returns `None` on shifts larger than
187-
/// or equal to the type width.
185+
/// Performs shift left, returning `None` on shifts larger than or equal to
186+
/// the type width.
188187
pub trait CheckedShl: Sized + Shl<u32, Output = Self> {
189188
/// Checked shift left. Computes `self << rhs`, returning `None`
190189
/// if `rhs` is larger than or equal to the number of bits in `self`.
@@ -227,8 +226,8 @@ checked_shift_impl!(CheckedShl, checked_shl, i64);
227226
checked_shift_impl!(CheckedShl, checked_shl, isize);
228227
checked_shift_impl!(CheckedShl, checked_shl, i128);
229228

230-
/// Performs a right shift that returns `None` on shifts larger than
231-
/// or equal to the type width.
229+
/// Performs shift right, returning `None` on shifts larger than or equal to
230+
/// the type width.
232231
pub trait CheckedShr: Sized + Shr<u32, Output = Self> {
233232
/// Checked shift right. Computes `self >> rhs`, returning `None`
234233
/// if `rhs` is larger than or equal to the number of bits in `self`.

0 commit comments

Comments
 (0)