@@ -259,12 +259,13 @@ macro_rules! step_integer_impls {
259
259
step_unsigned_methods!( ) ;
260
260
261
261
#[ inline]
262
- fn steps_between( start: & Self , end: & Self ) -> ( usize , Option <usize >) {
262
+ fn steps_between( start: & Self , end: & Self ) -> ( usize , Option <usize >) {
263
263
if * start <= * end {
264
264
// This relies on $u_narrower <= usize
265
- ( ( * end-* start) as usize , Some ( ( * end - * start) as usize ) )
265
+ let steps = ( * end - * start) as usize ;
266
+ ( steps, Some ( steps) )
266
267
} else {
267
- ( 0 , None )
268
+ ( 0 , None )
268
269
}
269
270
}
270
271
@@ -299,7 +300,8 @@ macro_rules! step_integer_impls {
299
300
// Casting to isize extends the width but preserves the sign.
300
301
// Use wrapping_sub in isize space and cast to usize to compute
301
302
// the difference that might not fit inside the range of isize.
302
- ( ( * end as isize ) . wrapping_sub( * start as isize ) as usize , Some ( ( * end as isize ) . wrapping_sub( * start as isize ) as usize ) )
303
+ let steps = ( * end as isize ) . wrapping_sub( * start as isize ) as usize ;
304
+ ( steps, Some ( steps) )
303
305
} else {
304
306
( 0 , None )
305
307
}
@@ -707,7 +709,7 @@ impl<A: Step> RangeIteratorImpl for ops::Range<A> {
707
709
#[ inline]
708
710
default fn spec_advance_by ( & mut self , n : usize ) -> Result < ( ) , NonZero < usize > > {
709
711
let steps = Step :: steps_between ( & self . start , & self . end ) ;
710
- let available = if let Some ( steps) = steps . 1 { steps } else { steps . 0 } ;
712
+ let available = steps. 1 . unwrap_or ( steps. 0 ) ;
711
713
712
714
let taken = available. min ( n) ;
713
715
@@ -745,7 +747,7 @@ impl<A: Step> RangeIteratorImpl for ops::Range<A> {
745
747
#[ inline]
746
748
default fn spec_advance_back_by ( & mut self , n : usize ) -> Result < ( ) , NonZero < usize > > {
747
749
let steps = Step :: steps_between ( & self . start , & self . end ) ;
748
- let available = if let Some ( steps) = steps . 1 { steps } else { steps . 0 } ;
750
+ let available = steps. 1 . unwrap_or ( steps. 0 ) ;
749
751
750
752
let taken = available. min ( n) ;
751
753
@@ -786,7 +788,7 @@ impl<T: TrustedStep> RangeIteratorImpl for ops::Range<T> {
786
788
#[ inline]
787
789
fn spec_advance_by ( & mut self , n : usize ) -> Result < ( ) , NonZero < usize > > {
788
790
let steps = Step :: steps_between ( & self . start , & self . end ) ;
789
- let available = if let Some ( steps) = steps . 1 { steps } else { steps . 0 } ;
791
+ let available = steps. 1 . unwrap_or ( steps. 0 ) ;
790
792
791
793
let taken = available. min ( n) ;
792
794
@@ -827,7 +829,7 @@ impl<T: TrustedStep> RangeIteratorImpl for ops::Range<T> {
827
829
#[ inline]
828
830
fn spec_advance_back_by ( & mut self , n : usize ) -> Result < ( ) , NonZero < usize > > {
829
831
let steps = Step :: steps_between ( & self . start , & self . end ) ;
830
- let available = if let Some ( steps) = steps . 1 { steps } else { steps . 0 } ;
832
+ let available = steps. 1 . unwrap_or ( steps. 0 ) ;
831
833
832
834
let taken = available. min ( n) ;
833
835
@@ -850,9 +852,9 @@ impl<A: Step> Iterator for ops::Range<A> {
850
852
#[ inline]
851
853
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
852
854
if self . start < self . end {
853
- ( 0 , Some ( 0 ) )
854
- } else {
855
855
Step :: steps_between ( & self . start , & self . end )
856
+ } else {
857
+ ( 0 , Some ( 0 ) )
856
858
}
857
859
}
858
860
0 commit comments