11use crate :: convert:: TryFrom ;
2+ use crate :: marker:: Destruct ;
23use crate :: mem;
34use crate :: ops:: { self , Try } ;
45
@@ -20,7 +21,8 @@ unsafe_impl_trusted_step![char i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usi
2021/// The *successor* operation moves towards values that compare greater.
2122/// The *predecessor* operation moves towards values that compare lesser.
2223#[ unstable( feature = "step_trait" , reason = "recently redesigned" , issue = "42168" ) ]
23- pub trait Step : Clone + PartialOrd + Sized {
24+ #[ const_trait]
25+ pub trait Step : ~const Clone + ~const PartialOrd + Sized {
2426 /// Returns the number of *successor* steps required to get from `start` to `end`.
2527 ///
2628 /// Returns `None` if the number of steps would overflow `usize`
@@ -234,7 +236,8 @@ macro_rules! step_integer_impls {
234236 $(
235237 #[ allow( unreachable_patterns) ]
236238 #[ unstable( feature = "step_trait" , reason = "recently redesigned" , issue = "42168" ) ]
237- impl Step for $u_narrower {
239+ #[ rustc_const_unstable( feature = "const_iter" , issue = "92476" ) ]
240+ impl const Step for $u_narrower {
238241 step_identical_methods!( ) ;
239242
240243 #[ inline]
@@ -266,7 +269,8 @@ macro_rules! step_integer_impls {
266269
267270 #[ allow( unreachable_patterns) ]
268271 #[ unstable( feature = "step_trait" , reason = "recently redesigned" , issue = "42168" ) ]
269- impl Step for $i_narrower {
272+ #[ rustc_const_unstable( feature = "const_iter" , issue = "92476" ) ]
273+ impl const Step for $i_narrower {
270274 step_identical_methods!( ) ;
271275
272276 #[ inline]
@@ -330,7 +334,8 @@ macro_rules! step_integer_impls {
330334 $(
331335 #[ allow( unreachable_patterns) ]
332336 #[ unstable( feature = "step_trait" , reason = "recently redesigned" , issue = "42168" ) ]
333- impl Step for $u_wider {
337+ #[ rustc_const_unstable( feature = "const_iter" , issue = "92476" ) ]
338+ impl const Step for $u_wider {
334339 step_identical_methods!( ) ;
335340
336341 #[ inline]
@@ -355,7 +360,8 @@ macro_rules! step_integer_impls {
355360
356361 #[ allow( unreachable_patterns) ]
357362 #[ unstable( feature = "step_trait" , reason = "recently redesigned" , issue = "42168" ) ]
358- impl Step for $i_wider {
363+ #[ rustc_const_unstable( feature = "const_iter" , issue = "92476" ) ]
364+ impl const Step for $i_wider {
359365 step_identical_methods!( ) ;
360366
361367 #[ inline]
@@ -405,7 +411,8 @@ step_integer_impls! {
405411}
406412
407413#[ unstable( feature = "step_trait" , reason = "recently redesigned" , issue = "42168" ) ]
408- impl Step for char {
414+ #[ rustc_const_unstable( feature = "const_iter" , issue = "92476" ) ]
415+ impl const Step for char {
409416 #[ inline]
410417 fn steps_between ( & start: & char , & end: & char ) -> Option < usize > {
411418 let start = start as u32 ;
@@ -423,6 +430,7 @@ impl Step for char {
423430 }
424431
425432 #[ inline]
433+ #[ rustc_allow_const_fn_unstable( const_try) ]
426434 fn forward_checked ( start : char , count : usize ) -> Option < char > {
427435 let start = start as u32 ;
428436 let mut res = Step :: forward_checked ( start, count) ?;
@@ -439,6 +447,7 @@ impl Step for char {
439447 }
440448
441449 #[ inline]
450+ #[ rustc_allow_const_fn_unstable( const_try) ]
442451 fn backward_checked ( start : char , count : usize ) -> Option < char > {
443452 let start = start as u32 ;
444453 let mut res = Step :: backward_checked ( start, count) ?;
@@ -514,6 +523,7 @@ macro_rules! range_incl_exact_iter_impl {
514523}
515524
516525/// Specialization implementations for `Range`.
526+ #[ const_trait]
517527trait RangeIteratorImpl {
518528 type Item ;
519529
@@ -528,7 +538,7 @@ trait RangeIteratorImpl {
528538 fn spec_advance_back_by ( & mut self , n : usize ) -> Result < ( ) , usize > ;
529539}
530540
531- impl < A : Step > RangeIteratorImpl for ops:: Range < A > {
541+ impl < A : ~ const Step + ~ const Destruct > const RangeIteratorImpl for ops:: Range < A > {
532542 type Item = A ;
533543
534544 #[ inline]
@@ -614,7 +624,7 @@ impl<A: Step> RangeIteratorImpl for ops::Range<A> {
614624 }
615625}
616626
617- impl < T : TrustedStep > RangeIteratorImpl for ops:: Range < T > {
627+ impl < T : ~ const TrustedStep + ~ const Destruct > const RangeIteratorImpl for ops:: Range < T > {
618628 #[ inline]
619629 fn spec_next ( & mut self ) -> Option < T > {
620630 if self . start < self . end {
@@ -702,7 +712,8 @@ impl<T: TrustedStep> RangeIteratorImpl for ops::Range<T> {
702712}
703713
704714#[ stable( feature = "rust1" , since = "1.0.0" ) ]
705- impl < A : Step > Iterator for ops:: Range < A > {
715+ #[ rustc_const_unstable( feature = "const_iter" , issue = "92476" ) ]
716+ impl < A : ~const Step + ~const Destruct > const Iterator for ops:: Range < A > {
706717 type Item = A ;
707718
708719 #[ inline]
@@ -812,7 +823,8 @@ range_incl_exact_iter_impl! {
812823}
813824
814825#[ stable( feature = "rust1" , since = "1.0.0" ) ]
815- impl < A : Step > DoubleEndedIterator for ops:: Range < A > {
826+ #[ rustc_const_unstable( feature = "const_iter" , issue = "92476" ) ]
827+ impl < A : ~const Step + ~const Destruct > const DoubleEndedIterator for ops:: Range < A > {
816828 #[ inline]
817829 fn next_back ( & mut self ) -> Option < A > {
818830 self . spec_next_back ( )
0 commit comments