diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs
index 64933d0acf56446a84fbeb1beaba73f0f5490d40..e37e52c6dc3e0a5f1c3aca0f2d3870f2e452cc00 100644
--- a/src/libcore/iter.rs
+++ b/src/libcore/iter.rs
@@ -4605,8 +4605,10 @@ fn next(&mut self) -> Option {
Empty { .. } => (None, None), // empty iterators yield no values
NonEmpty { ref mut start, ref mut end } => {
- let one = A::one();
- if start <= end {
+ if start == end {
+ (Some(mem::replace(end, A::one())), Some(mem::replace(start, A::one())))
+ } else if start < end {
+ let one = A::one();
let mut n = &*start + &one;
mem::swap(&mut n, start);
@@ -4620,7 +4622,7 @@ fn next(&mut self) -> Option {
// ^ are we done yet?
Some(n)) // < the value to output
} else {
- (Some(mem::replace(start, one)), None)
+ (Some(mem::replace(start, A::one())), None)
}
}
};
@@ -4664,15 +4666,17 @@ fn next_back(&mut self) -> Option {
Empty { .. } => return None,
NonEmpty { ref mut start, ref mut end } => {
- let one = A::one();
- if start <= end {
+ if start == end {
+ (Some(mem::replace(start, A::one())), Some(mem::replace(end, A::one())))
+ } else if start < end {
+ let one = A::one();
let mut n = &*end - &one;
mem::swap(&mut n, end);
(if n == *start { Some(mem::replace(start, one)) } else { None },
Some(n))
} else {
- (Some(mem::replace(end, one)), None)
+ (Some(mem::replace(end, A::one())), None)
}
}
};