Skip to content

Commit

Permalink
Fix clippy tests that trigger for_loop_over_fallibles lint
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Aug 25, 2022
1 parent 71b8c89 commit 252c65e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/for_loop_unfixable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
clippy::for_kv_map
)]
#[allow(clippy::linkedlist, clippy::unnecessary_mut_passed, clippy::similar_names)]
#[allow(for_loop_over_fallibles)]
fn main() {
let vec = vec![1, 2, 3, 4];

Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/for_loop_unfixable.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
--> $DIR/for_loop_unfixable.rs:14:15
--> $DIR/for_loop_unfixable.rs:15:15
|
LL | for _v in vec.iter().next() {}
| ^^^^^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/for_loops_over_fallibles.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![warn(clippy::for_loops_over_fallibles)]
#![allow(for_loop_over_fallibles)]

fn for_loops_over_fallibles() {
let option = Some(1);
Expand Down
22 changes: 11 additions & 11 deletions src/tools/clippy/tests/ui/for_loops_over_fallibles.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement
--> $DIR/for_loops_over_fallibles.rs:9:14
--> $DIR/for_loops_over_fallibles.rs:10:14
|
LL | for x in option {
| ^^^^^^
Expand All @@ -8,71 +8,71 @@ LL | for x in option {
= help: consider replacing `for x in option` with `if let Some(x) = option`

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

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

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

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

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

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

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

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
--> $DIR/for_loops_over_fallibles.rs:48:14
--> $DIR/for_loops_over_fallibles.rs:49:14
|
LL | for x in v.iter().next().ok_or("x not found") {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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")`

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

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

0 comments on commit 252c65e

Please sign in to comment.