Skip to content

Commit 9ac4160

Browse files
committed
remove Range specialization, simplify RangeInclusive code
1 parent 5a909a6 commit 9ac4160

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

src/libcore/iter/range.rs

+5-23
Original file line numberDiff line numberDiff line change
@@ -444,32 +444,14 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
444444
}
445445
Try::from_ok(accum)
446446
}
447-
}
448447

449-
macro_rules! impl_inclusive_range_count {
450-
($t:ty) => {
451-
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
452-
impl Iterator for ops::RangeInclusive<$t> {
453-
#[inline]
454-
fn count(self) -> usize {
455-
(self.end.wrapping_sub(self.start) as usize).wrapping_add(1)
456-
}
457-
}
458-
};
448+
#[inline]
449+
fn count(self) -> usize {
450+
<A as Step>::steps_between(&self.start, &self.end)
451+
.expect("Overflow on `RangeInclusive::count()`") + 1
452+
}
459453
}
460454

461-
impl_inclusive_range_count!(u8);
462-
impl_inclusive_range_count!(u16);
463-
impl_inclusive_range_count!(u32);
464-
impl_inclusive_range_count!(u64);
465-
impl_inclusive_range_count!(usize);
466-
467-
impl_inclusive_range_count!(i8);
468-
impl_inclusive_range_count!(i16);
469-
impl_inclusive_range_count!(i32);
470-
impl_inclusive_range_count!(i64);
471-
impl_inclusive_range_count!(isize);
472-
473455
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
474456
impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> {
475457
#[inline]

0 commit comments

Comments
 (0)