New lint: concealed_obvious_default#15037
Conversation
|
rustbot has assigned @samueltardieu. Use |
concealed_obvious_default lintconcealed_obvious_default
samueltardieu
left a comment
There was a problem hiding this comment.
Thanks, this is interesting. I've added some comments.
Also, could you split this into two commits: one with the lint applied (auto-fixed) to Clippy sources, then one with the lint itself. The order between both commits is not mandatory, but auto-fixing Clippy sources first allows the repository to pass the dogfood at every step, in case we need to bisect it.
Also, should the lint move to a allow-by-default category once we have discussed about it, removing the application commit would be easy.
14d8112 to
4f7953e
Compare
f2f906f to
bb6c0d4
Compare
Thanks for the review. I've addressed your comments and added tests to check for macro expansion both on the receiver and the method |
There was a problem hiding this comment.
Thanks. I've started a FCP thread on Zulip to discuss about the lint inclusion in Clippy.
|
☔ The latest upstream changes (possibly #14896) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Could you please rebase your PR? @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
`.unwrap_or(vec![])` is as readable as `.unwrap_or_default()`. Also, this ensures by adding tests that expressions such as `.unwrap_or(DEFAULT_LITERAL)` (`0`, `""`, etc.) are not replaced by `.unwrap_or_default()` either. Related to the discussion in the [Zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/FCP.20concealed_obvious_default) about PR #15037. changelog: [`unwrap_or_default`]: do not replace `.unwrap_or(vec![])` by `.unwrap_or_default()`
This PR introduces a
complexitylintconcealed_obvious_defaultwhich checks usages ofOption::<T>::unwrap_or_default()on a type with an obvious default and suggests usingOption::<T>::unwrap_or(<default>)instead. It checks similar methods onResultandEntryfor example, it suggests to replace
x.unwrap_or_default()withx.unwrap_or(0)wherex: Option<u8>.Closes #14779
changelog: add [
concealed_obvious_default] lint