-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New lint: manual_is_multiple_of
#14292
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
New lint: manual_is_multiple_of
#14292
Conversation
5cfb480 to
ca4c0a9
Compare
|
Having a |
ca4c0a9 to
432b361
Compare
I've added an extra commit to test this with lintcheck. There was only one hit in Clippy sources (except for tests). |
|
@joshtriplett The lintcheck output seems quite reasonable indeed. |
|
I agree with linting the |
|
First of all, please don't treat that as a blocker; it's not as important as the That said: I've seen many, many codebases which use We may need to tune the heuristic to make sure it doesn't produce false positives, and for instance we may want a different threshold for Looking at the lintcheck output, I think I agree with not flagging |
|
What about applying the min-divisor option (maybe using another name, like min-one-bits to represent the number of ones) only to the |
|
@samueltardieu Sounds reasonable. I would say the default should flag 7 and 15 by default, and maybe 3, but not 1. Because 1 might be a flag, but 3 is definitely two bits. |
0569fb8 to
b5db45e
Compare
|
Done, see the toplevel comment for the updated option. |
|
Looking at the lintcheck output, this looks great! |
b5db45e to
2f08e6b
Compare
|
rustup happened, PR ready. |
0423c58 to
160daec
Compare
|
Rebased. |
160daec to
9c75adf
Compare
|
Rebased |
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.
Very good lint and initial implementation, some nits in this initial reviewing round (some slip-ups)
8555fb4 to
36bb8c5
Compare
|
@blyxyas Should I reassign? |
fa180dd to
541345c
Compare
|
Removed the Also updated the clippy version to 1.88. @rustbot label +S-final-comment-period |
541345c to
eae5a6d
Compare
|
Rebased to fix UI test error in |
This comment has been minimized.
This comment has been minimized.
eae5a6d to
04c0a4f
Compare
|
Rebased |
This comment has been minimized.
This comment has been minimized.
04c0a4f to
313ec7d
Compare
|
Rebased and set Clippy version to 1.89. |
This comment has been minimized.
This comment has been minimized.
313ec7d to
0f1c6f7
Compare
|
Rebased |
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.
LGTM, thanks! ❤️
@flip1995 Does this message interpret as "I'd approve this if it didn't have binops" or as "I want binops removed from this lint, but don't approve it yet".
Binary operations are now removed, and I think it looks all good for approving (I need the second +1)
|
Hey, I'm not sure what your process is, do you have some mechanism to make sure this doesn't just sit here forever? |
|
I'll revive the thread on Zulip to see if someone else can take a look at this. We just need a secondary approving look (either from Philipp or from some other maintainer, ideally from him because he raised that request). |
This prevents triggering the new `manual_is_multiple_of` lint on unrelated lint tests.
0f1c6f7 to
6ffff5f
Compare
|
Rebased (a new UI test merged in the meantime needed to get the lint applied to it). |
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.
LGTM, thanks! ❤️
I've added amin_divisorconfiguration option, default to 4, to not trigger on smaller divisibility operations. I would prefer not to lintif a & 1 == 0asif a.is_multiple_of(2)by default because the former is very idiomatic in systems (and embedded) programming.Amin_and_mask_sizeoption, defaulting to 3, sets the default bits to be and-masked before this lint triggers; that would beninv & ((1 << n) - 1) == 0. The formv % 10 == 0is always linted.This PR will stay in draft mode until the next rustup which will markunsigned_is_multiple_ofstable for Rust 1.87.0, and the feature flags will be removed.What should its category be? I've used "complexity", but "pedantic" might be suitable as well.
Close #14289
changelog: [
manual_is_multiple_of]: new lintr? ghost