Fix behaviour after iterator exhaustion
This commit is contained in:
parent
439beab41f
commit
c23d4500fd
2 changed files with 20 additions and 5 deletions
|
|
@ -377,17 +377,23 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
|
|||
|
||||
#[inline]
|
||||
fn last(self) -> Option<A> {
|
||||
Some(self.end)
|
||||
if self.start <= self.end {
|
||||
Some(self.end)
|
||||
} else { None }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn min(self) -> Option<A> {
|
||||
Some(self.start)
|
||||
if self.start <= self.end {
|
||||
Some(self.start)
|
||||
} else { None }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn max(self) -> Option<A> {
|
||||
Some(self.end)
|
||||
if self.start <= self.end {
|
||||
Some(self.end)
|
||||
} else { None }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1360,21 +1360,30 @@ fn test_range_max() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_inc_last_max() {
|
||||
fn test_range_inclusive_last_max() {
|
||||
assert_eq!((0..=20).last(), Some(20));
|
||||
assert_eq!((-20..=0).last(), Some(0));
|
||||
assert_eq!((5..=5).last(), Some(5));
|
||||
let mut r = 10..=10;
|
||||
r.next();
|
||||
assert_eq!(r.last(), None);
|
||||
|
||||
assert_eq!((0..=20).max(), Some(20));
|
||||
assert_eq!((-20..=0).max(), Some(0));
|
||||
assert_eq!((5..=5).max(), Some(5));
|
||||
let mut r = 10..=10;
|
||||
r.next();
|
||||
assert_eq!(r.max(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_inc_min() {
|
||||
fn test_range_inclusive_min() {
|
||||
assert_eq!((0..=20).min(), Some(0));
|
||||
assert_eq!((-20..=0).min(), Some(-20));
|
||||
assert_eq!((5..=5).min(), Some(5));
|
||||
let mut r = 10..=10;
|
||||
r.next();
|
||||
assert_eq!(r.min(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue