Skip to content

Commit 2305d02

Browse files
committed
Add tests for handled cases
1 parent 330b7ed commit 2305d02

10 files changed

+286
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {
2+
for _ in [0..1] {}
3+
let start = 0;
4+
let end = 0;
5+
for _ in [start..end] {}
6+
let array_of_range = [start..end];
7+
for _ in array_of_range {}
8+
for _ in [0..1, 2..3] {}
9+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error[E0277]: `[std::ops::Range<{integer}>; 1]` is not an iterator
2+
--> $DIR/array-of-ranges.rs:2:14
3+
|
4+
LL | for _ in [0..1] {}
5+
| ^^^^^^ if you meant to iterate between two values, remove the square brackets
6+
|
7+
= help: the trait `std::iter::Iterator` is not implemented for `[std::ops::Range<{integer}>; 1]`
8+
= note: `[start..end]` is an array of one `Range`, you might have meant to have a `Range`: `start..end`
9+
= note: required by `std::iter::IntoIterator::into_iter`
10+
11+
error[E0277]: `[std::ops::Range<{integer}>; 1]` is not an iterator
12+
--> $DIR/array-of-ranges.rs:5:14
13+
|
14+
LL | for _ in [start..end] {}
15+
| ^^^^^^^^^^^^ if you meant to iterate between two values, remove the square brackets
16+
|
17+
= help: the trait `std::iter::Iterator` is not implemented for `[std::ops::Range<{integer}>; 1]`
18+
= note: `[start..end]` is an array of one `Range`, you might have meant to have a `Range`: `start..end`
19+
= note: required by `std::iter::IntoIterator::into_iter`
20+
21+
error[E0277]: `[std::ops::Range<{integer}>; 1]` is not an iterator
22+
--> $DIR/array-of-ranges.rs:7:14
23+
|
24+
LL | for _ in array_of_range {}
25+
| ^^^^^^^^^^^^^^ if you meant to iterate between two values, remove the square brackets
26+
|
27+
= help: the trait `std::iter::Iterator` is not implemented for `[std::ops::Range<{integer}>; 1]`
28+
= note: `[start..end]` is an array of one `Range`, you might have meant to have a `Range`: `start..end`
29+
= note: required by `std::iter::IntoIterator::into_iter`
30+
31+
error[E0277]: `[std::ops::Range<{integer}>; 2]` is not an iterator
32+
--> $DIR/array-of-ranges.rs:8:14
33+
|
34+
LL | for _ in [0..1, 2..3] {}
35+
| ^^^^^^^^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
36+
|
37+
= help: the trait `std::iter::Iterator` is not implemented for `[std::ops::Range<{integer}>; 2]`
38+
= note: arrays are not an iterators, but slices like the following are: `&[1, 2, 3]`
39+
= note: required by `std::iter::IntoIterator::into_iter`
40+
41+
error: aborting due to 4 previous errors
42+
43+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/iterators/array.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
for _ in [1, 2] {}
3+
let x = [1, 2];
4+
for _ in x {}
5+
for _ in [1.0, 2.0] {}
6+
}

src/test/ui/iterators/array.stderr

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0277]: `[{integer}; 2]` is not an iterator
2+
--> $DIR/array.rs:2:14
3+
|
4+
LL | for _ in [1, 2] {}
5+
| ^^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
6+
|
7+
= help: the trait `std::iter::Iterator` is not implemented for `[{integer}; 2]`
8+
= note: arrays are not an iterators, but slices like the following are: `&[1, 2, 3]`
9+
= note: required by `std::iter::IntoIterator::into_iter`
10+
11+
error[E0277]: `[{integer}; 2]` is not an iterator
12+
--> $DIR/array.rs:4:14
13+
|
14+
LL | for _ in x {}
15+
| ^ borrow the array with `&` or call `.iter()` on it to iterate over it
16+
|
17+
= help: the trait `std::iter::Iterator` is not implemented for `[{integer}; 2]`
18+
= note: arrays are not an iterators, but slices like the following are: `&[1, 2, 3]`
19+
= note: required by `std::iter::IntoIterator::into_iter`
20+
21+
error[E0277]: `[{float}; 2]` is not an iterator
22+
--> $DIR/array.rs:5:14
23+
|
24+
LL | for _ in [1.0, 2.0] {}
25+
| ^^^^^^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
26+
|
27+
= help: the trait `std::iter::Iterator` is not implemented for `[{float}; 2]`
28+
= note: arrays are not an iterators, but slices like the following are: `&[1, 2, 3]`
29+
= note: required by `std::iter::IntoIterator::into_iter`
30+
31+
error: aborting due to 3 previous errors
32+
33+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/iterators/bound.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct S<I: Iterator>(I);
2+
struct T(S<u8>);
3+
fn main() {}

