Skip to content

Commit

Permalink
clippy: arithmetic-side-effects (anza-xyz#2493)
Browse files Browse the repository at this point in the history
* possible arithmetic_side_effects

* feedback

* fix test expected message

* fmt
  • Loading branch information
yihau authored and ray-kast committed Nov 27, 2024
1 parent 2049228 commit a93213b
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions sdk/program/src/epoch_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
//! [`sysvar::epoch_rewards`]: crate::sysvar::epoch_rewards
use {crate::hash::Hash, solana_sdk_macro::CloneZeroed, std::ops::AddAssign};
use {crate::hash::Hash, solana_sdk_macro::CloneZeroed};

#[repr(C, align(16))]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
Expand Down Expand Up @@ -42,9 +42,9 @@ pub struct EpochRewards {

impl EpochRewards {
pub fn distribute(&mut self, amount: u64) {
assert!(self.distributed_rewards.saturating_add(amount) <= self.total_rewards);

self.distributed_rewards.add_assign(amount);
let new_distributed_rewards = self.distributed_rewards.saturating_add(amount);
assert!(new_distributed_rewards <= self.total_rewards);
self.distributed_rewards = new_distributed_rewards;
}
}

Expand Down Expand Up @@ -86,9 +86,7 @@ mod tests {
}

#[test]
#[should_panic(
expected = "self.distributed_rewards.saturating_add(amount) <= self.total_rewards"
)]
#[should_panic(expected = "new_distributed_rewards <= self.total_rewards")]
fn test_epoch_rewards_distribute_panic() {
let mut epoch_rewards = EpochRewards::new(100, 0, 64);
epoch_rewards.distribute(200);
Expand Down

0 comments on commit a93213b

Please sign in to comment.