Skip to content

Commit 8789117

Browse files
committed
Add test for suggestion of array_into_iter in for loop.
1 parent 612f974 commit 8789117

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
@@ -23,6 +23,9 @@ fn main() {
2323

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

2831
/// 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
@@ -29,5 +29,20 @@ help: or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicit
2929
LL | let _: Iter<'_, i32> = IntoIterator::into_iter(Box::new(array));
3030
| ^^^^^^^^^^^^^^^^^^^^^^^^ ^
3131

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

0 commit comments

Comments
 (0)