diff --git a/account-decoder/src/parse_account_data.rs b/account-decoder/src/parse_account_data.rs index 641b4f6db2566f..2f013d76b3345b 100644 --- a/account-decoder/src/parse_account_data.rs +++ b/account-decoder/src/parse_account_data.rs @@ -81,7 +81,7 @@ pub fn parse_account_data( ) -> Result { let program_name = PARSABLE_PROGRAM_IDS .get(program_id) - .ok_or_else(|| ParseAccountError::ProgramNotParsable)?; + .ok_or(ParseAccountError::ProgramNotParsable)?; let additional_data = additional_data.unwrap_or_default(); let parsed_json = match program_name { ParsableAccount::Config => serde_json::to_value(parse_config(data, pubkey)?)?, diff --git a/core/src/broadcast_stage.rs b/core/src/broadcast_stage.rs index b62feb27ffddf5..01c757f7548026 100644 --- a/core/src/broadcast_stage.rs +++ b/core/src/broadcast_stage.rs @@ -1,4 +1,6 @@ //! A stage to broadcast data from a leader node to validators +#![allow(clippy::rc_buffer)] + use self::{ broadcast_fake_shreds_run::BroadcastFakeShredsRun, broadcast_metrics::*, fail_entry_verification_broadcast_run::FailEntryVerificationBroadcastRun, diff --git a/core/src/broadcast_stage/standard_broadcast_run.rs b/core/src/broadcast_stage/standard_broadcast_run.rs index 40756bbcd72825..b9e28c84d4076d 100644 --- a/core/src/broadcast_stage/standard_broadcast_run.rs +++ b/core/src/broadcast_stage/standard_broadcast_run.rs @@ -1,3 +1,5 @@ +#![allow(clippy::rc_buffer)] + use super::{ broadcast_utils::{self, ReceiveResults}, *, diff --git a/core/src/cluster_info.rs b/core/src/cluster_info.rs index b1066eebc42a77..399139c3f81c88 100644 --- a/core/src/cluster_info.rs +++ b/core/src/cluster_info.rs @@ -874,6 +874,7 @@ impl ClusterInfo { )) }) .collect(); + #[allow(clippy::stable_sort_primitive)] current_slots.sort(); let min_slot: Slot = current_slots .iter() @@ -1211,7 +1212,7 @@ impl ClusterInfo { self.get_lowest_slot_for_node(&x.id, None, |lowest_slot, _| { lowest_slot.lowest <= slot }) - .unwrap_or_else(|| /* fallback to legacy behavior */ true) + .unwrap_or(true /* fallback to legacy behavior */) } }) .collect(); diff --git a/core/src/cluster_slots_service.rs b/core/src/cluster_slots_service.rs index 0cd0d026365c0b..ba0ec417f7d6f0 100644 --- a/core/src/cluster_slots_service.rs +++ b/core/src/cluster_slots_service.rs @@ -125,6 +125,7 @@ impl ClusterSlotsService { while let Ok(mut more) = completed_slots_receiver.try_recv() { slots.append(&mut more); } + #[allow(clippy::stable_sort_primitive)] slots.sort(); if !slots.is_empty() { cluster_info.push_epoch_slots(&slots); @@ -163,6 +164,7 @@ impl ClusterSlotsService { while let Ok(mut more) = completed_slots_receiver.try_recv() { slots.append(&mut more); } + #[allow(clippy::stable_sort_primitive)] slots.sort(); slots.dedup(); if !slots.is_empty() { diff --git a/core/src/crds_gossip_pull.rs b/core/src/crds_gossip_pull.rs index fb92c5386cf6de..1d2a30a31229ed 100644 --- a/core/src/crds_gossip_pull.rs +++ b/core/src/crds_gossip_pull.rs @@ -337,10 +337,7 @@ impl CrdsGossipPull { for r in responses { let owner = r.label().pubkey(); // Check if the crds value is older than the msg_timeout - if now - > r.wallclock() - .checked_add(self.msg_timeout) - .unwrap_or_else(|| 0) + if now > r.wallclock().checked_add(self.msg_timeout).unwrap_or(0) || now + self.msg_timeout < r.wallclock() { match &r.label() { @@ -350,7 +347,7 @@ impl CrdsGossipPull { let timeout = *timeouts .get(&owner) .unwrap_or_else(|| timeouts.get(&Pubkey::default()).unwrap()); - if now > r.wallclock().checked_add(timeout).unwrap_or_else(|| 0) + if now > r.wallclock().checked_add(timeout).unwrap_or(0) || now + timeout < r.wallclock() { stats.timeout_count += 1; diff --git a/core/src/crds_gossip_push.rs b/core/src/crds_gossip_push.rs index edf9b028a9173d..18c1c018694497 100644 --- a/core/src/crds_gossip_push.rs +++ b/core/src/crds_gossip_push.rs @@ -175,12 +175,7 @@ impl CrdsGossipPush { now: u64, ) -> Result, CrdsGossipError> { self.num_total += 1; - if now - > value - .wallclock() - .checked_add(self.msg_timeout) - .unwrap_or_else(|| 0) - { + if now > value.wallclock().checked_add(self.msg_timeout).unwrap_or(0) { return Err(CrdsGossipError::PushMessageTimeout); } if now + self.msg_timeout < value.wallclock() { @@ -208,7 +203,7 @@ impl CrdsGossipPush { /// push pull responses pub fn push_pull_responses(&mut self, values: Vec<(CrdsValueLabel, Hash, u64)>, now: u64) { for (label, value_hash, wc) in values { - if now > wc.checked_add(self.msg_timeout).unwrap_or_else(|| 0) { + if now > wc.checked_add(self.msg_timeout).unwrap_or(0) { continue; } self.push_messages.insert(label, value_hash); diff --git a/core/src/retransmit_stage.rs b/core/src/retransmit_stage.rs index 1e75c45644dcf5..eb4888dc768c13 100644 --- a/core/src/retransmit_stage.rs +++ b/core/src/retransmit_stage.rs @@ -1,4 +1,5 @@ //! The `retransmit_stage` retransmits shreds between validators +#![allow(clippy::rc_buffer)] use crate::{ cluster_info::{compute_retransmit_peers, ClusterInfo, DATA_PLANE_FANOUT}, diff --git a/core/src/rpc_subscriptions.rs b/core/src/rpc_subscriptions.rs index e288433e75f231..b0adf3e4876329 100644 --- a/core/src/rpc_subscriptions.rs +++ b/core/src/rpc_subscriptions.rs @@ -758,6 +758,7 @@ impl RpcSubscriptions { } pub fn notify_roots(&self, mut rooted_slots: Vec) { + #[allow(clippy::stable_sort_primitive)] rooted_slots.sort(); rooted_slots.into_iter().for_each(|root| { self.enqueue_notification(NotificationEntry::Root(root)); diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index f66800ac7d8921..6c9d252f03e8bf 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -2561,7 +2561,7 @@ fn main() { println!("Ledger is empty"); } else { let first = slots.first().unwrap(); - let last = slots.last().unwrap_or_else(|| first); + let last = slots.last().unwrap_or(first); if first != last { println!("Ledger has data for slots {:?} to {:?}", first, last); if all { diff --git a/ledger/src/bigtable_upload.rs b/ledger/src/bigtable_upload.rs index dd4397553141ed..c9a05226b3f340 100644 --- a/ledger/src/bigtable_upload.rs +++ b/ledger/src/bigtable_upload.rs @@ -107,6 +107,7 @@ pub async fn upload_confirmed_blocks( .difference(&bigtable_slots) .cloned() .collect::>(); + #[allow(clippy::stable_sort_primitive)] blocks_to_upload.sort(); blocks_to_upload }; diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 76de896e831852..c50d0c7b963f19 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -1601,6 +1601,7 @@ impl Blockstore { .map(|(iter_slot, _)| iter_slot) .take(timestamp_sample_range) .collect(); + #[allow(clippy::stable_sort_primitive)] timestamp_slots.sort(); get_slots.stop(); datapoint_info!( diff --git a/ledger/src/blockstore/blockstore_purge.rs b/ledger/src/blockstore/blockstore_purge.rs index 0d4ad0a91146d0..2470cef16dc4bb 100644 --- a/ledger/src/blockstore/blockstore_purge.rs +++ b/ledger/src/blockstore/blockstore_purge.rs @@ -95,7 +95,7 @@ impl Blockstore { .batch() .expect("Database Error: Failed to get write batch"); // delete range cf is not inclusive - let to_slot = to_slot.checked_add(1).unwrap_or_else(|| std::u64::MAX); + let to_slot = to_slot.checked_add(1).unwrap_or(std::u64::MAX); let mut delete_range_timer = Measure::start("delete_range"); let mut columns_purged = self diff --git a/programs/vote/src/vote_state/mod.rs b/programs/vote/src/vote_state/mod.rs index 897599e19ebc7d..777e47f857b148 100644 --- a/programs/vote/src/vote_state/mod.rs +++ b/programs/vote/src/vote_state/mod.rs @@ -712,7 +712,7 @@ pub fn process_vote( vote.slots .iter() .max() - .ok_or_else(|| VoteError::EmptySlots) + .ok_or(VoteError::EmptySlots) .and_then(|slot| vote_state.process_timestamp(*slot, timestamp))?; } vote_account.set_state(&VoteStateVersions::Current(Box::new(vote_state))) diff --git a/ramp-tps/src/results.rs b/ramp-tps/src/results.rs index d201b4417d9249..42a1b69674a333 100644 --- a/ramp-tps/src/results.rs +++ b/ramp-tps/src/results.rs @@ -37,8 +37,7 @@ impl Results { ) -> Self { let mut results: BTreeMap> = BTreeMap::new(); previous_results.drain().for_each(|(key, value)| { - if key.starts_with(ROUND_KEY_PREFIX) { - let round_str = &key[ROUND_KEY_PREFIX.len()..]; + if let Some(round_str) = key.strip_prefix(ROUND_KEY_PREFIX) { dbg!(round_str); if let Ok(round) = u32::from_str(round_str) { if round < start_round { diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index dfa168484ffc5d..bb9cdc3ea69c14 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -2843,6 +2843,7 @@ impl AccountsDB { pub fn generate_index(&self) { let mut slots = self.storage.all_slots(); + #[allow(clippy::stable_sort_primitive)] slots.sort(); let mut last_log_update = Instant::now(); @@ -2950,6 +2951,7 @@ impl AccountsDB { fn print_index(&self, label: &str) { let mut roots: Vec<_> = self.accounts_index.all_roots(); + #[allow(clippy::stable_sort_primitive)] roots.sort(); info!("{}: accounts_index roots: {:?}", label, roots,); for (pubkey, account_entry) in self.accounts_index.account_maps.read().unwrap().iter() { @@ -2963,12 +2965,14 @@ impl AccountsDB { fn print_count_and_status(&self, label: &str) { let mut slots: Vec<_> = self.storage.all_slots(); + #[allow(clippy::stable_sort_primitive)] slots.sort(); info!("{}: count_and status for {} slots:", label, slots.len()); for slot in &slots { let slot_stores = self.storage.get_slot_stores(*slot).unwrap(); let r_slot_stores = slot_stores.read().unwrap(); let mut ids: Vec<_> = r_slot_stores.keys().cloned().collect(); + #[allow(clippy::stable_sort_primitive)] ids.sort(); for id in &ids { let entry = r_slot_stores.get(id).unwrap(); diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index f5232922471635..867379bccb3d97 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -683,6 +683,7 @@ pub struct Bank { bpf_compute_budget: Option, /// Builtin programs activated dynamically by feature + #[allow(clippy::rc_buffer)] feature_builtins: Arc>, /// Last time when the cluster info vote listener has synced with this bank @@ -1081,6 +1082,7 @@ impl Bank { } let mut ancestors: Vec<_> = roots.into_iter().collect(); + #[allow(clippy::stable_sort_primitive)] ancestors.sort(); ancestors } diff --git a/runtime/src/status_cache.rs b/runtime/src/status_cache.rs index 80da95b86debb9..ee59283a7f14d2 100644 --- a/runtime/src/status_cache.rs +++ b/runtime/src/status_cache.rs @@ -226,7 +226,7 @@ impl StatusCache { ( *slot, self.roots.contains(slot), - self.slot_deltas.get(slot).unwrap_or_else(|| &empty).clone(), + self.slot_deltas.get(slot).unwrap_or(&empty).clone(), ) }) .collect() diff --git a/sdk/src/hard_forks.rs b/sdk/src/hard_forks.rs index 42a2b2e56832d8..5781b60a264f7f 100644 --- a/sdk/src/hard_forks.rs +++ b/sdk/src/hard_forks.rs @@ -22,6 +22,7 @@ impl HardForks { } else { self.hard_forks.push((new_slot, 1)); } + #[allow(clippy::stable_sort_primitive)] self.hard_forks.sort(); } diff --git a/storage-bigtable/src/bigtable.rs b/storage-bigtable/src/bigtable.rs index a0ac3e7336f89b..af26db262afcb4 100644 --- a/storage-bigtable/src/bigtable.rs +++ b/storage-bigtable/src/bigtable.rs @@ -445,7 +445,7 @@ impl BigTable { rows.into_iter() .next() .map(|r| r.1) - .ok_or_else(|| Error::RowNotFound) + .ok_or(Error::RowNotFound) } /// Store data for one or more `table` rows in the `family_name` Column family diff --git a/transaction-status/src/parse_instruction.rs b/transaction-status/src/parse_instruction.rs index 972b15b3db9e90..b3a286a18391b8 100644 --- a/transaction-status/src/parse_instruction.rs +++ b/transaction-status/src/parse_instruction.rs @@ -82,7 +82,7 @@ pub fn parse( ) -> Result { let program_name = PARSABLE_PROGRAM_IDS .get(program_id) - .ok_or_else(|| ParseInstructionError::ProgramNotParsable)?; + .ok_or(ParseInstructionError::ProgramNotParsable)?; let parsed_json = match program_name { ParsableProgram::SplMemo => parse_memo(instruction), ParsableProgram::SplToken => serde_json::to_value(parse_token(instruction, account_keys)?)?,