use checked_add for upper bound

This commit is contained in:
Yuri Astrakhan 2024-01-25 20:56:52 -05:00
parent 8cbff0b426
commit 77f31ef2b2

View File

@ -200,10 +200,10 @@ fn intersperse_size_hint<I>(iter: &I, started: bool, next_is_some: bool) -> (usi
lo.saturating_sub(!started as usize) lo.saturating_sub(!started as usize)
.saturating_add(next_is_some as usize) .saturating_add(next_is_some as usize)
.saturating_add(lo), .saturating_add(lo),
hi.map(|hi| { hi.and_then(|hi| {
hi.saturating_sub(!started as usize) hi.saturating_sub(!started as usize)
.saturating_add(next_is_some as usize) .saturating_add(next_is_some as usize)
.saturating_add(hi) .checked_add(hi)
}), }),
) )
} }