Replace underflow with overflow in doc comments
The use of underflow is misleading. Adding one to MAX and subtracting one from MIN are both considered an overflow.
This commit is contained in:
parent
2f897e2109
commit
a273814d23
|
@ -231,7 +231,7 @@ impl<'a> InstructionIndices<'a> {
|
||||||
let prev_remaining = self.remaining_bytes();
|
let prev_remaining = self.remaining_bytes();
|
||||||
let prev_pos = self.pos;
|
let prev_pos = self.pos;
|
||||||
let instruction = next_fn(self)?;
|
let instruction = next_fn(self)?;
|
||||||
// No underflow: there must be less remaining bytes now than previously
|
// No overflow: there must be less remaining bytes now than previously
|
||||||
let consumed = prev_remaining - self.remaining_bytes();
|
let consumed = prev_remaining - self.remaining_bytes();
|
||||||
// No overflow: sum will never exceed slice length which itself can't exceed `usize`
|
// No overflow: sum will never exceed slice length which itself can't exceed `usize`
|
||||||
self.pos += consumed;
|
self.pos += consumed;
|
||||||
|
|
|
@ -217,7 +217,7 @@ mod into_iter {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
// can't underflow thanks to the invariant
|
// can't overflow thanks to the invariant
|
||||||
let len = self.signature.len() - self.pos;
|
let len = self.signature.len() - self.pos;
|
||||||
(len, Some(len))
|
(len, Some(len))
|
||||||
}
|
}
|
||||||
|
|
|
@ -588,8 +588,8 @@ enum DisplayStyle {
|
||||||
|
|
||||||
/// Calculates the sum over the iterator using checked arithmetic.
|
/// Calculates the sum over the iterator using checked arithmetic.
|
||||||
pub trait CheckedSum<R>: sealed::Sealed<R> {
|
pub trait CheckedSum<R>: sealed::Sealed<R> {
|
||||||
/// Calculates the sum over the iterator using checked arithmetic. If an over or underflow would
|
/// Calculates the sum over the iterator using checked arithmetic. If an
|
||||||
/// happen it returns [`None`].
|
/// overflow happens it returns [`None`].
|
||||||
fn checked_sum(self) -> Option<R>;
|
fn checked_sum(self) -> Option<R>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,10 @@ use super::{
|
||||||
/// Warning!
|
/// Warning!
|
||||||
///
|
///
|
||||||
/// This type implements several arithmetic operations from [`core::ops`].
|
/// This type implements several arithmetic operations from [`core::ops`].
|
||||||
/// To prevent errors due to overflow or underflow when using these operations,
|
/// To prevent errors due to an overflow when using these operations,
|
||||||
/// it is advised to instead use the checked arithmetic methods whose names
|
/// it is advised to instead use the checked arithmetic methods whose names
|
||||||
/// start with `checked_`. The operations from [`core::ops`] that [`SignedAmount`]
|
/// start with `checked_`. The operations from [`core::ops`] that [`SignedAmount`]
|
||||||
/// implements will panic when overflow or underflow occurs.
|
/// implements will panic when an overflow occurs.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue