-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
base: master
Are you sure you want to change the base?
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. |
432b361
to
0569fb8
Compare
This prevents triggering the new `manual_is_multiple_of` lint on unrelated lint tests.
0569fb8
to
b5db45e
Compare
Done, see the toplevel comment for the updated option. |
Looking at the lintcheck output, this looks great! |
I've added amin_divisor
configuration option, default to 4, to not trigger on smaller divisibility operations. I would prefer not to lintif a & 1 == 0
asif a.is_multiple_of(2)
by default because the former is very idiomatic in systems (and embedded) programming.A
min_and_mask_size
option, defaulting to 3, sets the default bits to be and-masked before this lint triggers; that would ben
inv & ((1 << n) - 1) == 0
. The formv % 10 == 0
is always linted.This PR will stay in draft mode until the next rustup which will mark
unsigned_is_multiple_of
stable 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