-
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
Proposed changes to or_fun_call
/unwrap_or_else_default
#10080
Comments
The suggestions apply in the sense that they produce equivalent code. However, changing from |
@hrxi Would you say your point also applies to warnings like this? rust-clippy/tests/ui/unwrap_or_else_default.stderr Lines 27 to 31 in be15e60
If so, that would seem like an additional reason to merge unwrap_or_else_default into or_fun_call (regardless of its category).
|
Yes, I'd say my point also applies to this example.
Mhh, I'm not sure. unwrap_or_else(Default::default) |
Essentially, yes.
1 is more significant than 2, though, IMHO. |
Description
I propose the following changes to
or_fun_call
andunwrap_or_else_default
(which I would implement):Entry::or_default
forEntry::or_insert(Default::default())
#9342, e.g., handleor_insert_with(Default::default)
.unwrap_or_else_default
intoor_fun_call
. At present, there is an ambiguity as to where the just mentioned new functionality should go. However, I agree with @giraffate when he wrote here that things likeunwrap_or_else(Vec::new)
should be handled byor_fun_call
. Mergingunwrap_or_else_default
intoor_fun_call
would resolve the ambiguity.or_fun_call
to complexity. If I understand correctly, the "false positives" described in Make it clear thator_fun_call
can be a false-positive #9829 are because the suggestions don't improve performance, not that the suggestions don't apply. However, even when the suggestions don't improve performance, they still improve "code that does something simple but in a complex way."Note that 2 and 3 are intertwined. If I have misunderstood the reasoning in #9829, it might make sense to keep
unwrap_or_else_default
as a separate style lint. (cc: @hrxi @llogiq)Thoughts?
Version
No response
Additional Labels
No response
The text was updated successfully, but these errors were encountered: