rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

New lint: `concealed_obvious_default`

Open nik-rev opened this issue 6 months ago • 2 comments

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

nik-rev avatar Jun 12 '25 15:06 nik-rev

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

rustbot avatar Jun 12 '25 15:06 rustbot

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

nik-rev avatar Jun 13 '25 15:06 nik-rev

:umbrella: The latest upstream changes (possibly #14896) made this pull request unmergeable. Please resolve the merge conflicts.

rustbot avatar Aug 17 '25 11:08 rustbot

Could you please rebase your PR?

@rustbot author

samueltardieu avatar Sep 18 '25 10:09 samueltardieu

Reminder, once the PR becomes ready for a review, use @rustbot ready.

rustbot avatar Sep 18 '25 10:09 rustbot