Skip to content

Commit 252c65e

Browse files
committed
Fix clippy tests that trigger for_loop_over_fallibles lint
1 parent 71b8c89 commit 252c65e

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/tools/clippy/tests/ui/for_loop_unfixable.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
clippy::for_kv_map
99
)]
1010
#[allow(clippy::linkedlist, clippy::unnecessary_mut_passed, clippy::similar_names)]
11+
#[allow(for_loop_over_fallibles)]
1112
fn main() {
1213
let vec = vec![1, 2, 3, 4];
1314

src/tools/clippy/tests/ui/for_loop_unfixable.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
2-
--> $DIR/for_loop_unfixable.rs:14:15
2+
--> $DIR/for_loop_unfixable.rs:15:15
33
|
44
LL | for _v in vec.iter().next() {}
55
| ^^^^^^^^^^^^^^^^^

src/tools/clippy/tests/ui/for_loops_over_fallibles.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![warn(clippy::for_loops_over_fallibles)]
2+
#![allow(for_loop_over_fallibles)]
23

34
fn for_loops_over_fallibles() {
45
let option = Some(1);

src/tools/clippy/tests/ui/for_loops_over_fallibles.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement
2-
--> $DIR/for_loops_over_fallibles.rs:9:14
2+
--> $DIR/for_loops_over_fallibles.rs:10:14
33
|
44
LL | for x in option {
55
| ^^^^^^
@@ -8,71 +8,71 @@ LL | for x in option {
88
= help: consider replacing `for x in option` with `if let Some(x) = option`
99

1010
error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement
11-
--> $DIR/for_loops_over_fallibles.rs:14:14
11+
--> $DIR/for_loops_over_fallibles.rs:15:14
1212
|
1313
LL | for x in option.iter() {
1414
| ^^^^^^
1515
|
1616
= help: consider replacing `for x in option.iter()` with `if let Some(x) = option`
1717

1818
error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement
19-
--> $DIR/for_loops_over_fallibles.rs:19:14
19+
--> $DIR/for_loops_over_fallibles.rs:20:14
2020
|
2121
LL | for x in result {
2222
| ^^^^^^
2323
|
2424
= help: consider replacing `for x in result` with `if let Ok(x) = result`
2525

2626
error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement
27-
--> $DIR/for_loops_over_fallibles.rs:24:14
27+
--> $DIR/for_loops_over_fallibles.rs:25:14
2828
|
2929
LL | for x in result.iter_mut() {
3030
| ^^^^^^
3131
|
3232
= help: consider replacing `for x in result.iter_mut()` with `if let Ok(x) = result`
3333

3434
error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement
35-
--> $DIR/for_loops_over_fallibles.rs:29:14
35+
--> $DIR/for_loops_over_fallibles.rs:30:14
3636
|
3737
LL | for x in result.into_iter() {
3838
| ^^^^^^
3939
|
4040
= help: consider replacing `for x in result.into_iter()` with `if let Ok(x) = result`
4141

4242
error: for loop over `option.ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement
43-
--> $DIR/for_loops_over_fallibles.rs:33:14
43+
--> $DIR/for_loops_over_fallibles.rs:34:14
4444
|
4545
LL | for x in option.ok_or("x not found") {
4646
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
4747
|
4848
= help: consider replacing `for x in option.ok_or("x not found")` with `if let Ok(x) = option.ok_or("x not found")`
4949

5050
error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
51-
--> $DIR/for_loops_over_fallibles.rs:39:14
51+
--> $DIR/for_loops_over_fallibles.rs:40:14
5252
|
5353
LL | for x in v.iter().next() {
5454
| ^^^^^^^^^^^^^^^
5555
|
5656
= note: `#[deny(clippy::iter_next_loop)]` on by default
5757

5858
error: for loop over `v.iter().next().and(Some(0))`, which is an `Option`. This is more readably written as an `if let` statement
59-
--> $DIR/for_loops_over_fallibles.rs:44:14
59+
--> $DIR/for_loops_over_fallibles.rs:45:14
6060
|
6161
LL | for x in v.iter().next().and(Some(0)) {
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6363
|
6464
= help: consider replacing `for x in v.iter().next().and(Some(0))` with `if let Some(x) = v.iter().next().and(Some(0))`
6565

6666
error: for loop over `v.iter().next().ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement
67-
--> $DIR/for_loops_over_fallibles.rs:48:14
67+
--> $DIR/for_loops_over_fallibles.rs:49:14
6868
|
6969
LL | for x in v.iter().next().ok_or("x not found") {
7070
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7171
|
7272
= help: consider replacing `for x in v.iter().next().ok_or("x not found")` with `if let Ok(x) = v.iter().next().ok_or("x not found")`
7373

7474
error: this loop never actually loops
75-
--> $DIR/for_loops_over_fallibles.rs:60:5
75+
--> $DIR/for_loops_over_fallibles.rs:61:5
7676
|
7777
LL | / while let Some(x) = option {
7878
LL | | println!("{}", x);
@@ -83,7 +83,7 @@ LL | | }
8383
= note: `#[deny(clippy::never_loop)]` on by default
8484

8585
error: this loop never actually loops
86-
--> $DIR/for_loops_over_fallibles.rs:66:5
86+
--> $DIR/for_loops_over_fallibles.rs:67:5
8787
|
8888
LL | / while let Ok(x) = result {
8989
LL | | println!("{}", x);

0 commit comments

Comments
 (0)