-
Notifications
You must be signed in to change notification settings - Fork 239
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
clippy: arithmetic-side-effects #2493
clippy: arithmetic-side-effects #2493
Conversation
sdk/program/src/epoch_rewards.rs
Outdated
assert!(self.distributed_rewards.saturating_add(amount) <= self.total_rewards); | ||
|
||
self.distributed_rewards.add_assign(amount); | ||
self.distributed_rewards = self.distributed_rewards.saturating_add(amount); |
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.
The lint seems unnecessary here, but the change to saturating add is innocuous. I don't think we need to do the addition multiple times, though
How about this:
pub fn distribute(&mut self, amount: u64) {
let new_distributed_rewards = self.distributed_rewards.saturating_add(amount);
assert!(new_distributed_rewards <= self.total_rewards);
self.distributed_rewards = new_distributed_rewards;
}
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 like it.
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.
thank you for the insight! yeah, good catch! just fixed it! 34f81e7
🤔 I'll look at that test failure. |
ah... sorry for missing the update for the test. just fixed it! |
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.
Oh nice, thanks!
* possible arithmetic_side_effects * feedback * fix test expected message * fmt
(part of #2487)
Problem
Summary of Changes
replace
add_assign
withsaturating_add