From 77f31ef2b29e0ff16b9db8907327741c057bea8e Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 25 Jan 2024 20:56:52 -0500 Subject: [PATCH] use checked_add for upper bound --- library/core/src/iter/adapters/intersperse.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/iter/adapters/intersperse.rs b/library/core/src/iter/adapters/intersperse.rs index f436fe02dca..c97a59b614f 100644 --- a/library/core/src/iter/adapters/intersperse.rs +++ b/library/core/src/iter/adapters/intersperse.rs @@ -200,10 +200,10 @@ fn intersperse_size_hint(iter: &I, started: bool, next_is_some: bool) -> (usi lo.saturating_sub(!started as usize) .saturating_add(next_is_some as usize) .saturating_add(lo), - hi.map(|hi| { + hi.and_then(|hi| { hi.saturating_sub(!started as usize) .saturating_add(next_is_some as usize) - .saturating_add(hi) + .checked_add(hi) }), ) }