diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index bc5bbc2217cd3..7b273f7862a1f 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -2109,8 +2109,12 @@ impl Iterator for TakeWhile #[inline] fn size_hint(&self) -> (usize, Option) { - let (_, upper) = self.iter.size_hint(); - (0, upper) // can't know a lower bound, due to the predicate + if self.flag { + (0, Some(0)) + } else { + let (_, upper) = self.iter.size_hint(); + (0, upper) // can't know a lower bound, due to the predicate + } } #[inline] @@ -2321,6 +2325,10 @@ impl Iterator for Take where I: Iterator{ #[inline] fn size_hint(&self) -> (usize, Option) { + if self.n == 0 { + return (0, Some(0)); + } + let (lower, upper) = self.iter.size_hint(); let lower = cmp::min(lower, self.n);