Skip to content
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

Please separate clippy::precedence into multiple lints #14097

Closed
joshtriplett opened this issue Jan 29, 2025 · 1 comment · Fixed by #14115
Closed

Please separate clippy::precedence into multiple lints #14097

joshtriplett opened this issue Jan 29, 2025 · 1 comment · Fixed by #14115

Comments

@joshtriplett
Copy link
Member

I really appreciate the part of clippy::precedence that flags "mixed usage of arithmetic and bit shifting/combining operators without parentheses" (e.g. 1 << 2 + 3).

I would rather not have the part of clippy::precedence that flags "mixed usage of bitmasking and bit shifting operators without parentheses", because when you work with bitmasking regularly, it's reasonably well-known that x | 1 << 10 or y & 1 << 10 has the precedence you would expect.

Could clippy separate these into two separate lints, e.g. clippy::precedence_arithmetic_vs_bits and clippy::precedence_bits?

(I would also make the case that the latter should be allow-by-default, but for this issue I'm just requesting that the two be split.)

@samueltardieu
Copy link
Contributor

Agreed, as doing a lot of embedded programming and bit manipulation, this bugs me as well. I think the lint on shifting/combining operators should be in restriction.

github-merge-queue bot pushed a commit that referenced this issue Jan 30, 2025
…14115)

Commit 2550530 has extended the
`precedence` lint to include bitmasking and shift operations. The lint
is warn by default, and this generates many hits, especially in embedded
or system code, where it is very idiomatic to use expressions such as `1
<< 3 | 1 << 5` without parentheses.

This commit splits the recent addition into a new lint, which is put
into the "restriction" category, while the original one stays in
"complexity", because mixing bitmasking and arithmetic operations is
less typical.

Fix #14097

changelog: [`precedence_bits`]: new lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants