Skip to content

Commit

Permalink
patches clippy errors from new rust nightly release (backport #28028) (
Browse files Browse the repository at this point in the history
…#28035)

* patches clippy errors from new rust nightly release (#28028)

(cherry picked from commit 9ee53e5)

# Conflicts:
#	core/src/repair_weighted_traversal.rs
#	runtime/src/accounts_index.rs

* removes mergify merge conflicts

Co-authored-by: behzad nouri <[email protected]>
  • Loading branch information
mergify[bot] and behzadnouri authored Sep 24, 2022
1 parent 810745f commit 1a01f33
Show file tree
Hide file tree
Showing 20 changed files with 37 additions and 63 deletions.
2 changes: 1 addition & 1 deletion client/src/nonblocking/tpu_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/benches/cluster_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 1 addition & 8 deletions core/src/repair_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u64>(),
)
(slot, slot_repairs.pubkey_repairs.values().sum::<u64>())
})
.collect();
info!("repair_stats: {:?}", slot_to_count);
Expand Down
5 changes: 1 addition & 4 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<Slot>>(),
epoch_slots_frozen_slots.into_keys().collect::<Vec<Slot>>(),
vec![root, root + 1]
);
}
Expand Down
10 changes: 3 additions & 7 deletions core/src/sigverify_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<usize>()
})
.sum::<usize>()
.flatten()
.filter(|p| !p.meta.discard())
.count()
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions genesis/src/genesis_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ mod tests {

let lamports = genesis_config
.accounts
.iter()
.map(|(_, account)| account.lamports)
.values()
.map(|account| account.lamports)
.sum::<u64>();

assert_eq!(500_000_000 * LAMPORTS_PER_SOL, lamports);
Expand Down
4 changes: 2 additions & 2 deletions genesis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,8 @@ fn main() -> Result<(), Box<dyn error::Error>> {

let issued_lamports = genesis_config
.accounts
.iter()
.map(|(_key, account)| account.lamports)
.values()
.map(|account| account.lamports)
.sum::<u64>();

add_genesis_accounts(&mut genesis_config, issued_lamports - faucet_lamports);
Expand Down
4 changes: 2 additions & 2 deletions genesis/src/stakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ mod tests {
assert_eq!(
genesis_config
.accounts
.iter()
.map(|(_pubkey, account)| account.lamports)
.values()
.map(|account| account.lamports)
.sum::<u64>(),
total_lamports,
);
Expand Down
6 changes: 3 additions & 3 deletions ledger/src/slot_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions log-analyzer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ fn process_iftop_logs(matches: &ArgMatches) {
}
});
let output: Vec<LogLine> = unique_latest_logs
.into_iter()
.map(|(_, l)| {
.into_values()
.map(|l| {
if map_list.is_empty() {
l
} else {
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ impl<T: IndexValue> PreAllocatedAccountMapEntry<T> {
account_info: T,
storage: &Arc<BucketMapHolder<T>>,
) -> AccountMapEntry<T> {
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)],
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand Down
21 changes: 8 additions & 13 deletions runtime/src/cost_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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()
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/src/execute_cost_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u64>() / self.get_count() as u64
self.table.values().sum::<u64>() / self.get_count() as u64
}
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/src/expected_rent_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/in_mem_accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
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)) => {
Expand Down
4 changes: 1 addition & 3 deletions runtime/src/status_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ impl<T: Serialize + Clone> StatusCache<T> {
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);
Expand Down
1 change: 0 additions & 1 deletion sdk/src/signer/signers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ mod tests {
}

#[test]
#[allow(clippy::blacklisted_name)]
fn test_dyn_keypairs_by_ref_compile() {
let foo = Foo {};
let bar = Bar {};
Expand Down
6 changes: 1 addition & 5 deletions storage-bigtable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
let signatures = expected_tx_infos.keys().cloned().collect::<Vec<_>>();
let fetched_tx_infos: HashMap<String, std::result::Result<UploadedTransaction, _>> =
self.connection
.get_bincode_cells_with_retry::<TransactionInfo>("tx", &signatures)
Expand Down

0 comments on commit 1a01f33

Please sign in to comment.