macro_rules! range_exact_iter_impl {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
- impl ExactSizeIterator for ::ops::Range<$t> {
- #[inline]
- fn len(&self) -> usize {
- debug_assert!(self.end >= self.start);
- (self.end - self.start) as usize
- }
- }
+ impl ExactSizeIterator for ::ops::Range<$t> { }
)*)
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
- debug_assert!(self.end >= self.start);
- let hint = (self.end - self.start).to_uint();
- (hint.unwrap_or(0), hint)
+ if self.start >= self.end {
+ (0, Some(0))
+ } else {
+ let length = (self.end - self.start).to_uint();
+ (length.unwrap_or(0), length)
+ }
}
}
// 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]