From 3cb2ba7a50072a16d7722a5a1bd287a3ba7f8bb9 Mon Sep 17 00:00:00 2001 From: brooks Date: Fri, 10 Jan 2025 10:06:19 -0500 Subject: [PATCH] clippy: unnecessary_map_or --- accounts-db/src/account_locks.rs | 4 +--- bench-tps/src/log_transaction_service.rs | 2 +- core/src/replay_stage.rs | 2 +- core/src/warm_quic_cache_service.rs | 4 +--- poh/src/poh_recorder.rs | 9 ++++----- programs/vote/src/vote_state/mod.rs | 2 +- runtime/src/snapshot_archive_info.rs | 4 +--- runtime/src/snapshot_utils.rs | 2 +- sdk/program/src/vote/state/mod.rs | 2 +- validator/src/bootstrap.rs | 2 +- wen-restart/src/wen_restart.rs | 2 +- 11 files changed, 14 insertions(+), 21 deletions(-) diff --git a/accounts-db/src/account_locks.rs b/accounts-db/src/account_locks.rs index fc2fba7292b10e..403ae0158f1fb9 100644 --- a/accounts-db/src/account_locks.rs +++ b/accounts-db/src/account_locks.rs @@ -62,9 +62,7 @@ impl AccountLocks { #[cfg_attr(feature = "dev-context-only-utils", qualifiers(pub))] fn is_locked_readonly(&self, key: &Pubkey) -> bool { - self.readonly_locks - .get(key) - .map_or(false, |count| *count > 0) + self.readonly_locks.get(key).is_some_and(|count| *count > 0) } #[cfg_attr(feature = "dev-context-only-utils", qualifiers(pub))] diff --git a/bench-tps/src/log_transaction_service.rs b/bench-tps/src/log_transaction_service.rs index 99b7a9cc0d6835..571df11bb30fd4 100644 --- a/bench-tps/src/log_transaction_service.rs +++ b/bench-tps/src/log_transaction_service.rs @@ -476,7 +476,7 @@ impl TransactionLogWriter { .latest() .expect("valid timestamp") }), - successful: meta.as_ref().map_or(false, |m| m.status.is_ok()), + successful: meta.as_ref().is_some_and(|m| m.status.is_ok()), error: meta .as_ref() .and_then(|m| m.err.as_ref().map(|x| x.to_string())), diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 2b40bafb4bc3ec..2fac1d7fcf51ef 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -2428,7 +2428,7 @@ impl ReplayStage { // The following differs from rooted_slots by including the parent slot of the oldest parent bank. let rooted_slots_with_parents = bank_notification_sender .as_ref() - .map_or(false, |sender| sender.should_send_parents) + .is_some_and(|sender| sender.should_send_parents) .then(|| { let mut new_chain = rooted_slots.clone(); new_chain.push(oldest_parent.unwrap_or_else(|| bank.parent_slot())); diff --git a/core/src/warm_quic_cache_service.rs b/core/src/warm_quic_cache_service.rs index c0a51f037b1c54..8833b4d525c91b 100644 --- a/core/src/warm_quic_cache_service.rs +++ b/core/src/warm_quic_cache_service.rs @@ -76,9 +76,7 @@ impl WarmQuicCacheService { .unwrap() .leader_after_n_slots((CACHE_OFFSET_SLOT + slot_jitter) as u64); if let Some(leader_pubkey) = leader_pubkey { - if maybe_last_leader - .map_or(true, |last_leader| last_leader != leader_pubkey) - { + if maybe_last_leader != Some(leader_pubkey) { maybe_last_leader = Some(leader_pubkey); // Warm cache for regular transactions Self::warmup_connection( diff --git a/poh/src/poh_recorder.rs b/poh/src/poh_recorder.rs index 0fcdb217e05fae..2791f1ed700fce 100644 --- a/poh/src/poh_recorder.rs +++ b/poh/src/poh_recorder.rs @@ -352,15 +352,14 @@ impl PohRecorder { pub fn would_be_leader(&self, within_next_n_ticks: u64) -> bool { self.has_bank() - || self.leader_first_tick_height_including_grace_ticks.map_or( - false, - |leader_first_tick_height_including_grace_ticks| { + || self + .leader_first_tick_height_including_grace_ticks + .is_some_and(|leader_first_tick_height_including_grace_ticks| { let ideal_leader_tick_height = leader_first_tick_height_including_grace_ticks .saturating_sub(self.grace_ticks); self.tick_height + within_next_n_ticks >= ideal_leader_tick_height && self.tick_height <= self.leader_last_tick_height - }, - ) + }) } // Return the slot for a given tick height diff --git a/programs/vote/src/vote_state/mod.rs b/programs/vote/src/vote_state/mod.rs index d732925bec6ad8..d2fed0fc0bceb7 100644 --- a/programs/vote/src/vote_state/mod.rs +++ b/programs/vote/src/vote_state/mod.rs @@ -451,7 +451,7 @@ fn check_slots_are_valid( // where `s` >= `last_voted_slot` if vote_state .last_voted_slot() - .map_or(false, |last_voted_slot| vote_slots[i] <= last_voted_slot) + .is_some_and(|last_voted_slot| vote_slots[i] <= last_voted_slot) { i = i .checked_add(1) diff --git a/runtime/src/snapshot_archive_info.rs b/runtime/src/snapshot_archive_info.rs index 72779718ac80dd..e203d872e04162 100644 --- a/runtime/src/snapshot_archive_info.rs +++ b/runtime/src/snapshot_archive_info.rs @@ -33,9 +33,7 @@ pub trait SnapshotArchiveInfoGetter { self.snapshot_archive_info() .path .parent() - .map_or(false, |p| { - p.ends_with(snapshot_utils::SNAPSHOT_ARCHIVE_DOWNLOAD_DIR) - }) + .is_some_and(|p| p.ends_with(snapshot_utils::SNAPSHOT_ARCHIVE_DOWNLOAD_DIR)) } } diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index 95cf08ba7d3dfe..9dad240589749d 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -114,7 +114,7 @@ impl FromStr for SnapshotVersion { // Remove leading 'v' or 'V' from slice let version_string = if version_string .get(..1) - .map_or(false, |s| s.eq_ignore_ascii_case("v")) + .is_some_and(|s| s.eq_ignore_ascii_case("v")) { &version_string[1..] } else { diff --git a/sdk/program/src/vote/state/mod.rs b/sdk/program/src/vote/state/mod.rs index 5162bff8cef9cb..9fc72c41fc882f 100644 --- a/sdk/program/src/vote/state/mod.rs +++ b/sdk/program/src/vote/state/mod.rs @@ -701,7 +701,7 @@ impl VoteState { // Ignore votes for slots earlier than we already have votes for if self .last_voted_slot() - .map_or(false, |last_voted_slot| next_vote_slot <= last_voted_slot) + .is_some_and(|last_voted_slot| next_vote_slot <= last_voted_slot) { return; } diff --git a/validator/src/bootstrap.rs b/validator/src/bootstrap.rs index 2f3e5cceb0cbb0..96bdebd4ad8930 100644 --- a/validator/src/bootstrap.rs +++ b/validator/src/bootstrap.rs @@ -189,7 +189,7 @@ fn get_rpc_peers( cluster_entrypoint .gossip() .and_then(|addr| cluster_info.lookup_contact_info_by_gossip_addr(&addr)) - .map_or(false, |entrypoint| entrypoint.shred_version() == 0) + .is_some_and(|entrypoint| entrypoint.shred_version() == 0) }); if all_zero_shred_versions { diff --git a/wen-restart/src/wen_restart.rs b/wen-restart/src/wen_restart.rs index 6f4ee589c820a0..9fa7a4abdd9068 100644 --- a/wen-restart/src/wen_restart.rs +++ b/wen-restart/src/wen_restart.rs @@ -357,7 +357,7 @@ fn is_over_stake_threshold( epoch_info_vec .iter() .find(|info| info.epoch == epoch) - .map_or(false, |info| { + .is_some_and(|info| { let threshold = info .actively_voting_stake .checked_sub((info.total_stake as f64 * HEAVIEST_FORK_THRESHOLD_DELTA) as u64)