From bdeb61437fe3cdbf96d84b48116ab113a38c417c Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Tue, 25 May 2021 19:15:48 +0200 Subject: Add test for suggestion of array_into_iter in for loop. --- src/test/ui/iterators/into-iter-on-arrays-2018.rs | 3 +++ src/test/ui/iterators/into-iter-on-arrays-2018.stderr | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/test/ui/iterators/into-iter-on-arrays-2018.rs b/src/test/ui/iterators/into-iter-on-arrays-2018.rs index 255ebfbd8f9..e2b75610fef 100644 --- a/src/test/ui/iterators/into-iter-on-arrays-2018.rs +++ b/src/test/ui/iterators/into-iter-on-arrays-2018.rs @@ -25,6 +25,9 @@ fn main() { // But you can always use the trait method explicitly as an array. let _: IntoIter = IntoIterator::into_iter(array); + + for _ in [1, 2, 3].into_iter() {} + //~^ WARNING this method call resolves to `<&[T; N] as IntoIterator>::into_iter` } /// User type that dereferences to an 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 index b6ca4ba2283..daa8a388366 100644 --- a/src/test/ui/iterators/into-iter-on-arrays-2018.stderr +++ b/src/test/ui/iterators/into-iter-on-arrays-2018.stderr @@ -33,5 +33,20 @@ help: or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicit LL | let _: Iter<'_, i32> = IntoIterator::into_iter(Box::new(array)); | ^^^^^^^^^^^^^^^^^^^^^^^^ ^ -warning: 2 warnings emitted +warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021. + --> $DIR/into-iter-on-arrays-2018.rs:27:24 + | +LL | for _ in [1, 2, 3].into_iter() {} + | ^^^^^^^^^ + | +help: use `.iter()` instead of `.into_iter()` to avoid ambiguity + | +LL | for _ in [1, 2, 3].iter() {} + | ^^^^ +help: or remove `.into_iter()` to iterate by value + | +LL | for _ in [1, 2, 3] {} + | -- + +warning: 3 warnings emitted -- cgit 1.4.1-3-g733a5