]> git.lizzy.rs Git - rust.git/commit
Fix std::ops::Range size_hint and ExactSizeIterator impls
authorUlrik Sverdrup <root@localhost>
Sat, 7 Feb 2015 23:17:04 +0000 (00:17 +0100)
committerUlrik Sverdrup <root@localhost>
Sat, 7 Feb 2015 23:17:04 +0000 (00:17 +0100)
commit4f61e160326676cdcce94b9d5bca7d88c5f40ee9
tree3445e5ff2b784552c7966cba0a91b14a95f47cfb
parentce5aad2f107e79c5f1baab40aff35b7899322d94
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.
src/libcore/iter.rs
src/libcoretest/iter.rs