Skip to content

Commit

Permalink
remove under/overflow from next_back/next
Browse files Browse the repository at this point in the history
  • Loading branch information
durka committed Mar 4, 2016
1 parent a928c83 commit 430b3e1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/libcore/iter.rs
Expand Up @@ -4605,8 +4605,10 @@ impl<A: Step + One> Iterator for ops::RangeInclusive<A> where
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);

Expand All @@ -4620,7 +4622,7 @@ impl<A: Step + One> Iterator for ops::RangeInclusive<A> where
// ^ are we done yet?
Some(n)) // < the value to output
} else {
(Some(mem::replace(start, one)), None)
(Some(mem::replace(start, A::one())), None)
}
}
};
Expand Down Expand Up @@ -4664,15 +4666,17 @@ impl<A: Step + One> DoubleEndedIterator for ops::RangeInclusive<A> where
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)
}
}
};
Expand Down

0 comments on commit 430b3e1

Please sign in to comment.