-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New lint: concealed_obvious_default
#15037
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
base: master
Are you sure you want to change the base?
Conversation
rustbot has assigned @samueltardieu. Use |
concealed_obvious_default
lintconcealed_obvious_default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I've started a FCP thread on Zulip to discuss about the lint inclusion in Clippy.
This PR introduces a
complexity
lintconcealed_obvious_default
which 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 onResult
andEntry
for example, it suggests to replace
x.unwrap_or_default()
withx.unwrap_or(0)
wherex: Option<u8>
.Closes #14779
changelog: add [
concealed_obvious_default
] lint