diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2017-05-30 09:15:25 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2017-05-30 09:15:25 -0700 |
| commit | 265dce66b6b1181f4b955032b742c702c753f6c8 (patch) | |
| tree | 5270d39833685a2f986dfe1598a252fd63ccdd53 | |
| parent | 920c4799bead614c21b12ba396afe19cb70730f3 (diff) | |
| download | rust-265dce66b6b1181f4b955032b742c702c753f6c8.tar.gz rust-265dce66b6b1181f4b955032b742c702c753f6c8.zip | |
RangeFrom should have an infinite size_hint
This makes the size_hint from things like `take` more precise.
| -rw-r--r-- | src/libcore/iter/iterator.rs | 3 | ||||
| -rw-r--r-- | src/libcore/iter/range.rs | 5 | ||||
| -rw-r--r-- | src/libcore/tests/iter.rs | 1 |
3 files changed, 8 insertions, 1 deletions
diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs index 77cbdb98c83..85149a0f570 100644 --- a/src/libcore/iter/iterator.rs +++ b/src/libcore/iter/iterator.rs @@ -130,9 +130,10 @@ pub trait Iterator { /// /// ``` /// // an infinite iterator has no upper bound + /// // and the maximum possible lower bound /// let iter = 0..; /// - /// assert_eq!((0, None), iter.size_hint()); + /// assert_eq!((usize::max_value(), None), iter.size_hint()); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs index e02823fd812..c0313333ea9 100644 --- a/src/libcore/iter/range.rs +++ b/src/libcore/iter/range.rs @@ -543,6 +543,11 @@ impl<A: Step> Iterator for ops::RangeFrom<A> where mem::swap(&mut n, &mut self.start); Some(n) } + + #[inline] + fn size_hint(&self) -> (usize, Option<usize>) { + (usize::MAX, None) + } } #[unstable(feature = "fused", issue = "35602")] diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index 4030eaf2b23..44d5936c63e 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -764,6 +764,7 @@ fn test_iterator_size_hint() { let v2 = &[10, 11, 12]; let vi = v.iter(); + assert_eq!((0..).size_hint(), (usize::MAX, None)); assert_eq!(c.size_hint(), (usize::MAX, None)); assert_eq!(vi.clone().size_hint(), (10, Some(10))); |
