-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #5032 - JohnTitor:add-sugg-some-result, r=flip1995
Add suggestions for `if_let_some_result` Fixes #4991 This approach may be fragile though... changelog: Add suggestions for `if_let_some_result`
- Loading branch information
Showing
8 changed files
with
124 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// run-rustfix | ||
|
||
#![warn(clippy::if_let_some_result)] | ||
|
||
fn str_to_int(x: &str) -> i32 { | ||
if let Ok(y) = x.parse() { | ||
y | ||
} else { | ||
0 | ||
} | ||
} | ||
|
||
fn str_to_int_ok(x: &str) -> i32 { | ||
if let Ok(y) = x.parse() { | ||
y | ||
} else { | ||
0 | ||
} | ||
} | ||
|
||
#[rustfmt::skip] | ||
fn strange_some_no_else(x: &str) -> i32 { | ||
{ | ||
if let Ok(y) = x . parse() { | ||
return y; | ||
}; | ||
0 | ||
} | ||
} | ||
|
||
fn main() { | ||
let _ = str_to_int("1"); | ||
let _ = str_to_int_ok("2"); | ||
let _ = strange_some_no_else("3"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// run-rustfix | ||
|
||
#![warn(clippy::if_let_some_result)] | ||
|
||
fn str_to_int(x: &str) -> i32 { | ||
if let Some(y) = x.parse().ok() { | ||
y | ||
} else { | ||
0 | ||
} | ||
} | ||
|
||
fn str_to_int_ok(x: &str) -> i32 { | ||
if let Ok(y) = x.parse() { | ||
y | ||
} else { | ||
0 | ||
} | ||
} | ||
|
||
#[rustfmt::skip] | ||
fn strange_some_no_else(x: &str) -> i32 { | ||
{ | ||
if let Some(y) = x . parse() . ok () { | ||
return y; | ||
}; | ||
0 | ||
} | ||
} | ||
|
||
fn main() { | ||
let _ = str_to_int("1"); | ||
let _ = str_to_int_ok("2"); | ||
let _ = strange_some_no_else("3"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
error: Matching on `Some` with `ok()` is redundant | ||
--> $DIR/if_let_some_result.rs:6:5 | ||
| | ||
LL | if let Some(y) = x.parse().ok() { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::if-let-some-result` implied by `-D warnings` | ||
help: Consider matching on `Ok(y)` and removing the call to `ok` instead | ||
| | ||
LL | if let Ok(y) = x.parse() { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: Matching on `Some` with `ok()` is redundant | ||
--> $DIR/if_let_some_result.rs:24:9 | ||
| | ||
LL | if let Some(y) = x . parse() . ok () { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: Consider matching on `Ok(y)` and removing the call to `ok` instead | ||
| | ||
LL | if let Ok(y) = x . parse() { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.