Skip to content

Commit 2d83343

Browse files
committed
Use next and next_back
1 parent c23d450 commit 2d83343

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/libcore/iter/range.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,8 @@ impl<A: Step> Iterator for ops::Range<A> {
253253
}
254254

255255
#[inline]
256-
fn max(self) -> Option<A> {
257-
if self.start != self.end {
258-
Some(self.end.sub_one())
259-
} else { None }
256+
fn max(mut self) -> Option<A> {
257+
self.next_back()
260258
}
261259
}
262260

@@ -376,24 +374,18 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
376374
}
377375

378376
#[inline]
379-
fn last(self) -> Option<A> {
380-
if self.start <= self.end {
381-
Some(self.end)
382-
} else { None }
377+
fn last(mut self) -> Option<A> {
378+
self.next_back()
383379
}
384380

385381
#[inline]
386-
fn min(self) -> Option<A> {
387-
if self.start <= self.end {
388-
Some(self.start)
389-
} else { None }
382+
fn min(mut self) -> Option<A> {
383+
self.next()
390384
}
391385

392386
#[inline]
393-
fn max(self) -> Option<A> {
394-
if self.start <= self.end {
395-
Some(self.end)
396-
} else { None }
387+
fn max(mut self) -> Option<A> {
388+
self.next_back()
397389
}
398390
}
399391

0 commit comments

Comments
 (0)