-
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
Suggest use of unwrap_or_default #7250
Comments
+1, I see a lot of code in our code base that's like |
Oh, we've already have the |
Yes, I saw that. Though it only works when used with |
@giraffate Maybe, there should be another int, let's call it name:
Warnings message: This way, we would convert values to default, and then |
IMO
I don't want to make Clippy run multiple times. I want it to suggest the desired code once. |
I'm wondering whenever something like this would work: #8163 |
#8163 fixes this, so I'm closing this. |
What it does
Suggest using
Option::unwrap_or_default
whenOption::unwrap_or_else
is called using a function that creates the default.Categories (optional)
Makes the code shorter and more idiomatic.
Drawbacks
None.
Example
Could be written as:
Requires an understanding of what closures produce default values - e.g.
Vec::default
,Default::default
,Vec::new
,|| Vec::new()
.The text was updated successfully, but these errors were encountered: