-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Simplify if let
statements that immediately return unwrapped value
#8288
Comments
This can be an enhancement of the |
Is it true that the It detects if let Err(err) = function_call() {
return Err(err);
} else {} but not without |
If you're referring to rust-clippy/clippy_lints/src/question_mark.rs Lines 98 to 99 in 0b143e3
else , it's because of the pattern match in L98 to only match on if_else: Some(..) .
|
Thank you for pointing that out~ |
@J-ZhengLi are you working on this? If so, you can comment |
Well... fine, I guess I'll give it a try. @rustbot claim |
Simplify if let statements fixes: #8288 --- changelog: Allowing [`qustion_mark`] lint to check `if let` expressions that immediatly return unwrapped value
What it does
Reduce simple
if let
statements that immediately return the unwrapped value by replacing theif let
with a?
.Lint Name
collapsible_if_let_return
Category
style
Advantage
Encourages concise code and proper use of the
?
operator.Drawbacks
None that I can think of.
Example
Could be written as:
And, if there were no other function logic, could further be reduced to:
The text was updated successfully, but these errors were encountered: