Skip to content

Commit bdeb614

Browse files
committed
Add test for suggestion of array_into_iter in for loop.
1 parent ef152d9 commit bdeb614

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/test/ui/iterators/into-iter-on-arrays-2018.rs

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ fn main() {
2525

2626
// But you can always use the trait method explicitly as an array.
2727
let _: IntoIter<i32, 10> = IntoIterator::into_iter(array);
28+
29+
for _ in [1, 2, 3].into_iter() {}
30+
//~^ WARNING this method call resolves to `<&[T; N] as IntoIterator>::into_iter`
2831
}
2932

3033
/// User type that dereferences to an array.

src/test/ui/iterators/into-iter-on-arrays-2018.stderr

+16-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,20 @@ help: or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicit
3333
LL | let _: Iter<'_, i32> = IntoIterator::into_iter(Box::new(array));
3434
| ^^^^^^^^^^^^^^^^^^^^^^^^ ^
3535

36-
warning: 2 warnings emitted
36+
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.
37+
--> $DIR/into-iter-on-arrays-2018.rs:27:24
38+
|
39+
LL | for _ in [1, 2, 3].into_iter() {}
40+
| ^^^^^^^^^
41+
|
42+
help: use `.iter()` instead of `.into_iter()` to avoid ambiguity
43+
|
44+
LL | for _ in [1, 2, 3].iter() {}
45+
| ^^^^
46+
help: or remove `.into_iter()` to iterate by value
47+
|
48+
LL | for _ in [1, 2, 3] {}
49+
| --
50+
51+
warning: 3 warnings emitted
3752

0 commit comments

Comments
 (0)