-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.I-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
#![deny(clippy::manual_map)]
fn f(_x: &str) -> Result<bool, bool> {
Ok(false)
}
pub fn g(x: Option<String>) -> Result<(), bool> {
let _x = match x {
Some(ref x) => Some(f(x)?),
None => None,
};
Ok(())
}$ cargo clippy
error: manual implementation of `Option::map`
--> src/main.rs:8:14
|
8 | let _x = match x {
| ______________^
9 | | Some(ref x) => Some(f(x)?),
10 | | None => None,
11 | | };
| |_____^ help: try this: `x.as_ref().map(|x| f(x)?)`Applying the suggestion made by clippy makes the code not compile:
error[E0277]: the `?` operator can only be used in a closure that returns `Result` or `Option` (or another type that implements `Try`)
--> src/main.rs:8:33
|
8 | let _x = x.as_ref().map(|x| f(x)?);
| ----^^^^^
| | |
| | cannot use the `?` operator in a closure that returns `bool`
| this function should return `Result` or `Option` to accept `?`
|
= help: the trait `Try` is not implemented for `bool`
= note: required by `from_error`Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.I-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have