-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Suggest using unwrap_or_default()
instead of unwrap_or(<default>)
#9436
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
Conversation
Signed-off-by: xphoniex <[email protected]>
…>)` in `/src` Signed-off-by: xphoniex <[email protected]>
r? @giraffate (rust-highfive has picked a reviewer for you, use r? to override) |
r? @flip1995 |
unwrap_or_default()
instead of unwrap_or(<default>)
I don't like this because it ads an unnecessary layer of abstraction to the code without benefit. |
☔ The latest upstream changes (presumably #9447) made this pull request unmergeable. Please resolve the merge conflicts. |
I think using |
By "layer of abstraction", do you mean syntax-wise or is there a performance penalty when using |
Makes sense. But then, why do we have a |
For primitives, this also looks needlessly complex and obfuscated. The It also seems that the lint performs constant evaluation (i.e. folds Finally, I expect this to create a lot of churn, so if added, this lint must be |
I agree with @afetisov. If I remember correctly, I added |
I don't have an issue with let map: HashMap<u64, String> = make_map();
let s = map.get(idx).unwrap_or_else(String::new); The expression is more complex, you need to remember to use But the for primitive types an explicit initializer is much more clear. |
@xphoniex As we talked about this before (I think in DMs?), I agree with all the others here: The reason this lint exists for more complex types is the exact reason @afetisov brought up in the above comment: #9436 (comment) We can add an extra lint that just lints this for primitives. But then again, I don't see who would use a lint like that. So I'm strongly leaning towards not merging this PR. |
Thanks everyone for the input, I'm closing this PR. |
Closes #9435
changelog: [
or_fun_call
]: Suggest usingunwrap_or_default()
instead ofunwrap_or(<default>)