src/test/ui/iterators/bound.stderr

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: `u8` is not an iterator
2+
--> $DIR/bound.rs:2:10
3+
|
4+
LL | struct T(S<u8>);
5+
| ^^^^^ `u8` is not an iterator
6+
|
7+
= help: the trait `std::iter::Iterator` is not implemented for `u8`
8+
= note: if you want to iterate between `0` until a value `end`, use the range syntax: `0..end`
9+
note: required by `S`
10+
--> $DIR/bound.rs:1:1
11+
|
12+
LL | struct S<I: Iterator>(I);
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/iterators/integral.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
fn main() {
2+
for _ in 42 {}
3+
//~^ ERROR `{integer}` is not an iterator
4+
for _ in 42 as u8 {}
5+
//~^ ERROR `u8` is not an iterator
6+
for _ in 42 as i8 {}
7+
//~^ ERROR `i8` is not an iterator
8+
for _ in 42 as u16 {}
9+
//~^ ERROR `u16` is not an iterator
10+
for _ in 42 as i16 {}
11+
//~^ ERROR `i16` is not an iterator
12+
for _ in 42 as u32 {}
13+
//~^ ERROR `u32` is not an iterator
14+
for _ in 42 as i32 {}
15+
//~^ ERROR `i32` is not an iterator
16+
for _ in 42 as u64 {}
17+
//~^ ERROR `u64` is not an iterator
18+
for _ in 42 as i64 {}
19+
//~^ ERROR `i64` is not an iterator
20+
for _ in 42 as usize {}
21+
//~^ ERROR `usize` is not an iterator
22+
for _ in 42 as isize {}
23+
//~^ ERROR `isize` is not an iterator
24+
for _ in 42.0 {}
25+
//~^ ERROR `{float}` is not an iterator
26+
}

