Skip to content

New lint: decimal_bit_mask #15215

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Artur-Sulej
Copy link

@Artur-Sulej Artur-Sulej commented Jul 6, 2025

changelog: [decimal_bit_mask]: add a new lint that detects the use of decimal literals as bit masks in bitwise operations. Using decimal literals for bit masks can obscure the intended bit pattern and reduce code readability. This lint encourages the use of binary (0b...) or hexadecimal (0x...) notation to make bit patterns explicit and easier to understand at a glance.

Addresses issue: #1775


Example:

let masked = x & 15; // Bad: decimal literal as bit mask
let masked = x & 0b1111; // Good: bit pattern is explicit

Summary Notes

Managed by @rustbot—see help for details

Copy link

github-actions bot commented Jul 6, 2025

Seems that you are trying to add a new lint!
We are currently in a feature freeze, so we are delaying all lint-adding PRs to September 18 and focusing on bugfixes.
Thanks a lot for your contribution, and sorry for the inconvenience.
With ❤ from the Clippy team

@rustbot note Feature-freeze
@rustbot blocked
@rustbot label +A-lint

@rustbot rustbot added S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work A-lint Area: New lints labels Jul 6, 2025
@Artur-Sulej
Copy link
Author

Although I annotated my test with //~ decimal_bit_mask, Clippy still reports the lint as an unmatched diagnostic and the test fails.
Any idea what I might be missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants