Skip to content

Commit 5df3883

Browse files
committed
Auto merge of rust-lang#109684 - fee1-dead-contrib:rv_const_range, r=Mark-Simulacrum
Revert rust-lang#104100, Allow using `Range` as an `Iterator` in const contexts. This fixes rust-lang#109632.
2 parents 5adc54f + efec0fb commit 5df3883

File tree

8 files changed

+16
-86
lines changed

8 files changed

+16
-86
lines changed

core/src/iter/range.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::convert::TryFrom;
2-
use crate::marker::Destruct;
32
use crate::mem;
43
use crate::num::NonZeroUsize;
54
use crate::ops::{self, Try};
@@ -22,8 +21,7 @@ unsafe_impl_trusted_step![char i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usi
2221
/// The *successor* operation moves towards values that compare greater.
2322
/// The *predecessor* operation moves towards values that compare lesser.
2423
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
25-
#[const_trait]
26-
pub trait Step: ~const Clone + ~const PartialOrd + Sized {
24+
pub trait Step: Clone + PartialOrd + Sized {
2725
/// Returns the number of *successor* steps required to get from `start` to `end`.
2826
///
2927
/// Returns `None` if the number of steps would overflow `usize`
@@ -237,8 +235,7 @@ macro_rules! step_integer_impls {
237235
$(
238236
#[allow(unreachable_patterns)]
239237
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
240-
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
241-
impl const Step for $u_narrower {
238+
impl Step for $u_narrower {
242239
step_identical_methods!();
243240

244241
#[inline]
@@ -270,8 +267,7 @@ macro_rules! step_integer_impls {
270267

271268
#[allow(unreachable_patterns)]
272269
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
273-
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
274-
impl const Step for $i_narrower {
270+
impl Step for $i_narrower {
275271
step_identical_methods!();
276272

277273
#[inline]
@@ -335,8 +331,7 @@ macro_rules! step_integer_impls {
335331
$(
336332
#[allow(unreachable_patterns)]
337333
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
338-
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
339-
impl const Step for $u_wider {
334+
impl Step for $u_wider {
340335
step_identical_methods!();
341336

342337
#[inline]
@@ -361,8 +356,7 @@ macro_rules! step_integer_impls {
361356

362357
#[allow(unreachable_patterns)]
363358
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
364-
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
365-
impl const Step for $i_wider {
359+
impl Step for $i_wider {
366360
step_identical_methods!();
367361

368362
#[inline]
@@ -412,8 +406,7 @@ step_integer_impls! {
412406
}
413407

414408
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
415-
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
416-
impl const Step for char {
409+
impl Step for char {
417410
#[inline]
418411
fn steps_between(&start: &char, &end: &char) -> Option<usize> {
419412
let start = start as u32;
@@ -431,7 +424,6 @@ impl const Step for char {
431424
}
432425

433426
#[inline]
434-
#[rustc_allow_const_fn_unstable(const_try)]
435427
fn forward_checked(start: char, count: usize) -> Option<char> {
436428
let start = start as u32;
437429
let mut res = Step::forward_checked(start, count)?;
@@ -448,7 +440,6 @@ impl const Step for char {
448440
}
449441

450442
#[inline]
451-
#[rustc_allow_const_fn_unstable(const_try)]
452443
fn backward_checked(start: char, count: usize) -> Option<char> {
453444
let start = start as u32;
454445
let mut res = Step::backward_checked(start, count)?;
@@ -524,7 +515,6 @@ macro_rules! range_incl_exact_iter_impl {
524515
}
525516

526517
/// Specialization implementations for `Range`.
527-
#[const_trait]
528518
trait RangeIteratorImpl {
529519
type Item;
530520

@@ -539,7 +529,7 @@ trait RangeIteratorImpl {
539529
fn spec_advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize>;
540530
}
541531

542-
impl<A: ~const Step + ~const Destruct> const RangeIteratorImpl for ops::Range<A> {
532+
impl<A: Step> RangeIteratorImpl for ops::Range<A> {
543533
type Item = A;
544534

545535
#[inline]
@@ -625,7 +615,7 @@ impl<A: ~const Step + ~const Destruct> const RangeIteratorImpl for ops::Range<A>
625615
}
626616
}
627617

628-
impl<T: ~const TrustedStep + ~const Destruct> const RangeIteratorImpl for ops::Range<T> {
618+
impl<T: TrustedStep> RangeIteratorImpl for ops::Range<T> {
629619
#[inline]
630620
fn spec_next(&mut self) -> Option<T> {
631621
if self.start < self.end {
@@ -713,8 +703,7 @@ impl<T: ~const TrustedStep + ~const Destruct> const RangeIteratorImpl for ops::R
713703
}
714704

715705
#[stable(feature = "rust1", since = "1.0.0")]
716-
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
717-
impl<A: ~const Step + ~const Destruct> const Iterator for ops::Range<A> {
706+
impl<A: Step> Iterator for ops::Range<A> {
718707
type Item = A;
719708

720709
#[inline]
@@ -824,8 +813,7 @@ range_incl_exact_iter_impl! {
824813
}
825814

826815
#[stable(feature = "rust1", since = "1.0.0")]
827-
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
828-
impl<A: ~const Step + ~const Destruct> const DoubleEndedIterator for ops::Range<A> {
816+
impl<A: Step> DoubleEndedIterator for ops::Range<A> {
829817
#[inline]
830818
fn next_back(&mut self) -> Option<A> {
831819
self.spec_next_back()

core/src/iter/traits/double_ended.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::marker::Destruct;
21
use crate::num::NonZeroUsize;
32
use crate::ops::{ControlFlow, Try};
43

@@ -39,7 +38,6 @@ use crate::ops::{ControlFlow, Try};
3938
/// ```
4039
#[stable(feature = "rust1", since = "1.0.0")]
4140
#[cfg_attr(not(test), rustc_diagnostic_item = "DoubleEndedIterator")]
42-
#[const_trait]
4341
pub trait DoubleEndedIterator: Iterator {
4442
/// Removes and returns an element from the end of the iterator.
4543
///
@@ -136,10 +134,7 @@ pub trait DoubleEndedIterator: Iterator {
136134
/// [`Err(k)`]: Err
137135
#[inline]
138136
#[unstable(feature = "iter_advance_by", reason = "recently added", issue = "77404")]
139-
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
140-
where
141-
Self::Item: ~const Destruct,
142-
{
137+
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize> {
143138
for i in 0..n {
144139
if self.next_back().is_none() {
145140
// SAFETY: `i` is always less than `n`.
@@ -192,7 +187,6 @@ pub trait DoubleEndedIterator: Iterator {
192187
/// ```
193188
#[inline]
194189
#[stable(feature = "iter_nth_back", since = "1.37.0")]
195-
#[rustc_do_not_const_check]
196190
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
197191
if self.advance_back_by(n).is_err() {
198192
return None;
@@ -232,7 +226,6 @@ pub trait DoubleEndedIterator: Iterator {
232226
/// ```
233227
#[inline]
234228
#[stable(feature = "iterator_try_fold", since = "1.27.0")]
235-
#[rustc_do_not_const_check]
236229
fn try_rfold<B, F, R>(&mut self, init: B, mut f: F) -> R
237230
where
238231
Self: Sized,
@@ -304,7 +297,6 @@ pub trait DoubleEndedIterator: Iterator {
304297
#[doc(alias = "foldr")]
305298
#[inline]
306299
#[stable(feature = "iter_rfold", since = "1.27.0")]
307-
#[rustc_do_not_const_check]
308300
fn rfold<B, F>(mut self, init: B, mut f: F) -> B
309301
where
310302
Self: Sized,
@@ -360,7 +352,6 @@ pub trait DoubleEndedIterator: Iterator {
360352
/// ```
361353
#[inline]
362354
#[stable(feature = "iter_rfind", since = "1.27.0")]
363-
#[rustc_do_not_const_check]
364355
fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>
365356
where
366357
Self: Sized,

core/src/iter/traits/iterator.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::array;
22
use crate::cmp::{self, Ordering};
3-
use crate::marker::Destruct;
43
use crate::num::NonZeroUsize;
54
use crate::ops::{ChangeOutputType, ControlFlow, FromResidual, Residual, Try};
65

@@ -340,10 +339,8 @@ pub trait Iterator {
340339
/// ```
341340
#[inline]
342341
#[unstable(feature = "iter_advance_by", reason = "recently added", issue = "77404")]
343-
fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
344-
where
345-
Self::Item: ~const Destruct,
346-
{
342+
#[rustc_do_not_const_check]
343+
fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize> {
347344
for i in 0..n {
348345
if self.next().is_none() {
349346
// SAFETY: `i` is always less than `n`.
@@ -394,10 +391,8 @@ pub trait Iterator {
394391
/// ```
395392
#[inline]
396393
#[stable(feature = "rust1", since = "1.0.0")]
397-
fn nth(&mut self, n: usize) -> Option<Self::Item>
398-
where
399-
Self::Item: ~const Destruct,
400-
{
394+
#[rustc_do_not_const_check]
395+
fn nth(&mut self, n: usize) -> Option<Self::Item> {
401396
self.advance_by(n).ok()?;
402397
self.next()
403398
}

core/src/iter/traits/marker.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,4 @@ 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-
#[const_trait]
90-
pub unsafe trait TrustedStep: ~const Step {}
89+
pub unsafe trait TrustedStep: Step {}

core/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,9 @@
123123
#![feature(const_index_range_slice_index)]
124124
#![feature(const_inherent_unchecked_arith)]
125125
#![feature(const_int_unchecked_arith)]
126-
#![feature(const_intoiterator_identity)]
127126
#![feature(const_intrinsic_forget)]
128127
#![feature(const_ipv4)]
129128
#![feature(const_ipv6)]
130-
#![feature(const_iter)]
131129
#![feature(const_likely)]
132130
#![feature(const_maybe_uninit_uninit_array)]
133131
#![feature(const_maybe_uninit_as_mut_ptr)]

core/tests/iter/consts.rs

Lines changed: 0 additions & 36 deletions
This file was deleted.

core/tests/iter/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ mod range;
2020
mod sources;
2121
mod traits;
2222

23-
mod consts;
24-
2523
use core::cell::Cell;
2624
use core::convert::TryFrom;
2725
use core::iter::*;

core/tests/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
#![feature(const_caller_location)]
1313
#![feature(const_cell_into_inner)]
1414
#![feature(const_convert)]
15-
#![feature(const_for)]
1615
#![feature(const_hash)]
1716
#![feature(const_heap)]
18-
#![feature(const_intoiterator_identity)]
19-
#![feature(const_iter)]
2017
#![feature(const_maybe_uninit_as_mut_ptr)]
2118
#![feature(const_maybe_uninit_assume_init_read)]
2219
#![feature(const_nonnull_new)]

0 commit comments

Comments
 (0)