fix range sugar
This commit is contained in:
parent
496dc4eae7
commit
5cc17382d1
2 changed files with 7 additions and 7 deletions
|
@ -2620,10 +2620,10 @@ pub trait Step: Ord {
|
||||||
/// Change self to the previous object.
|
/// Change self to the previous object.
|
||||||
fn step_back(&mut self);
|
fn step_back(&mut self);
|
||||||
/// The steps_between two step objects.
|
/// The steps_between two step objects.
|
||||||
/// a should always be less than b, so the result should never be negative.
|
/// start should always be less than end, so the result should never be negative.
|
||||||
/// Return None if it is not possible to calculate steps_between without
|
/// Return None if it is not possible to calculate steps_between without
|
||||||
/// overflow.
|
/// overflow.
|
||||||
fn steps_between(a: &Self, b: &Self) -> Option<uint>;
|
fn steps_between(start: &Self, end: &Self) -> Option<uint>;
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! step_impl {
|
macro_rules! step_impl {
|
||||||
|
@ -2635,9 +2635,9 @@ macro_rules! step_impl {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn step_back(&mut self) { *self -= 1; }
|
fn step_back(&mut self) { *self -= 1; }
|
||||||
#[inline]
|
#[inline]
|
||||||
fn steps_between(a: &$t, b: &$t) -> Option<uint> {
|
fn steps_between(start: &$t, end: &$t) -> Option<uint> {
|
||||||
debug_assert!(a < b);
|
debug_assert!(end >= start);
|
||||||
Some((*a - *b) as uint)
|
Some((*end - *start) as uint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)*)
|
)*)
|
||||||
|
@ -2652,7 +2652,7 @@ macro_rules! step_impl_no_between {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn step_back(&mut self) { *self -= 1; }
|
fn step_back(&mut self) { *self -= 1; }
|
||||||
#[inline]
|
#[inline]
|
||||||
fn steps_between(_a: &$t, _b: &$t) -> Option<uint> {
|
fn steps_between(_start: &$t, _end: &$t) -> Option<uint> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -803,7 +803,7 @@ impl<Idx: Clone + Step> Iterator<Idx> for Range<Idx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn size_hint(&self) -> (uint, Option<uint>) {
|
fn size_hint(&self) -> (uint, Option<uint>) {
|
||||||
if let Some(hint) = Step::steps_between(&self.end, &self.start) {
|
if let Some(hint) = Step::steps_between(&self.start, &self.end) {
|
||||||
(hint, Some(hint))
|
(hint, Some(hint))
|
||||||
} else {
|
} else {
|
||||||
(0, None)
|
(0, None)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue