Skip to content

Commit c321cf5

Browse files
committed
Add test
1 parent 83c6c11 commit c321cf5

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

tests/ui/issue_2356.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![deny(while_let_on_iterator)]
2+
3+
use std::iter::Iterator;
4+
5+
struct Foo;
6+
7+
impl Foo {
8+
fn foo1<I: Iterator<Item = usize>>(mut it: I) {
9+
while let Some(_) = it.next() {
10+
println!("{:?}", it.size_hint());
11+
}
12+
}
13+
14+
fn foo2<I: Iterator<Item = usize>>(mut it: I) {
15+
while let Some(e) = it.next() {
16+
println!("{:?}", e);
17+
}
18+
}
19+
}
20+
21+
fn main() {
22+
Foo::foo1(vec![].into_iter());
23+
Foo::foo2(vec![].into_iter());
24+
}

tests/ui/issue_2356.stderr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: this loop could be written as a `for` loop
2+
--> $DIR/issue_2356.rs:15:29
3+
|
4+
15 | while let Some(e) = it.next() {
5+
| ^^^^^^^^^ help: try: `for e in it { .. }`
6+
|
7+
note: lint level defined here
8+
--> $DIR/issue_2356.rs:1:9
9+
|
10+
1 | #![deny(while_let_on_iterator)]
11+
| ^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)