]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #90602 - mbartlett21:const-intoiterator, r=oli-obk
authorbors <bors@rust-lang.org>
Sat, 23 Apr 2022 15:41:45 +0000 (15:41 +0000)
committerbors <bors@rust-lang.org>
Sat, 23 Apr 2022 15:41:45 +0000 (15:41 +0000)
Unstably constify `impl<I: Iterator> IntoIterator for I`

This constifies the default `IntoIterator` implementation under the `const_intoiterator_identity` feature.

Tracking Issue: #90603

library/core/src/iter/traits/collect.rs
src/test/ui/consts/const-fn-error.stderr
src/test/ui/consts/const-for.stderr
src/test/ui/never_type/issue-52443.stderr

index 7b75ab96ee7deea69f7f194b115490bc51702a64..e6900742c31d235d7ce15e4f1f1c1b5e4f2341fc 100644 (file)
@@ -267,8 +267,9 @@ pub trait IntoIterator {
     fn into_iter(self) -> Self::IntoIter;
 }
 
+#[rustc_const_unstable(feature = "const_intoiterator_identity", issue = "90603")]
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<I: Iterator> IntoIterator for I {
+impl<I: ~const Iterator> const IntoIterator for I {
     type Item = I::Item;
     type IntoIter = I;
 
index 4d53cfc35e1c4ab88db8e8b0bca1e545a23c99b2..e36324f0b3eea2680367b8780d7413fde536266e 100644 (file)
@@ -22,8 +22,8 @@ LL |     for i in 0..x {
 note: impl defined here, but it is not `const`
   --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
    |
-LL | impl<I: Iterator> IntoIterator for I {
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | impl<I: ~const Iterator> const IntoIterator for I {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
 
 error[E0658]: mutable references are not allowed in constant functions
index b0dc43eb8e8508f0d23cb136faa64e168408afb2..f2e1c8a4991a31c5f265db040cf518b6b0695c74 100644 (file)
@@ -7,8 +7,8 @@ LL |     for _ in 0..5 {}
 note: impl defined here, but it is not `const`
   --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
    |
-LL | impl<I: Iterator> IntoIterator for I {
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | impl<I: ~const Iterator> const IntoIterator for I {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: calls in constants are limited to constant functions, tuple structs and tuple variants
 
 error[E0015]: cannot call non-const fn `<std::ops::Range<i32> as Iterator>::next` in constants
index 8c1755205f0253b82f6026b5d05f2508c4d831f0..c2079a19d0a58059b03637f4d7009c7292d42808 100644 (file)
@@ -47,8 +47,8 @@ LL |     [(); { for _ in 0usize.. {}; 0}];
 note: impl defined here, but it is not `const`
   --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
    |
-LL | impl<I: Iterator> IntoIterator for I {
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | impl<I: ~const Iterator> const IntoIterator for I {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: calls in constants are limited to constant functions, tuple structs and tuple variants
 
 error[E0658]: mutable references are not allowed in constants