Skip to content

Commit 04a5d61

Browse files
committed
Revert "Mark DoubleEndedIterator as #[const_trait] using rustc_do_not_const_check, implement const Iterator and DoubleEndedIterator for Range."
This reverts commit 8a9d6bf.
1 parent 131211a commit 04a5d61

File tree

9 files changed

+24
-70
lines changed

9 files changed

+24
-70
lines changed

library/core/src/iter/range.rs

Lines changed: 4 additions & 8 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};
@@ -524,7 +523,6 @@ macro_rules! range_incl_exact_iter_impl {
524523
}
525524

526525
/// Specialization implementations for `Range`.
527-
#[const_trait]
528526
trait RangeIteratorImpl {
529527
type Item;
530528

@@ -539,7 +537,7 @@ trait RangeIteratorImpl {
539537
fn spec_advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize>;
540538
}
541539

542-
impl<A: ~const Step + ~const Destruct> const RangeIteratorImpl for ops::Range<A> {
540+
impl<A: Step> RangeIteratorImpl for ops::Range<A> {
543541
type Item = A;
544542

545543
#[inline]
@@ -625,7 +623,7 @@ impl<A: ~const Step + ~const Destruct> const RangeIteratorImpl for ops::Range<A>
625623
}
626624
}
627625

628-
impl<T: ~const TrustedStep + ~const Destruct> const RangeIteratorImpl for ops::Range<T> {
626+
impl<T: TrustedStep> RangeIteratorImpl for ops::Range<T> {
629627
#[inline]
630628
fn spec_next(&mut self) -> Option<T> {
631629
if self.start < self.end {
@@ -713,8 +711,7 @@ impl<T: ~const TrustedStep + ~const Destruct> const RangeIteratorImpl for ops::R
713711
}
714712

715713
#[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> {
714+
impl<A: Step> Iterator for ops::Range<A> {
718715
type Item = A;
719716

720717
#[inline]
@@ -824,8 +821,7 @@ range_incl_exact_iter_impl! {
824821
}
825822

826823
#[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> {
824+
impl<A: Step> DoubleEndedIterator for ops::Range<A> {
829825
#[inline]
830826
fn next_back(&mut self) -> Option<A> {
831827
self.spec_next_back()

library/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,

library/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
}

library/core/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@
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)]

library/core/tests/iter/consts.rs

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

library/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::*;

library/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)]

tests/ui/typeck/typeck_type_placeholder_item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,5 @@ fn evens_squared(n: usize) -> _ {
228228

229229
const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
230230
//~^ ERROR the trait bound
231+
//~| ERROR the trait bound
231232
//~| ERROR the placeholder

tests/ui/typeck/typeck_type_placeholder_item.stderr

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,19 @@ LL | fn evens_squared(n: usize) -> _ {
437437
| not allowed in type signatures
438438
| help: replace with an appropriate return type: `impl Iterator<Item = usize>`
439439

440+
error[E0277]: the trait bound `std::ops::Range<{integer}>: Iterator` is not satisfied
441+
--> $DIR/typeck_type_placeholder_item.rs:229:22
442+
|
443+
LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
444+
| ^^^^^^ `std::ops::Range<{integer}>` is not an iterator
445+
|
446+
= help: the trait `~const Iterator` is not implemented for `std::ops::Range<{integer}>`
447+
note: the trait `Iterator` is implemented for `std::ops::Range<{integer}>`, but that implementation is not `const`
448+
--> $DIR/typeck_type_placeholder_item.rs:229:14
449+
|
450+
LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
451+
| ^^^^^^^
452+
440453
error[E0277]: the trait bound `Filter<std::ops::Range<{integer}>, [closure@$DIR/typeck_type_placeholder_item.rs:229:29: 229:32]>: Iterator` is not satisfied
441454
--> $DIR/typeck_type_placeholder_item.rs:229:45
442455
|
@@ -664,7 +677,7 @@ LL | const D: _ = 42;
664677
| not allowed in type signatures
665678
| help: replace with the correct type: `i32`
666679

667-
error: aborting due to 72 previous errors
680+
error: aborting due to 73 previous errors
668681

669682
Some errors have detailed explanations: E0121, E0277, E0282, E0403.
670683
For more information about an error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)