-
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
Extend precedence to lint for masking bits and shifts #8735
Conversation
This changes precedence to lint for expressions like `x & 0xF000 >> 12`, where the user likely meant to mask before shifting, and suggests adding parentheses around the binary and.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon. Please see the contribution instructions for more information. |
r? @Jarcho (I'm travelling rn and might not be able to do full reviews, can rubber-stamp after you've had a look at it) |
You'll need to switch the suggestion to I'll give a proper review tomorrow. |
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.
Finished an initial read of the changes. The current implementation will lint twice on expression such as a + b & x >> d
.
I'd also like to see this extended to handle any combination of &
, |
, and ^
with either shift operation. The approach would be to change the match expression to match (op, get_bin_opt(left), get_bin_opt(right))
and then fill in arms like (BitAnd | BitOr | BitXor, Some(Shl | Shr | Add | ...), Some(Shl | Shr | Add | ...))
. get_bin_opt
will need to be written as well.
return; | ||
} | ||
let mut applicability = Applicability::MachineApplicable; | ||
match (is_arith_expr(left), is_arith_expr(right)) { |
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.
This is the match expression that would need to change.
@goth-turtle ping from triage. Can you have any question on this? |
☔ The latest upstream changes (presumably #9388) made this pull request unmergeable. Please resolve the merge conflicts. |
@goth-turtle closing this it has been inactive for 403 days. Closing this as (from your contribution history) it seems like you're no longer interested in OSS (nothing wrong about that ❤️). If you return to the community, and are interested in continuing this PR, don't hesitate to reopen this PR (●ↀωↀ●) |
Currently this lints for any expression
_ & _ << _
or_ & _ >> _
, and suggests adding parentheses, like so:(_ & _) << _
.Also, im not really sure about my wording with the documentation i added, so id appreciate some feedback on that. Thanks!
changelog: extended [
precedence
] to lint for bitmasking with shifting without parenthesesfixes #6632