src/test/ui/iterators/integral.stderr

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
error[E0277]: `{integer}` is not an iterator
2+
--> $DIR/integral.rs:2:14
3+
|
4+
LL | for _ in 42 {}
5+
| ^^ `{integer}` is not an iterator
6+
|
7+
= help: the trait `std::iter::Iterator` is not implemented for `{integer}`
8+
= note: if you want to iterate between `0` until a value `end`, use the range syntax: `0..end`
9+
= note: required by `std::iter::IntoIterator::into_iter`
10+
11+
error[E0277]: `u8` is not an iterator
12+
--> $DIR/integral.rs:4:14
13+
|
14+
LL | for _ in 42 as u8 {}
15+
| ^^^^^^^^ `u8` is not an iterator
16+
|
17+
= help: the trait `std::iter::Iterator` is not implemented for `u8`
18+
= note: if you want to iterate between `0` until a value `end`, use the range syntax: `0..end`
19+
= note: required by `std::iter::IntoIterator::into_iter`
20+
21+
error[E0277]: `i8` is not an iterator
22+
--> $DIR/integral.rs:6:14
23+
|
24+
LL | for _ in 42 as i8 {}
25+
| ^^^^^^^^ `i8` is not an iterator
26+
|
27+
= help: the trait `std::iter::Iterator` is not implemented for `i8`
28+
= note: if you want to iterate between `0` until a value `end`, use the range syntax: `0..end`
29+
= note: required by `std::iter::IntoIterator::into_iter`
30+
31+
error[E0277]: `u16` is not an iterator
32+
--> $DIR/integral.rs:8:14
33+
|
34+
LL | for _ in 42 as u16 {}
35+
| ^^^^^^^^^ `u16` is not an iterator
36+
|
37+
= help: the trait `std::iter::Iterator` is not implemented for `u16`
38+
= note: if you want to iterate between `0` until a value `end`, use the range syntax: `0..end`
39+
= note: required by `std::iter::IntoIterator::into_iter`
40+
41+
error[E0277]: `i16` is not an iterator
42+
--> $DIR/integral.rs:10:14
43+
|
44+
LL | for _ in 42 as i16 {}
45+
| ^^^^^^^^^ `i16` is not an iterator
46+
|
47+
= help: the trait `std::iter::Iterator` is not implemented for `i16`
48+
= note: if you want to iterate between `0` until a value `end`, use the range syntax: `0..end`
49+
= note: required by `std::iter::IntoIterator::into_iter`
50+
51+
error[E0277]: `u32` is not an iterator
52+
--> $DIR/integral.rs:12:14
53+
|
54+
LL | for _ in 42 as u32 {}
55+
| ^^^^^^^^^ `u32` is not an iterator
56+
|
57+
= help: the trait `std::iter::Iterator` is not implemented for `u32`
58+
= note: if you want to iterate between `0` until a value `end`, use the range syntax: `0..end`
59+
= note: required by `std::iter::IntoIterator::into_iter`
60+
61+
error[E0277]: `i32` is not an iterator
62+
--> $DIR/integral.rs:14:14
63+
|
64+
LL | for _ in 42 as i32 {}
65+
| ^^^^^^^^^ `i32` is not an iterator
66+
|
67+
= help: the trait `std::iter::Iterator` is not implemented for `i32`
68+
= note: if you want to iterate between `0` until a value `end`, use the range syntax: `0..end`
69+
= note: required by `std::iter::IntoIterator::into_iter`
70+
71+
error[E0277]: `u64` is not an iterator
72+
--> $DIR/integral.rs:16:14
73+
|
74+
LL | for _ in 42 as u64 {}
75+
| ^^^^^^^^^ `u64` is not an iterator
76+
|
77+
= help: the trait `std::iter::Iterator` is not implemented for `u64`
78+
= note: if you want to iterate between `0` until a value `end`, use the range syntax: `0..end`
79+
= note: required by `std::iter::IntoIterator::into_iter`
80+
81+
error[E0277]: `i64` is not an iterator
82+
--> $DIR/integral.rs:18:14
83+
|
84+
LL | for _ in 42 as i64 {}
85+
| ^^^^^^^^^ `i64` is not an iterator
86+
|
87+
= help: the trait `std::iter::Iterator` is not implemented for `i64`
88+
= note: if you want to iterate between `0` until a value `end`, use the range syntax: `0..end`
89+
= note: required by `std::iter::IntoIterator::into_iter`
90+
91+
error[E0277]: `usize` is not an iterator
92+
--> $DIR/integral.rs:20:14
93+
|
94+
LL | for _ in 42 as usize {}
95+
| ^^^^^^^^^^^ `usize` is not an iterator
96+
|
97+
= help: the trait `std::iter::Iterator` is not implemented for `usize`
98+
= note: if you want to iterate between `0` until a value `end`, use the range syntax: `0..end`
99+
= note: required by `std::iter::IntoIterator::into_iter`
100+
101+
error[E0277]: `isize` is not an iterator
102+
--> $DIR/integral.rs:22:14
103+
|
104+
LL | for _ in 42 as isize {}
105+
| ^^^^^^^^^^^ `isize` is not an iterator
106+
|
107+
= help: the trait `std::iter::Iterator` is not implemented for `isize`
108+
= note: if you want to iterate between `0` until a value `end`, use the range syntax: `0..end`
109+
= note: required by `std::iter::IntoIterator::into_iter`
110+
111+
error[E0277]: `{float}` is not an iterator
112+
--> $DIR/integral.rs:24:14
113+
|
114+
LL | for _ in 42.0 {}
115+
| ^^^^ `{float}` is not an iterator
116+
|
117+
= help: the trait `std::iter::Iterator` is not implemented for `{float}`
118+
= note: required by `std::iter::IntoIterator::into_iter`
119+
120+
error: aborting due to 12 previous errors
121+
122+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/iterators/string.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
for _ in "".to_owned() {}
3+
//~^ ERROR `std::string::String` is not an iterator
4+
for _ in "" {}
5+
//~^ ERROR `&str` is not an iterator
6+
}

src/test/ui/iterators/string.stderr

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0277]: `std::string::String` is not an iterator
2+
--> $DIR/string.rs:2:14
3+
|
4+
LL | for _ in "".to_owned() {}
5+
| ^^^^^^^^^^^^^ `std::string::String` is not an iterator; try calling `.chars()` or `.bytes()`
6+
|
7+
= help: the trait `std::iter::Iterator` is not implemented for `std::string::String`
8+
= note: required by `std::iter::IntoIterator::into_iter`
9+
10+
error[E0277]: `&str` is not an iterator
11+
--> $DIR/string.rs:4:14
12+
|
13+
LL | for _ in "" {}
14+
| ^^ `&str` is not an iterator; try calling `.chars()` or `.bytes()`
15+
|
16+
= help: the trait `std::iter::Iterator` is not implemented for `&str`
17+
= note: required by `std::iter::IntoIterator::into_iter`
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)