-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
154 additions
and
2 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
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,16 @@ | ||
// run-rustfix | ||
#![deny(clippy::option_and_then_some)] | ||
|
||
// need a main anyway, use it get rid of unused warnings too | ||
pub fn main() { | ||
let x = Some(5); | ||
// the easiest cases | ||
let _ = x; | ||
let _ = x.map(|o| o + 1); | ||
// and an easy counter-example | ||
let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); | ||
|
||
// Different type | ||
let x: Result<u32, &str> = Ok(1); | ||
let _ = x.and_then(Ok); | ||
} |
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,16 @@ | ||
// run-rustfix | ||
#![deny(clippy::option_and_then_some)] | ||
|
||
// need a main anyway, use it get rid of unused warnings too | ||
pub fn main() { | ||
let x = Some(5); | ||
// the easiest cases | ||
let _ = x.and_then(Some); | ||
let _ = x.and_then(|o| Some(o + 1)); | ||
// and an easy counter-example | ||
let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); | ||
|
||
// Different type | ||
let x: Result<u32, &str> = Ok(1); | ||
let _ = x.and_then(Ok); | ||
} |
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,20 @@ | ||
error: using `Option.and_then(Some)`, which is no-op | ||
--> $DIR/option_and_then_some.rs:8:13 | ||
| | ||
LL | let _ = x.and_then(Some); | ||
| ^^^^^^^^^^^^^^^^ help: use the expression directly: `x` | ||
| | ||
note: lint level defined here | ||
--> $DIR/option_and_then_some.rs:2:9 | ||
| | ||
LL | #![deny(clippy::option_and_then_some)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` | ||
--> $DIR/option_and_then_some.rs:9:13 | ||
| | ||
LL | let _ = x.and_then(|o| Some(o + 1)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `x.map(|o| o + 1)` | ||
|
||
error: aborting due to 2 previous errors | ||
|