File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -4665,19 +4665,23 @@ impl<A: Step + One> DoubleEndedIterator for ops::RangeInclusive<A> where
4665
4665
4666
4666
NonEmpty { ref mut start, ref mut end } => {
4667
4667
let one = A :: one ( ) ;
4668
- let mut n = & * end - & one;
4669
- mem:: swap ( & mut n, end) ;
4668
+ if start <= end {
4669
+ let mut n = & * end - & one;
4670
+ mem:: swap ( & mut n, end) ;
4670
4671
4671
- ( if n == * start { Some ( mem:: replace ( start, one) ) } else { None } ,
4672
- n)
4672
+ ( if n == * start { Some ( mem:: replace ( start, one) ) } else { None } ,
4673
+ Some ( n) )
4674
+ } else {
4675
+ ( Some ( mem:: replace ( end, one) ) , None )
4676
+ }
4673
4677
}
4674
4678
} ;
4675
4679
4676
4680
if let Some ( start) = finishing {
4677
4681
* self = Empty { at : start } ;
4678
4682
}
4679
4683
4680
- Some ( n )
4684
+ n
4681
4685
}
4682
4686
}
4683
4687
Original file line number Diff line number Diff line change @@ -99,6 +99,11 @@ pub fn main() {
99
99
}
100
100
assert_eq ! ( long, RangeInclusive :: Empty { at: 251 } ) ;
101
101
102
+ // check underflow
103
+ let mut narrow = 1 ...0 ;
104
+ assert_eq ! ( narrow. next_back( ) , None ) ;
105
+ assert_eq ! ( narrow, RangeInclusive :: Empty { at: 0 } ) ;
106
+
102
107
// what happens if you have a nonsense range?
103
108
let mut nonsense = 10 ...5 ;
104
109
assert_eq ! ( nonsense. next( ) , None ) ;
You can’t perform that action at this time.
0 commit comments