about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2021-04-12 16:07:28 -0700
committerJosh Stone <jistone@redhat.com>2021-04-16 11:12:01 -0700
commit3dab4e22d43c1ec724b23d301c81bdc2b99d50e7 (patch)
tree28f83332951c330c70a497df43db18d30616d5fc /src
parent35b1590223b44a7da28c584c97967cc63f3e4e25 (diff)
downloadrust-3dab4e22d43c1ec724b23d301c81bdc2b99d50e7.tar.gz
rust-3dab4e22d43c1ec724b23d301c81bdc2b99d50e7.zip
Skip into_iter() for arrays before 2021
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/iterators/into-iter-on-arrays-2018.rs17
-rw-r--r--src/test/ui/iterators/into-iter-on-arrays-2018.stderr23
-rw-r--r--src/test/ui/iterators/into-iter-on-arrays-2021.rs15
3 files changed, 55 insertions, 0 deletions
diff --git a/src/test/ui/iterators/into-iter-on-arrays-2018.rs b/src/test/ui/iterators/into-iter-on-arrays-2018.rs
new file mode 100644
index 00000000000..cbcfcf2512f
--- /dev/null
+++ b/src/test/ui/iterators/into-iter-on-arrays-2018.rs
@@ -0,0 +1,17 @@
+// check-pass
+
+use std::array::IntoIter;
+use std::slice::Iter;
+
+fn main() {
+    let array = [0; 10];
+
+    // Before 2021, the method dispatched to `IntoIterator for &[T]`,
+    // which we continue to support for compatibility.
+    let _: Iter<'_, i32> = array.into_iter();
+    //~^ WARNING this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter`
+    //~| WARNING this was previously accepted by the compiler but is being phased out
+
+    // But you can always use the trait method explicitly as an array.
+    let _: IntoIter<i32, 10> = IntoIterator::into_iter(array);
+}
diff --git a/src/test/ui/iterators/into-iter-on-arrays-2018.stderr b/src/test/ui/iterators/into-iter-on-arrays-2018.stderr
new file mode 100644
index 00000000000..7140c01ed0e
--- /dev/null
+++ b/src/test/ui/iterators/into-iter-on-arrays-2018.stderr
@@ -0,0 +1,23 @@
+warning: this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter` (due to autoref coercions), but that might change in the future when `IntoIterator` impls for arrays are added.
+  --> $DIR/into-iter-on-arrays-2018.rs:11:34
+   |
+LL |     let _: Iter<'_, i32> = array.into_iter();
+   |                                  ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
+   |
+   = note: `#[warn(array_into_iter)]` on by default
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #66145 <https://github.com/rust-lang/rust/issues/66145>
+
+warning: 1 warning emitted
+
+Future incompatibility report: Future breakage date: None, diagnostic:
+warning: this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter` (due to autoref coercions), but that might change in the future when `IntoIterator` impls for arrays are added.
+  --> $DIR/into-iter-on-arrays-2018.rs:11:34
+   |
+LL |     let _: Iter<'_, i32> = array.into_iter();
+   |                                  ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
+   |
+   = note: `#[warn(array_into_iter)]` on by default
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #66145 <https://github.com/rust-lang/rust/issues/66145>
+
diff --git a/src/test/ui/iterators/into-iter-on-arrays-2021.rs b/src/test/ui/iterators/into-iter-on-arrays-2021.rs
new file mode 100644
index 00000000000..731971484e8
--- /dev/null
+++ b/src/test/ui/iterators/into-iter-on-arrays-2021.rs
@@ -0,0 +1,15 @@
+// check-pass
+// edition:2021
+// compile-flags: -Zunstable-options
+
+use std::array::IntoIter;
+
+fn main() {
+    let array = [0; 10];
+
+    // In 2021, the method dispatches to `IntoIterator for [T; N]`.
+    let _: IntoIter<i32, 10> = array.into_iter();
+
+    // And you can always use the trait method explicitly as an array.
+    let _: IntoIter<i32, 10> = IntoIterator::into_iter(array);
+}