Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7e3d4c3

Browse files
committedNov 8, 2024·
fixed format
1 parent 4ab4aa8 commit 7e3d4c3

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed
 

‎library/core/src/iter/range.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,13 @@ macro_rules! step_integer_impls {
259259
step_unsigned_methods!();
260260

261261
#[inline]
262-
fn steps_between(start: &Self, end: &Self) -> (usize,Option<usize>) {
262+
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
263263
if *start <= *end {
264264
// 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))
266267
} else {
267-
(0,None)
268+
(0, None)
268269
}
269270
}
270271

@@ -299,7 +300,8 @@ macro_rules! step_integer_impls {
299300
// Casting to isize extends the width but preserves the sign.
300301
// Use wrapping_sub in isize space and cast to usize to compute
301302
// 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))
303305
} else {
304306
(0,None)
305307
}
@@ -707,7 +709,7 @@ impl<A: Step> RangeIteratorImpl for ops::Range<A> {
707709
#[inline]
708710
default fn spec_advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
709711
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);
711713

712714
let taken = available.min(n);
713715

@@ -745,7 +747,7 @@ impl<A: Step> RangeIteratorImpl for ops::Range<A> {
745747
#[inline]
746748
default fn spec_advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
747749
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);
749751

750752
let taken = available.min(n);
751753

@@ -786,7 +788,7 @@ impl<T: TrustedStep> RangeIteratorImpl for ops::Range<T> {
786788
#[inline]
787789
fn spec_advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
788790
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);
790792

791793
let taken = available.min(n);
792794

@@ -827,7 +829,7 @@ impl<T: TrustedStep> RangeIteratorImpl for ops::Range<T> {
827829
#[inline]
828830
fn spec_advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
829831
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);
831833

832834
let taken = available.min(n);
833835

@@ -850,9 +852,9 @@ impl<A: Step> Iterator for ops::Range<A> {
850852
#[inline]
851853
fn size_hint(&self) -> (usize, Option<usize>) {
852854
if self.start < self.end {
853-
(0, Some(0))
854-
} else {
855855
Step::steps_between(&self.start, &self.end)
856+
} else {
857+
(0, Some(0))
856858
}
857859
}
858860

0 commit comments

Comments
 (0)
Please sign in to comment.