-
Notifications
You must be signed in to change notification settings - Fork 1.6k
add Result to question_mark #7135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We already have the |
Yeah, the |
I found more linting cases which are currently unsupported by fn if_let_option(input: Option<String>) -> Option<usize> {
if let Some(string) = input {
return Some(string.len());
}
None
}
fn if_let_else_option(input: Option<String>) -> Option<usize> {
if let Some(string) = input {
Some(string.len())
} else {
None
}
}
fn match_option(input: Option<String>) -> Option<usize> {
match input {
Some(string) => Some(string.len()),
None => None,
}
} Could be rewritten as: fn map_option(input: Option<String>) -> Option<usize> {
input.map(|string| string.len())
}
// or
fn propagate_option(input: Option<String>) -> Option<usize> {
Some(input?.len())
} |
I think the
All those cases would be a better fit for |
Absolutely, but as I designed them I wanted to construct cases, which are equivalent to the
I am not sure as most linting cases are undeniably different from |
Let me put it differently.
|
What it does
The lint should hint to flatten the error propagation from using
match
/if let
to a more readable declarative propagation with the?
operator.Categories
clippy::style
, maybeclippy::pedantic
The control structures distract in the flow of reading and therefore the
?
operator was created. A comprehensive list of arguments can be found in the documentation of RustDrawbacks
As long as only the
Err
will always return anErr
, there should be no false-positives.Example
Could be written as:
The text was updated successfully, but these errors were encountered: