Skip to content

Commit d53068e

Browse files
committed
improve step_integer_impls macro
1 parent 90b1961 commit d53068e

File tree

1 file changed

+6
-29
lines changed

1 file changed

+6
-29
lines changed

src/libcore/iter/range.rs

+6-29
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ macro_rules! step_identical_methods {
196196
unsafe fn backward_unchecked(start: Self, n: usize) -> Self {
197197
start.unchecked_sub(n as Self)
198198
}
199-
};
200-
( [$u:ident $i:ident] ) => {
201-
step_identical_methods!();
202199

203200
#[inline]
204201
fn forward(start: Self, n: usize) -> Self {
@@ -207,8 +204,8 @@ macro_rules! step_identical_methods {
207204
if Self::forward_checked(start, n).is_none() {
208205
let _ = Add::add(Self::MAX, 1);
209206
}
210-
// Do wrapping math to allow e.g. `Step::forward(-128u8, 255)`.
211-
start.wrapping_add(n as Self) as Self
207+
// Do wrapping math to allow e.g. `Step::forward(-128i8, 255)`.
208+
start.wrapping_add(n as Self)
212209
}
213210

214211
#[inline]
@@ -218,8 +215,8 @@ macro_rules! step_identical_methods {
218215
if Self::backward_checked(start, n).is_none() {
219216
let _ = Sub::sub(Self::MIN, 1);
220217
}
221-
// Do wrapping math to allow e.g. `Step::backward(127u8, 255)`.
222-
start.wrapping_sub(n as Self) as Self
218+
// Do wrapping math to allow e.g. `Step::backward(127i8, 255)`.
219+
start.wrapping_sub(n as Self)
223220
}
224221
};
225222
}
@@ -235,7 +232,7 @@ macro_rules! step_integer_impls {
235232
#[allow(unreachable_patterns)]
236233
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
237234
unsafe impl Step for $u_narrower {
238-
step_identical_methods!( [ $u_narrower $i_narrower ] );
235+
step_identical_methods!();
239236

240237
#[inline]
241238
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
@@ -267,7 +264,7 @@ macro_rules! step_integer_impls {
267264
#[allow(unreachable_patterns)]
268265
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
269266
unsafe impl Step for $i_narrower {
270-
step_identical_methods!( [ $u_narrower $i_narrower ] );
267+
step_identical_methods!();
271268

272269
#[inline]
273270
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
@@ -347,20 +344,10 @@ macro_rules! step_integer_impls {
347344
start.checked_add(n as Self)
348345
}
349346

350-
#[inline]
351-
fn forward(start: Self, n: usize) -> Self {
352-
Add::add(start, n as Self)
353-
}
354-
355347
#[inline]
356348
fn backward_checked(start: Self, n: usize) -> Option<Self> {
357349
start.checked_sub(n as Self)
358350
}
359-
360-
#[inline]
361-
fn backward(start: Self, n: usize) -> Self {
362-
Sub::sub(start, n as Self)
363-
}
364351
}
365352

366353
#[allow(unreachable_patterns)]
@@ -387,20 +374,10 @@ macro_rules! step_integer_impls {
387374
start.checked_add(n as Self)
388375
}
389376

390-
#[inline]
391-
fn forward(start: Self, n: usize) -> Self {
392-
Add::add(start, n as Self)
393-
}
394-
395377
#[inline]
396378
fn backward_checked(start: Self, n: usize) -> Option<Self> {
397379
start.checked_sub(n as Self)
398380
}
399-
400-
#[inline]
401-
fn backward(start: Self, n: usize) -> Self {
402-
Sub::sub(start, n as Self)
403-
}
404381
}
405382
)+
406383
};

0 commit comments

Comments
 (0)