Skip to content

Commit 8fd09d9

Browse files
Add UI test for array.into_iter() lint
1 parent b492c97 commit 8fd09d9

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// run-pass
2+
// run-rustfix
3+
4+
fn main() {
5+
let small = [1, 2];
6+
let big = [0u8; 33];
7+
8+
// Expressions that should trigger the lint
9+
small.iter();
10+
//~^ WARNING this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter`
11+
//~| WARNING this was previously accepted by the compiler but is being phased out
12+
[1, 2].iter();
13+
//~^ WARNING this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter`
14+
//~| WARNING this was previously accepted by the compiler but is being phased out
15+
big.iter();
16+
//~^ WARNING this method call currently resolves to `<&[T] as IntoIterator>::into_iter`
17+
//~| WARNING this was previously accepted by the compiler but is being phased out
18+
[0u8; 33].iter();
19+
//~^ WARNING this method call currently resolves to `<&[T] as IntoIterator>::into_iter`
20+
//~| WARNING this was previously accepted by the compiler but is being phased out
21+
22+
23+
// Expressions that should not
24+
(&[1, 2]).into_iter();
25+
(&small).into_iter();
26+
(&[0u8; 33]).into_iter();
27+
(&big).into_iter();
28+
29+
for _ in &[1, 2] {}
30+
(&small as &[_]).into_iter();
31+
small[..].into_iter();
32+
std::iter::IntoIterator::into_iter(&[1, 2]);
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// run-pass
2+
// run-rustfix
3+
4+
fn main() {
5+
let small = [1, 2];
6+
let big = [0u8; 33];
7+
8+
// Expressions that should trigger the lint
9+
small.into_iter();
10+
//~^ WARNING this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter`
11+
//~| WARNING this was previously accepted by the compiler but is being phased out
12+
[1, 2].into_iter();
13+
//~^ WARNING this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter`
14+
//~| WARNING this was previously accepted by the compiler but is being phased out
15+
big.into_iter();
16+
//~^ WARNING this method call currently resolves to `<&[T] as IntoIterator>::into_iter`
17+
//~| WARNING this was previously accepted by the compiler but is being phased out
18+
[0u8; 33].into_iter();
19+
//~^ WARNING this method call currently resolves to `<&[T] as IntoIterator>::into_iter`
20+
//~| WARNING this was previously accepted by the compiler but is being phased out
21+
22+
23+
// Expressions that should not
24+
(&[1, 2]).into_iter();
25+
(&small).into_iter();
26+
(&[0u8; 33]).into_iter();
27+
(&big).into_iter();
28+
29+
for _ in &[1, 2] {}
30+
(&small as &[_]).into_iter();
31+
small[..].into_iter();
32+
std::iter::IntoIterator::into_iter(&[1, 2]);
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
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.
2+
--> $DIR/into-iter-on-arrays-lint.rs:9:11
3+
|
4+
LL | small.into_iter();
5+
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
6+
|
7+
= note: `#[warn(array_into_iter)]` on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #66145 <https://github.com/rust-lang/rust/issues/66145>
10+
11+
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.
12+
--> $DIR/into-iter-on-arrays-lint.rs:12:12
13+
|
14+
LL | [1, 2].into_iter();
15+
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
16+
|
17+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
18+
= note: for more information, see issue #66145 <https://github.com/rust-lang/rust/issues/66145>
19+
20+
warning: this method call currently resolves to `<&[T] as IntoIterator>::into_iter` (due to autoref coercions), but that might change in the future when `IntoIterator` impls for arrays are added.
21+
--> $DIR/into-iter-on-arrays-lint.rs:15:9
22+
|
23+
LL | big.into_iter();
24+
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
25+
|
26+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27+
= note: for more information, see issue #66145 <https://github.com/rust-lang/rust/issues/66145>
28+
29+
warning: this method call currently resolves to `<&[T] as IntoIterator>::into_iter` (due to autoref coercions), but that might change in the future when `IntoIterator` impls for arrays are added.
30+
--> $DIR/into-iter-on-arrays-lint.rs:18:15
31+
|
32+
LL | [0u8; 33].into_iter();
33+
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
34+
|
35+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
36+
= note: for more information, see issue #66145 <https://github.com/rust-lang/rust/issues/66145>
37+

0 commit comments

Comments
 (0)