From aeb94642ce0e4e0cd5aaafa2f2ff1641c4f419bb Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 21 Jun 2022 13:10:22 +0200 Subject: [PATCH] fix clippy warnings --- liquidator/src/chain_data.rs | 4 ++-- liquidator/src/metrics.rs | 6 +++--- liquidator/src/snapshot_source.rs | 4 ++-- liquidator/src/websocket_source.rs | 2 +- programs/mango-v4/src/state/health.rs | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/liquidator/src/chain_data.rs b/liquidator/src/chain_data.rs index fd4a006fe..811f1e7b5 100644 --- a/liquidator/src/chain_data.rs +++ b/liquidator/src/chain_data.rs @@ -271,11 +271,11 @@ impl ChainData { pub fn account<'a>(&'a self, pubkey: &Pubkey) -> anyhow::Result<&'a AccountSharedData> { self.accounts .get(pubkey) - .ok_or(anyhow::anyhow!("account {} not found", pubkey))? + .ok_or_else(|| anyhow::anyhow!("account {} not found", pubkey))? .iter() .rev() .find(|w| self.is_account_write_live(w)) - .ok_or(anyhow::anyhow!("account {} has no live data", pubkey)) + .ok_or_else(|| anyhow::anyhow!("account {} has no live data", pubkey)) .map(|w| &w.account) } } diff --git a/liquidator/src/metrics.rs b/liquidator/src/metrics.rs index 5e479afd1..554426468 100644 --- a/liquidator/src/metrics.rs +++ b/liquidator/src/metrics.rs @@ -87,7 +87,7 @@ impl Metrics { let mut registry = self.registry.write().unwrap(); let value = registry .entry(name) - .or_insert(Value::U64(Arc::new(atomic::AtomicU64::new(0)))); + .or_insert_with(|| Value::U64(Arc::new(atomic::AtomicU64::new(0)))); MetricU64 { value: match value { Value::U64(v) => v.clone(), @@ -100,7 +100,7 @@ impl Metrics { let mut registry = self.registry.write().unwrap(); let value = registry .entry(name) - .or_insert(Value::I64(Arc::new(atomic::AtomicI64::new(0)))); + .or_insert_with(|| Value::I64(Arc::new(atomic::AtomicI64::new(0)))); MetricI64 { value: match value { Value::I64(v) => v.clone(), @@ -113,7 +113,7 @@ impl Metrics { let mut registry = self.registry.write().unwrap(); let value = registry .entry(name) - .or_insert(Value::String(Arc::new(Mutex::new(String::new())))); + .or_insert_with(|| Value::String(Arc::new(Mutex::new(String::new())))); MetricString { value: match value { Value::String(v) => v.clone(), diff --git a/liquidator/src/snapshot_source.rs b/liquidator/src/snapshot_source.rs index 4330dfb1d..97c8b8eca 100644 --- a/liquidator/src/snapshot_source.rs +++ b/liquidator/src/snapshot_source.rs @@ -44,7 +44,7 @@ impl AccountSnapshot { account: a .account .decode() - .ok_or(anyhow::anyhow!("could not decode account"))?, + .ok_or_else(|| anyhow::anyhow!("could not decode account"))?, }); } Ok(()) @@ -63,7 +63,7 @@ impl AccountSnapshot { pubkey, account: ui_account .decode() - .ok_or(anyhow::anyhow!("could not decode account"))?, + .ok_or_else(|| anyhow::anyhow!("could not decode account"))?, }); } } diff --git a/liquidator/src/websocket_source.rs b/liquidator/src/websocket_source.rs index 0d098742d..d9495825c 100644 --- a/liquidator/src/websocket_source.rs +++ b/liquidator/src/websocket_source.rs @@ -30,7 +30,7 @@ impl AccountUpdate { .value .account .decode() - .ok_or(anyhow::anyhow!("could not decode account"))?; + .ok_or_else(|| anyhow::anyhow!("could not decode account"))?; Ok(AccountUpdate { pubkey, slot: rpc.context.slot, diff --git a/programs/mango-v4/src/state/health.rs b/programs/mango-v4/src/state/health.rs index 568251460..32fb64afb 100644 --- a/programs/mango-v4/src/state/health.rs +++ b/programs/mango-v4/src/state/health.rs @@ -495,7 +495,7 @@ fn compute_health_detail( } // find the TokenInfos for the market's base and quote tokens - let base_index = find_token_info_index(&token_infos, serum_account.base_token_index)?; + let base_index = find_token_info_index(&token_infos, serum_account.base_token_index)?; let quote_index = find_token_info_index(&token_infos, serum_account.quote_token_index)?; let (base_info, quote_info) = if base_index < quote_index { let (l, r) = token_infos.split_at_mut(quote_index);