about summary refs log tree commit diff
path: root/src/libcoretest
diff options
context:
space:
mode:
authorUlrik Sverdrup <root@localhost>2015-02-08 00:17:04 +0100
committerUlrik Sverdrup <root@localhost>2015-02-08 00:17:04 +0100
commit4f61e160326676cdcce94b9d5bca7d88c5f40ee9 (patch)
tree3445e5ff2b784552c7966cba0a91b14a95f47cfb /src/libcoretest
parentce5aad2f107e79c5f1baab40aff35b7899322d94 (diff)
downloadrust-4f61e160326676cdcce94b9d5bca7d88c5f40ee9.tar.gz
rust-4f61e160326676cdcce94b9d5bca7d88c5f40ee9.zip
Fix std::ops::Range size_hint and ExactSizeIterator impls
When self.start > self.end, these iterators simply return None,
so we adjust the size_hint to just return zero in this case.

Certain optimizations can be implemented in and outside libstd if we
know we can trust the size_hint for all inputs to for example
Range<usize>.

This corrects the ExactSizeIterator implementations, which IMO were
unsound and incorrect previously, since they allowed a range like (2..1)
to return a size_hint of -1us in when debug assertions are turned off.
Diffstat (limited to 'src/libcoretest')
-rw-r--r--src/libcoretest/iter.rs1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs
index c9cdf50fdbd..3f8e330b332 100644
--- a/src/libcoretest/iter.rs
+++ b/src/libcoretest/iter.rs
@@ -756,6 +756,7 @@ fn test_range() {
     // this test is only meaningful when sizeof uint < sizeof u64
     assert_eq!((uint::MAX - 1..uint::MAX).size_hint(), (1, Some(1)));
     assert_eq!((-10..-1).size_hint(), (9, Some(9)));
+    assert_eq!((-1..-10).size_hint(), (0, Some(0)));
 }
 
 #[test]