-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix false positive in cast_possible_truncation
#12722
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Alexendoo (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
BinOpKind::BitAnd => get_constant_bits(cx, right) | ||
.unwrap_or(u64::MAX) | ||
.min(get_constant_bits(cx, left).unwrap_or(u64::MAX)) | ||
.min(apply_reductions(cx, nbits, left, signed)), |
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.
We should apply reductions to right
as well, e.g. in
fn x() -> u64 {
u64::MAX
}
let _ = ((x() & 255) & 999999) as u8;
let _ = (999999 & (x() & 255)) as u8; // it would stop this one linting
That & the above added to the tests should be good to go, if you could squash the commits that would be great also
A bit of a nit but a commit message that doesn't require looking up the issue # would be ideal
Fixed formatting Added tests for issue rust-lang#12721 Checking for reduction on RHS
Great, thanks! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #12721
changelog: [
cast_possible_truncation
]: Separated checking whether integer constant has sufficient leading zeroes to be safely casted when getting remainder from bitwise and, since the latter allows a constant on either side of the operator to increase the number of leading zeroes that can be guaranteed.