]> git.lizzy.rs Git - rust.git/commitdiff
Add test for 2021 ambiguous [T; N].into_iter().
authorMara Bos <m-ou.se@m-ou.se>
Mon, 30 Aug 2021 19:23:56 +0000 (21:23 +0200)
committerMara Bos <m-ou.se@m-ou.se>
Mon, 30 Aug 2021 19:27:31 +0000 (21:27 +0200)
src/test/ui/rust-2021/array-into-iter-ambiguous.fixed [new file with mode: 0644]
src/test/ui/rust-2021/array-into-iter-ambiguous.rs [new file with mode: 0644]
src/test/ui/rust-2021/array-into-iter-ambiguous.stderr [new file with mode: 0644]

diff --git a/src/test/ui/rust-2021/array-into-iter-ambiguous.fixed b/src/test/ui/rust-2021/array-into-iter-ambiguous.fixed
new file mode 100644 (file)
index 0000000..76f661b
--- /dev/null
@@ -0,0 +1,27 @@
+// See https://github.com/rust-lang/rust/issues/88475
+// run-rustfix
+// edition:2018
+// check-pass
+#![warn(array_into_iter)]
+#![allow(unused)]
+
+struct FooIter;
+
+trait MyIntoIter {
+    fn into_iter(self) -> FooIter;
+}
+
+impl<T, const N: usize> MyIntoIter for [T; N] {
+    fn into_iter(self) -> FooIter {
+        FooIter
+    }
+}
+
+struct Point;
+
+pub fn main() {
+    let points: [Point; 1] = [Point];
+    let y = MyIntoIter::into_iter(points);
+    //~^ WARNING trait method `into_iter` will become ambiguous in Rust 2021
+    //~| WARNING this changes meaning in Rust 2021
+}
diff --git a/src/test/ui/rust-2021/array-into-iter-ambiguous.rs b/src/test/ui/rust-2021/array-into-iter-ambiguous.rs
new file mode 100644 (file)
index 0000000..83fbf8f
--- /dev/null
@@ -0,0 +1,27 @@
+// See https://github.com/rust-lang/rust/issues/88475
+// run-rustfix
+// edition:2018
+// check-pass
+#![warn(array_into_iter)]
+#![allow(unused)]
+
+struct FooIter;
+
+trait MyIntoIter {
+    fn into_iter(self) -> FooIter;
+}
+
+impl<T, const N: usize> MyIntoIter for [T; N] {
+    fn into_iter(self) -> FooIter {
+        FooIter
+    }
+}
+
+struct Point;
+
+pub fn main() {
+    let points: [Point; 1] = [Point];
+    let y = points.into_iter();
+    //~^ WARNING trait method `into_iter` will become ambiguous in Rust 2021
+    //~| WARNING this changes meaning in Rust 2021
+}
diff --git a/src/test/ui/rust-2021/array-into-iter-ambiguous.stderr b/src/test/ui/rust-2021/array-into-iter-ambiguous.stderr
new file mode 100644 (file)
index 0000000..fac8d21
--- /dev/null
@@ -0,0 +1,16 @@
+warning: trait method `into_iter` will become ambiguous in Rust 2021
+  --> $DIR/array-into-iter-ambiguous.rs:24:13
+   |
+LL |     let y = points.into_iter();
+   |             ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `MyIntoIter::into_iter(points)`
+   |
+note: the lint level is defined here
+  --> $DIR/array-into-iter-ambiguous.rs:5:9
+   |
+LL | #![warn(array_into_iter)]
+   |         ^^^^^^^^^^^^^^^
+   = warning: this changes meaning in Rust 2021
+   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
+
+warning: 1 warning emitted
+