Skip to content

Commit 4481b60

Browse files
committed
Make the Step implementations const.
1 parent 9dccf4f commit 4481b60

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
@@ -21,7 +21,8 @@ unsafe_impl_trusted_step![char i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usi
2121
/// The *successor* operation moves towards values that compare greater.
2222
/// The *predecessor* operation moves towards values that compare lesser.
2323
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
24-
pub trait Step: Clone + PartialOrd + Sized {
24+
#[const_trait]
25+
pub trait Step: ~const Clone + ~const PartialOrd + Sized {
2526
/// Returns the number of *successor* steps required to get from `start` to `end`.
2627
///
2728
/// Returns `None` if the number of steps would overflow `usize`
@@ -235,7 +236,8 @@ macro_rules! step_integer_impls {
235236
$(
236237
#[allow(unreachable_patterns)]
237238
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
238-
impl Step for $u_narrower {
239+
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
240+
impl const Step for $u_narrower {
239241
step_identical_methods!();
240242

241243
#[inline]
@@ -267,7 +269,8 @@ macro_rules! step_integer_impls {
267269

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

273276
#[inline]
@@ -331,7 +334,8 @@ macro_rules! step_integer_impls {
331334
$(
332335
#[allow(unreachable_patterns)]
333336
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
334-
impl Step for $u_wider {
337+
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
338+
impl const Step for $u_wider {
335339
step_identical_methods!();
336340

337341
#[inline]
@@ -356,7 +360,8 @@ macro_rules! step_integer_impls {
356360

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

362367
#[inline]
@@ -406,7 +411,8 @@ step_integer_impls! {
406411
}
407412

408413
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
409-
impl Step for char {
414+
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
415+
impl const Step for char {
410416
#[inline]
411417
fn steps_between(&start: &char, &end: &char) -> Option<usize> {
412418
let start = start as u32;
@@ -424,6 +430,7 @@ impl Step for char {
424430
}
425431

426432
#[inline]
433+
#[rustc_allow_const_fn_unstable(const_try)]
427434
fn forward_checked(start: char, count: usize) -> Option<char> {
428435
let start = start as u32;
429436
let mut res = Step::forward_checked(start, count)?;
@@ -440,6 +447,7 @@ impl Step for char {
440447
}
441448

442449
#[inline]
450+
#[rustc_allow_const_fn_unstable(const_try)]
443451
fn backward_checked(start: char, count: usize) -> Option<char> {
444452
let start = start as u32;
445453
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
@@ -75,4 +75,5 @@ pub unsafe trait InPlaceIterable: Iterator {}
7575
/// for details. Consumers are free to rely on the invariants in unsafe code.
7676
#[unstable(feature = "trusted_step", issue = "85731")]
7777
#[rustc_specialization_trait]
78-
pub unsafe trait TrustedStep: Step {}
78+
#[const_trait]
79+
pub unsafe trait TrustedStep: ~const Step {}

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
#![feature(const_inherent_unchecked_arith)]
125125
#![feature(const_int_unchecked_arith)]
126126
#![feature(const_intrinsic_forget)]
127+
#![feature(const_iter)]
127128
#![feature(const_likely)]
128129
#![feature(const_maybe_uninit_uninit_array)]
129130
#![feature(const_maybe_uninit_as_mut_ptr)]

0 commit comments

Comments
 (0)