Skip to content

Commit 7bc67ef

Browse files
committed
Make the Step implementations const.
1 parent 13afbda commit 7bc67ef

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

library/core/src/iter/range.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ unsafe_impl_trusted_step![char i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usi
2020
/// The *successor* operation moves towards values that compare greater.
2121
/// The *predecessor* operation moves towards values that compare lesser.
2222
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
23-
pub trait Step: Clone + PartialOrd + Sized {
23+
#[const_trait]
24+
pub trait Step: ~const Clone + ~const PartialOrd + Sized {
2425
/// Returns the number of *successor* steps required to get from `start` to `end`.
2526
///
2627
/// Returns `None` if the number of steps would overflow `usize`
@@ -234,7 +235,8 @@ macro_rules! step_integer_impls {
234235
$(
235236
#[allow(unreachable_patterns)]
236237
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
237-
impl Step for $u_narrower {
238+
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
239+
impl const Step for $u_narrower {
238240
step_identical_methods!();
239241

240242
#[inline]
@@ -266,7 +268,8 @@ macro_rules! step_integer_impls {
266268

267269
#[allow(unreachable_patterns)]
268270
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
269-
impl Step for $i_narrower {
271+
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
272+
impl const Step for $i_narrower {
270273
step_identical_methods!();
271274

272275
#[inline]
@@ -330,7 +333,8 @@ macro_rules! step_integer_impls {
330333
$(
331334
#[allow(unreachable_patterns)]
332335
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
333-
impl Step for $u_wider {
336+
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
337+
impl const Step for $u_wider {
334338
step_identical_methods!();
335339

336340
#[inline]
@@ -355,7 +359,8 @@ macro_rules! step_integer_impls {
355359

356360
#[allow(unreachable_patterns)]
357361
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
358-
impl Step for $i_wider {
362+
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
363+
impl const Step for $i_wider {
359364
step_identical_methods!();
360365

361366
#[inline]
@@ -405,7 +410,8 @@ step_integer_impls! {
405410
}
406411

407412
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
408-
impl Step for char {
413+
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
414+
impl const Step for char {
409415
#[inline]
410416
fn steps_between(&start: &char, &end: &char) -> Option<usize> {
411417
let start = start as u32;
@@ -423,6 +429,7 @@ impl Step for char {
423429
}
424430

425431
#[inline]
432+
#[rustc_allow_const_fn_unstable(const_try)]
426433
fn forward_checked(start: char, count: usize) -> Option<char> {
427434
let start = start as u32;
428435
let mut res = Step::forward_checked(start, count)?;
@@ -439,6 +446,7 @@ impl Step for char {
439446
}
440447

441448
#[inline]
449+
#[rustc_allow_const_fn_unstable(const_try)]
442450
fn backward_checked(start: char, count: usize) -> Option<char> {
443451
let start = start as u32;
444452
let mut res = Step::backward_checked(start, count)?;

library/core/src/iter/traits/marker.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,5 @@ pub unsafe trait InPlaceIterable: Iterator {}
8686
/// for details. Consumers are free to rely on the invariants in unsafe code.
8787
#[unstable(feature = "trusted_step", issue = "85731")]
8888
#[rustc_specialization_trait]
89-
pub unsafe trait TrustedStep: Step {}
89+
#[const_trait]
90+
pub unsafe trait TrustedStep: ~const Step {}

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
#![feature(const_intrinsic_forget)]
127127
#![feature(const_ipv4)]
128128
#![feature(const_ipv6)]
129+
#![feature(const_iter)]
129130
#![feature(const_likely)]
130131
#![feature(const_maybe_uninit_uninit_array)]
131132
#![feature(const_maybe_uninit_as_mut_ptr)]

0 commit comments

Comments
 (0)