We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
saturating_add
1 parent 1cc8b6e commit 5199a70Copy full SHA for 5199a70
src/libcore/str/mod.rs
@@ -432,7 +432,10 @@ impl<'a> Iterator for Chars<'a> {
432
#[inline]
433
fn size_hint(&self) -> (usize, Option<usize>) {
434
let (len, _) = self.iter.size_hint();
435
- (len.saturating_add(3) / 4, Some(len))
+ // `(len + 3)` can't overflow, because we know that the `slice::Iter`
436
+ // belongs to a slice in memory which has a maximum length of
437
+ // `isize::MAX` (that's well below `usize::MAX`).
438
+ ((len + 3) / 4, Some(len))
439
}
440
441
0 commit comments