Skip to content

Commit 6b4563b

Browse files
committed
Auto merge of rust-lang#90602 - mbartlett21:const-intoiterator, r=oli-obk
Unstably constify `impl<I: Iterator> IntoIterator for I` This constifies the default `IntoIterator` implementation under the `const_intoiterator_identity` feature. Tracking Issue: rust-lang#90603
2 parents 1e9aa8a + b8ef1db commit 6b4563b

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,9 @@ pub trait IntoIterator {
267267
fn into_iter(self) -> Self::IntoIter;
268268
}
269269

270+
#[rustc_const_unstable(feature = "const_intoiterator_identity", issue = "90603")]
270271
#[stable(feature = "rust1", since = "1.0.0")]
271-
impl<I: Iterator> IntoIterator for I {
272+
impl<I: ~const Iterator> const IntoIterator for I {
272273
type Item = I::Item;
273274
type IntoIter = I;
274275

src/test/ui/consts/const-fn-error.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ LL | for i in 0..x {
2222
note: impl defined here, but it is not `const`
2323
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
2424
|
25-
LL | impl<I: Iterator> IntoIterator for I {
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25+
LL | impl<I: ~const Iterator> const IntoIterator for I {
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2727
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
2828

2929
error[E0658]: mutable references are not allowed in constant functions

src/test/ui/consts/const-for.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | for _ in 0..5 {}
77
note: impl defined here, but it is not `const`
88
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
99
|
10-
LL | impl<I: Iterator> IntoIterator for I {
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
LL | impl<I: ~const Iterator> const IntoIterator for I {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
1313

1414
error[E0015]: cannot call non-const fn `<std::ops::Range<i32> as Iterator>::next` in constants

src/test/ui/never_type/issue-52443.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ LL | [(); { for _ in 0usize.. {}; 0}];
4747
note: impl defined here, but it is not `const`
4848
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
4949
|
50-
LL | impl<I: Iterator> IntoIterator for I {
51-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
LL | impl<I: ~const Iterator> const IntoIterator for I {
51+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5252
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
5353

5454
error[E0658]: mutable references are not allowed in constants

0 commit comments

Comments
 (0)