New lint: `concealed_obvious_default`
This PR introduces a complexity lint concealed_obvious_default which checks usages of Option::<T>::unwrap_or_default() on a type with an obvious default and suggests using Option::<T>::unwrap_or(<default>) instead. It checks similar methods on Result and Entry
for example, it suggests to replace x.unwrap_or_default() with x.unwrap_or(0) where x: Option<u8>.
Closes rust-lang/rust-clippy#14779
changelog: add [concealed_obvious_default] lint
r? @samueltardieu
rustbot has assigned @samueltardieu. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.
Use r? to explicitly pick a reviewer
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.
Thanks for the review. I've addressed your comments and added tests to check for macro expansion both on the receiver and the method
:umbrella: 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 @rustbot ready.