diff --git a/client/src/nonblocking/tpu_client.rs b/client/src/nonblocking/tpu_client.rs index deb34e97114b56..27ed331334141c 100644 --- a/client/src/nonblocking/tpu_client.rs +++ b/client/src/nonblocking/tpu_client.rs @@ -342,7 +342,7 @@ impl TpuClient { } } - transactions = pending_transactions.into_iter().map(|(_k, v)| v).collect(); + transactions = pending_transactions.into_values().collect(); progress_bar.println(format!( "Blockhash expired. {} retries remaining", expired_blockhash_retries diff --git a/core/benches/cluster_nodes.rs b/core/benches/cluster_nodes.rs index 10900c0bea54b3..2e359193885e26 100644 --- a/core/benches/cluster_nodes.rs +++ b/core/benches/cluster_nodes.rs @@ -36,7 +36,7 @@ fn get_retransmit_peers_deterministic( root_bank: &Bank, num_simulated_shreds: usize, ) { - let parent_offset = if slot == 0 { 0 } else { 1 }; + let parent_offset = u16::from(slot != 0); for i in 0..num_simulated_shreds { let index = i as u32; let shred = Shred::new_from_data( diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index 074be1b83261ec..a748ea701cbfec 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -1647,8 +1647,8 @@ impl BankingStage { let (units, times): (Vec<_>, Vec<_>) = execute_timings .details .per_program_timings - .iter() - .map(|(_program_id, program_timings)| { + .values() + .map(|program_timings| { ( program_timings.accumulated_units, program_timings.accumulated_us, diff --git a/core/src/repair_service.rs b/core/src/repair_service.rs index 6303ee323d1f0b..6e5047e3cd114d 100644 --- a/core/src/repair_service.rs +++ b/core/src/repair_service.rs @@ -393,14 +393,7 @@ impl RepairService { .chain(repair_stats.highest_shred.slot_pubkeys.iter()) .chain(repair_stats.orphan.slot_pubkeys.iter()) .map(|(slot, slot_repairs)| { - ( - slot, - slot_repairs - .pubkey_repairs - .iter() - .map(|(_key, count)| count) - .sum::(), - ) + (slot, slot_repairs.pubkey_repairs.values().sum::()) }) .collect(); info!("repair_stats: {:?}", slot_to_count); diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index da322cd311f4fb..880624ed182c69 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -3866,10 +3866,7 @@ pub(crate) mod tests { vec![root, root + 1] ); assert_eq!( - epoch_slots_frozen_slots - .into_iter() - .map(|(slot, _hash)| slot) - .collect::>(), + epoch_slots_frozen_slots.into_keys().collect::>(), vec![root, root + 1] ); } diff --git a/core/src/sigverify_stage.rs b/core/src/sigverify_stage.rs index 30174dc986888b..15fa4fc7cd903c 100644 --- a/core/src/sigverify_stage.rs +++ b/core/src/sigverify_stage.rs @@ -472,13 +472,9 @@ mod tests { fn count_non_discard(packet_batches: &[PacketBatch]) -> usize { packet_batches .iter() - .map(|batch| { - batch - .iter() - .map(|p| if p.meta.discard() { 0 } else { 1 }) - .sum::() - }) - .sum::() + .flatten() + .filter(|p| !p.meta.discard()) + .count() } #[test] diff --git a/genesis/src/genesis_accounts.rs b/genesis/src/genesis_accounts.rs index 1f540d4c6f72b6..0704985913838f 100644 --- a/genesis/src/genesis_accounts.rs +++ b/genesis/src/genesis_accounts.rs @@ -276,8 +276,8 @@ mod tests { let lamports = genesis_config .accounts - .iter() - .map(|(_, account)| account.lamports) + .values() + .map(|account| account.lamports) .sum::(); assert_eq!(500_000_000 * LAMPORTS_PER_SOL, lamports); diff --git a/genesis/src/main.rs b/genesis/src/main.rs index 01989e331b9892..d88516c11003c8 100644 --- a/genesis/src/main.rs +++ b/genesis/src/main.rs @@ -580,8 +580,8 @@ fn main() -> Result<(), Box> { let issued_lamports = genesis_config .accounts - .iter() - .map(|(_key, account)| account.lamports) + .values() + .map(|account| account.lamports) .sum::(); add_genesis_accounts(&mut genesis_config, issued_lamports - faucet_lamports); diff --git a/genesis/src/stakes.rs b/genesis/src/stakes.rs index a3b645ed3edc54..4fbb6d34d68daf 100644 --- a/genesis/src/stakes.rs +++ b/genesis/src/stakes.rs @@ -183,8 +183,8 @@ mod tests { assert_eq!( genesis_config .accounts - .iter() - .map(|(_pubkey, account)| account.lamports) + .values() + .map(|account| account.lamports) .sum::(), total_lamports, ); diff --git a/ledger/src/slot_stats.rs b/ledger/src/slot_stats.rs index 0f3a72defd8e43..f144eb245d4de6 100644 --- a/ledger/src/slot_stats.rs +++ b/ledger/src/slot_stats.rs @@ -39,10 +39,10 @@ pub struct SlotStats { impl SlotStats { pub fn get_min_index_count(&self) -> usize { self.turbine_fec_set_index_counts - .iter() - .map(|(_, cnt)| *cnt) + .values() .min() - .unwrap_or(0) + .copied() + .unwrap_or_default() } fn report(&self, slot: Slot) { diff --git a/log-analyzer/src/main.rs b/log-analyzer/src/main.rs index c2bd11aa072803..d28bdf597324f4 100644 --- a/log-analyzer/src/main.rs +++ b/log-analyzer/src/main.rs @@ -129,8 +129,8 @@ fn process_iftop_logs(matches: &ArgMatches) { } }); let output: Vec = unique_latest_logs - .into_iter() - .map(|(_, l)| { + .into_values() + .map(|l| { if map_list.is_empty() { l } else { diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index 3cd88ba07a1980..e3618d7494f713 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -412,7 +412,7 @@ impl PreAllocatedAccountMapEntry { account_info: T, storage: &Arc>, ) -> AccountMapEntry { - let ref_count = if account_info.is_cached() { 0 } else { 1 }; + let ref_count = u64::from(!account_info.is_cached()); let meta = AccountMapEntryMeta::new_dirty(storage); Arc::new(AccountMapEntryInner::new( vec![(slot, account_info)], @@ -2587,7 +2587,7 @@ pub mod tests { // verify the added entry matches expected { let entry = index.get_account_read_entry(&key).unwrap(); - assert_eq!(entry.ref_count(), if is_cached { 0 } else { 1 }); + assert_eq!(entry.ref_count(), u64::from(!is_cached)); let expected = vec![(slot0, account_infos[0])]; assert_eq!(entry.slot_list().to_vec(), expected); let new_entry: AccountMapEntry<_> = PreAllocatedAccountMapEntry::new( diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 66aa4a14276646..e2d048c2173120 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -16930,7 +16930,7 @@ pub(crate) mod tests { load_vote_and_stake_accounts(&bank).vote_with_stake_delegations_map; assert_eq!( vote_and_stake_accounts.len(), - if check_owner_change { 0 } else { 1 } + usize::from(!check_owner_change) ); } diff --git a/runtime/src/cost_tracker.rs b/runtime/src/cost_tracker.rs index 468730bcb54703..518ac8fb759df0 100644 --- a/runtime/src/cost_tracker.rs +++ b/runtime/src/cost_tracker.rs @@ -164,16 +164,11 @@ impl CostTracker { } fn find_costliest_account(&self) -> (Pubkey, u64) { - let mut costliest_account = Pubkey::default(); - let mut costliest_account_cost = 0; - for (key, cost) in self.cost_by_writable_accounts.iter() { - if *cost > costliest_account_cost { - costliest_account = *key; - costliest_account_cost = *cost; - } - } - - (costliest_account, costliest_account_cost) + self.cost_by_writable_accounts + .iter() + .max_by_key(|(_, &cost)| cost) + .map(|(&pubkey, &cost)| (pubkey, cost)) + .unwrap_or_default() } fn would_fit(&self, tx_cost: &TransactionCost) -> Result<(), CostTrackerError> { @@ -315,9 +310,9 @@ impl CostTracker { /// count number of none-zero CU accounts fn number_of_accounts(&self) -> usize { self.cost_by_writable_accounts - .iter() - .map(|(_key, units)| usize::from(*units > 0)) - .sum() + .values() + .filter(|units| **units > 0) + .count() } } diff --git a/runtime/src/execute_cost_table.rs b/runtime/src/execute_cost_table.rs index 922d31c1c0ed7e..0fc76974a204a2 100644 --- a/runtime/src/execute_cost_table.rs +++ b/runtime/src/execute_cost_table.rs @@ -54,7 +54,7 @@ impl ExecuteCostTable { if self.table.is_empty() { self.get_default_compute_unit_limit() } else { - self.table.iter().map(|(_, value)| value).sum::() / self.get_count() as u64 + self.table.values().sum::() / self.get_count() as u64 } } diff --git a/runtime/src/expected_rent_collection.rs b/runtime/src/expected_rent_collection.rs index 0aeb5471cb0794..4e2c45b839bb84 100644 --- a/runtime/src/expected_rent_collection.rs +++ b/runtime/src/expected_rent_collection.rs @@ -866,7 +866,7 @@ pub mod tests { ); let partition_index_passed_pubkey = partition_from_pubkey <= partition_index; let expected_rent_epoch = - rent_collector.epoch - if partition_index_passed_pubkey { 0 } else { 1 }; + rent_collector.epoch - u64::from(!partition_index_passed_pubkey); let expected_rent_collection_slot_max_epoch = first_slot_in_max_epoch + partition_from_pubkey - if partition_index_passed_pubkey { @@ -1090,7 +1090,7 @@ pub mod tests { partition_index_from_max_slot, first_slot_in_max_epoch, expected_rent_collection_slot_max_epoch, - rent_epoch: rent_collector.epoch - if hit_this_epoch { 0 } else {1}, + rent_epoch: rent_collector.epoch - u64::from(!hit_this_epoch), }), "partition_index_from_max_slot: {}, epoch: {}, hit_this_epoch: {}, skipped_slot: {}", partition_index_from_max_slot, diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index a4bd3d5f7d962f..9796ac9be667d8 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -1116,7 +1116,7 @@ impl InMemAccountsIndex { let mut count = 0; insert.into_iter().for_each(|(slot, k, v)| { let entry = (slot, v); - let new_ref_count = if v.is_cached() { 0 } else { 1 }; + let new_ref_count = u64::from(!v.is_cached()); disk.update(&k, |current| { match current { Some((current_slot_list, mut ref_count)) => { diff --git a/runtime/src/status_cache.rs b/runtime/src/status_cache.rs index 0458ddfc832b25..bb7cfc98db5c99 100644 --- a/runtime/src/status_cache.rs +++ b/runtime/src/status_cache.rs @@ -154,9 +154,7 @@ impl StatusCache { key: K, ancestors: &Ancestors, ) -> Option<(Slot, T)> { - let mut keys = vec![]; - let mut val: Vec<_> = self.cache.iter().map(|(k, _)| *k).collect(); - keys.append(&mut val); + let keys: Vec<_> = self.cache.keys().copied().collect(); for blockhash in keys.iter() { trace!("get_status_any_blockhash: trying {}", blockhash); diff --git a/sdk/src/signer/signers.rs b/sdk/src/signer/signers.rs index bd25c0d6194337..eaf2fce0e394f6 100644 --- a/sdk/src/signer/signers.rs +++ b/sdk/src/signer/signers.rs @@ -170,7 +170,6 @@ mod tests { } #[test] - #[allow(clippy::blacklisted_name)] fn test_dyn_keypairs_by_ref_compile() { let foo = Foo {}; let bar = Bar {}; diff --git a/storage-bigtable/src/lib.rs b/storage-bigtable/src/lib.rs index b644509b715793..fa96d3a102bc32 100644 --- a/storage-bigtable/src/lib.rs +++ b/storage-bigtable/src/lib.rs @@ -975,11 +975,7 @@ impl LedgerStorage { .collect(); let tx_deletion_rows = if !expected_tx_infos.is_empty() { - let signatures = expected_tx_infos - .iter() - .map(|(signature, _info)| signature) - .cloned() - .collect::>(); + let signatures = expected_tx_infos.keys().cloned().collect::>(); let fetched_tx_infos: HashMap> = self.connection .get_bincode_cells_with_retry::("tx", &signatures)