-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Fix - Upcoming arithmetic_side_effects
lints
#33000
Fix - Upcoming arithmetic_side_effects
lints
#33000
Conversation
i'd like to review some of the introduced unwraps here before merging |
I think the main ones that stood out to me are the ones with the compute budget. Those appear to be defined as constants initialized in Other unwraps involving |
a32b94d
to
9a84379
Compare
I made all the divisions which have a non-constant divisor (those used in CU consumption) to be |
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.
pushed a few more commits to wrap up arithmetic_side_effects
compatibility
@@ -763,7 +773,7 @@ declare_syscall!( | |||
let cost = compute_budget.mem_op_base_cost.max( | |||
compute_budget | |||
.sha256_byte_cost | |||
.saturating_mul((val.len() as u64).saturating_div(2)), | |||
.saturating_mul((val.len() as u64).checked_div(2).unwrap()), |
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.
it's annoying that the lint can't resolve non-zero literals. compiler can know this div is safe
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.
Does it generate a linter warning?
At -O
it is compiled to a bit shift:
pub fn square(num: u64) -> u64 {
num.checked_div(2).unwrap()
}
example::square:
mov rax, rdi
shr rax
ret
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.
I think that happens in LLVM, not in rustc. In other words, rustc is probably unaware.
513596b
to
0b2e923
Compare
0b2e923
to
7643cbb
Compare
was the commit that switched unwraps to expects dropped intentionally/ |
n/m, i see that it was squashed in. more rebase hell than i was hoping for this early in the day 😅 |
Yes, I reordered and squashed the commits to reduce the forward / backward changes. |
7643cbb
to
bbc8981
Compare
Problem
This PR is another preparation for #32961.
saturating
andwrapping
versions ofdiv
andrem
will no longer be accepted.Summary of Changes
Replaces them with their
checked
version.