Skip to content

Commit

Permalink
removes instances of clippy::manual_let_else (#32417)
Browse files Browse the repository at this point in the history
  • Loading branch information
behzadnouri authored Jul 9, 2023
1 parent 8dfb956 commit d54b620
Show file tree
Hide file tree
Showing 46 changed files with 261 additions and 414 deletions.
13 changes: 5 additions & 8 deletions bucket_map/src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,14 +733,11 @@ impl<'b, T: Clone + Copy + 'static> Bucket<T> {
pub fn insert(&mut self, key: &Pubkey, value: (&[T], RefCount)) {
let (new, refct) = value;
loop {
let rv = self.try_write(key, new.iter(), new.len(), refct);
match rv {
Ok(_) => return,
Err(err) => {
self.grow(err);
self.handle_delayed_grows();
}
}
let Err(err) = self.try_write(key, new.iter(), new.len(), refct) else {
return;
};
self.grow(err);
self.handle_delayed_grows();
}
}

Expand Down
2 changes: 2 additions & 0 deletions ci/test-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ _ scripts/cargo-for-all-lock-files.sh -- "+${rust_nightly}" clippy --workspace -
--deny=warnings \
--deny=clippy::default_trait_access \
--deny=clippy::integer_arithmetic \
--deny=clippy::manual_let_else \
--deny=clippy::used_underscore_binding \
"${nightly_clippy_allows[@]}"

Expand All @@ -103,6 +104,7 @@ _ scripts/cargo-for-all-lock-files.sh -- clippy --workspace --tests --bins --ex
--deny=warnings \
--deny=clippy::default_trait_access \
--deny=clippy::integer_arithmetic \
--deny=clippy::manual_let_else \
--deny=clippy::used_underscore_binding

if [[ -n $CI ]]; then
Expand Down
17 changes: 7 additions & 10 deletions core/src/cluster_info_vote_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,17 +447,14 @@ impl ClusterInfoVoteListener {
verified_packets_sender: &BankingPacketSender,
verified_vote_packets: &VerifiedVotePackets,
) -> Result<()> {
let current_working_bank = match current_working_bank {
Some(current_working_bank) => current_working_bank,
None => {
// We are not the leader!
if let Some(bank_vote_sender_state) = bank_vote_sender_state_option {
// This ensures we report the last slot's metrics
bank_vote_sender_state.report_metrics();
*bank_vote_sender_state_option = None;
}
return Ok(());
let Some(current_working_bank) = current_working_bank else {
// We are not the leader!
if let Some(bank_vote_sender_state) = bank_vote_sender_state_option {
// This ensures we report the last slot's metrics
bank_vote_sender_state.report_metrics();
*bank_vote_sender_state_option = None;
}
return Ok(());
};
// We will take this lock at most once every `BANK_SEND_VOTES_LOOP_SLEEP_MS`
if let Some(bank_vote_sender_state) = bank_vote_sender_state_option {
Expand Down
5 changes: 2 additions & 3 deletions core/src/cluster_slots_service/cluster_slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,8 @@ impl ClusterSlots {
})
.collect()
};
let slot_peers = match self.lookup(slot) {
None => return stakes,
Some(slot_peers) => slot_peers,
let Some(slot_peers) = self.lookup(slot) else {
return stakes;
};
let slot_peers = slot_peers.read().unwrap();
repair_peers
Expand Down
5 changes: 2 additions & 3 deletions core/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,8 @@ impl Tower {
latest_validator_votes_for_frozen_banks: &LatestValidatorVotesForFrozenBanks,
heaviest_subtree_fork_choice: &HeaviestSubtreeForkChoice,
) -> SwitchForkDecision {
let (last_voted_slot, last_voted_hash) = match self.last_voted_slot_hash() {
None => return SwitchForkDecision::SameFork,
Some(slot_hash) => slot_hash,
let Some((last_voted_slot, last_voted_hash)) = self.last_voted_slot_hash() else {
return SwitchForkDecision::SameFork;
};
let root = self.root();
let empty_ancestors = HashSet::default();
Expand Down
27 changes: 9 additions & 18 deletions core/src/repair/ancestor_hashes_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,31 +358,22 @@ impl AncestorHashesService {
ancestor_socket: &UdpSocket,
) -> Option<AncestorRequestDecision> {
let from_addr = packet.meta().socket_addr();
let packet_data = match packet.data(..) {
Some(data) => data,
None => {
stats.invalid_packets += 1;
return None;
}
let Some(packet_data) = packet.data(..) else {
stats.invalid_packets += 1;
return None;
};
let mut cursor = Cursor::new(packet_data);
let response = match deserialize_from_with_limit(&mut cursor) {
Ok(response) => response,
Err(_) => {
stats.invalid_packets += 1;
return None;
}
let Ok(response) = deserialize_from_with_limit(&mut cursor) else {
stats.invalid_packets += 1;
return None;
};

match response {
AncestorHashesResponse::Hashes(ref hashes) => {
// deserialize trailing nonce
let nonce = match deserialize_from_with_limit(&mut cursor) {
Ok(nonce) => nonce,
Err(_) => {
stats.invalid_packets += 1;
return None;
}
let Ok(nonce) = deserialize_from_with_limit(&mut cursor) else {
stats.invalid_packets += 1;
return None;
};

// verify that packet does not contain extraneous data
Expand Down
31 changes: 15 additions & 16 deletions core/src/repair/duplicate_repair_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,10 +884,9 @@ pub mod tests {

// We don't have the earlier ancestors because we just started up, however sample should
// not be rejected as invalid.
let DuplicateAncestorDecision::EarliestMismatchFound(repair_status) = run_add_multiple_correct_and_incorrect_responses(
vec![],
&mut test_setup,
) else {
let DuplicateAncestorDecision::EarliestMismatchFound(repair_status) =
run_add_multiple_correct_and_incorrect_responses(vec![], &mut test_setup)
else {
panic!("Incorrect decision")
};
assert_eq!(
Expand Down Expand Up @@ -938,10 +937,12 @@ pub mod tests {
)];

// We have no entries in the blockstore, so all the ancestors will be missing
let DuplicateAncestorDecision::EarliestMismatchFound(repair_status) = run_add_multiple_correct_and_incorrect_responses(
desired_incorrect_responses,
&mut test_setup,
) else {
let DuplicateAncestorDecision::EarliestMismatchFound(repair_status) =
run_add_multiple_correct_and_incorrect_responses(
desired_incorrect_responses,
&mut test_setup,
)
else {
panic!("Incorrect decision")
};
assert_eq!(
Expand Down Expand Up @@ -1089,10 +1090,9 @@ pub mod tests {
}

// All the ancestors matched, only the requested slot should be dumped
let DuplicateAncestorDecision::EarliestMismatchFound(repair_status) = run_add_multiple_correct_and_incorrect_responses(
vec![],
&mut test_setup,
) else {
let DuplicateAncestorDecision::EarliestMismatchFound(repair_status) =
run_add_multiple_correct_and_incorrect_responses(vec![], &mut test_setup)
else {
panic!("Incorrect decision")
};
assert_eq!(
Expand Down Expand Up @@ -1133,10 +1133,9 @@ pub mod tests {
.add_tree(tree, true, true, 2, Hash::default());

// All the ancestors matched, only the requested slot should be dumped
let DuplicateAncestorDecision::EarliestPrunedMismatchFound(repair_status) = run_add_multiple_correct_and_incorrect_responses(
vec![],
&mut test_setup,
) else {
let DuplicateAncestorDecision::EarliestPrunedMismatchFound(repair_status) =
run_add_multiple_correct_and_incorrect_responses(vec![], &mut test_setup)
else {
panic!("Incorrect decision")
};
assert_eq!(
Expand Down
39 changes: 16 additions & 23 deletions core/src/repair/serve_repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,25 +867,19 @@ impl ServeRepair {
if u128::from(time_diff_ms) > SIGNED_REPAIR_TIME_WINDOW.as_millis() {
return Err(Error::from(RepairVerifyError::TimeSkew));
}
let leading_buf = match packet.data(..4) {
Some(buf) => buf,
None => {
debug_assert!(
false,
"request should have failed deserialization: {request:?}",
);
return Err(Error::from(RepairVerifyError::Malformed));
}
let Some(leading_buf) = packet.data(..4) else {
debug_assert!(
false,
"request should have failed deserialization: {request:?}",
);
return Err(Error::from(RepairVerifyError::Malformed));
};
let trailing_buf = match packet.data(4 + SIGNATURE_BYTES..) {
Some(buf) => buf,
None => {
debug_assert!(
false,
"request should have failed deserialization: {request:?}",
);
return Err(Error::from(RepairVerifyError::Malformed));
}
let Some(trailing_buf) = packet.data(4 + SIGNATURE_BYTES..) else {
debug_assert!(
false,
"request should have failed deserialization: {request:?}",
);
return Err(Error::from(RepairVerifyError::Malformed));
};
let from_id = request.sender();
let signed_data = [leading_buf, trailing_buf].concat();
Expand Down Expand Up @@ -978,11 +972,10 @@ impl ServeRepair {
}
}
stats.processed += 1;
let rsp = match Self::handle_repair(
recycler, &from_addr, blockstore, request, stats, ping_cache,
) {
None => continue,
Some(rsp) => rsp,
let Some(rsp) =
Self::handle_repair(recycler, &from_addr, blockstore, request, stats, ping_cache)
else {
continue;
};
let num_response_packets = rsp.len();
let num_response_bytes = rsp.iter().map(|p| p.meta().size).sum();
Expand Down
19 changes: 8 additions & 11 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2272,17 +2272,14 @@ impl ReplayStage {
return None;
}

let authorized_voter_pubkey =
if let Some(authorized_voter_pubkey) = vote_state.get_authorized_voter(bank.epoch()) {
authorized_voter_pubkey
} else {
warn!(
"Vote account {} has no authorized voter for epoch {}. Unable to vote",
vote_account_pubkey,
bank.epoch()
);
return None;
};
let Some(authorized_voter_pubkey) = vote_state.get_authorized_voter(bank.epoch()) else {
warn!(
"Vote account {} has no authorized voter for epoch {}. Unable to vote",
vote_account_pubkey,
bank.epoch()
);
return None;
};

let authorized_voter_keypair = match authorized_voter_keypairs
.iter()
Expand Down
5 changes: 2 additions & 3 deletions entry/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,8 @@ impl EntrySlice for [Entry] {
recyclers: VerifyRecyclers,
) -> EntryVerificationState {
let start = Instant::now();
let api = match perf_libs::api() {
None => return self.verify_cpu(start_hash),
Some(api) => api,
let Some(api) = perf_libs::api() else {
return self.verify_cpu(start_hash);
};
inc_new_counter_info!("entry_verify-num_entries", self.len());

Expand Down
5 changes: 2 additions & 3 deletions genesis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,8 @@ fn main() -> Result<(), Box<dyn error::Error>> {

let mut bootstrap_validator_pubkeys_iter = bootstrap_validator_pubkeys.iter();
loop {
let identity_pubkey = match bootstrap_validator_pubkeys_iter.next() {
None => break,
Some(identity_pubkey) => identity_pubkey,
let Some(identity_pubkey) = bootstrap_validator_pubkeys_iter.next() else {
break;
};
let vote_pubkey = bootstrap_validator_pubkeys_iter.next().unwrap();
let stake_pubkey = bootstrap_validator_pubkeys_iter.next().unwrap();
Expand Down
5 changes: 2 additions & 3 deletions gossip/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1412,9 +1412,8 @@ impl ClusterInfo {
const THROTTLE_DELAY: u64 = CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS / 2;
let entrypoint = {
let mut entrypoints = self.entrypoints.write().unwrap();
let entrypoint = match entrypoints.choose_mut(&mut rand::thread_rng()) {
Some(entrypoint) => entrypoint,
None => return,
let Some(entrypoint) = entrypoints.choose_mut(&mut rand::thread_rng()) else {
return;
};
if !pulls.is_empty() {
let now = timestamp();
Expand Down
10 changes: 4 additions & 6 deletions gossip/src/contact_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,11 @@ impl TryFrom<ContactInfoLite> for ContactInfo {
let mut port = 0u16;
for &SocketEntry { key, index, offset } in &node.sockets {
port += offset;
let entry = match node.cache.get_mut(usize::from(key)) {
None => continue,
Some(entry) => entry,
let Some(entry) = node.cache.get_mut(usize::from(key)) else {
continue;
};
let addr = match node.addrs.get(usize::from(index)) {
None => continue,
Some(&addr) => addr,
let Some(&addr) = node.addrs.get(usize::from(index)) else {
continue;
};
let socket = SocketAddr::new(addr, port);
if sanitize_socket(&socket).is_ok() {
Expand Down
5 changes: 2 additions & 3 deletions gossip/src/crds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,8 @@ impl Crds {
}

pub fn remove(&mut self, key: &CrdsValueLabel, now: u64) {
let (index, _ /*label*/, value) = match self.table.swap_remove_full(key) {
Some(entry) => entry,
None => return,
let Some((index, _ /*label*/, value)) = self.table.swap_remove_full(key) else {
return;
};
self.purged.push_back((value.value_hash, now));
self.shards.remove(index, &value);
Expand Down
5 changes: 2 additions & 3 deletions gossip/src/crds_gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,8 @@ pub(crate) fn maybe_ping_gossip_addresses<R: Rng + CryptoRng>(
nodes
.into_iter()
.filter(|node| {
let node_gossip = match node.gossip() {
Err(_) => return false,
Ok(addr) => addr,
let Ok(node_gossip) = node.gossip() else {
return false;
};
let (check, ping) = {
let node = (*node.pubkey(), node_gossip);
Expand Down
5 changes: 2 additions & 3 deletions gossip/src/crds_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,8 @@ impl NodeInstance {
// the same owner. Otherwise returns true if self has more recent timestamp
// than other, and so overrides it.
pub(crate) fn overrides(&self, other: &CrdsValue) -> Option<bool> {
let other = match &other.data {
CrdsData::NodeInstance(other) => other,
_ => return None,
let CrdsData::NodeInstance(other) = &other.data else {
return None;
};
if self.token == other.token || self.from != other.from {
return None;
Expand Down
7 changes: 3 additions & 4 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3016,10 +3016,9 @@ fn main() {
let mut bootstrap_validator_pubkeys_iter =
bootstrap_validator_pubkeys.iter();
loop {
let identity_pubkey = match bootstrap_validator_pubkeys_iter.next()
{
None => break,
Some(identity_pubkey) => identity_pubkey,
let Some(identity_pubkey) = bootstrap_validator_pubkeys_iter.next()
else {
break;
};
let vote_pubkey = bootstrap_validator_pubkeys_iter.next().unwrap();
let stake_pubkey = bootstrap_validator_pubkeys_iter.next().unwrap();
Expand Down
9 changes: 3 additions & 6 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1966,12 +1966,9 @@ impl Blockstore {
require_previous_blockhash: bool,
) -> Result<VersionedConfirmedBlock> {
let slot_meta_cf = self.db.column::<cf::SlotMeta>();
let slot_meta = match slot_meta_cf.get(slot)? {
Some(slot_meta) => slot_meta,
None => {
info!("SlotMeta not found for slot {}", slot);
return Err(BlockstoreError::SlotUnavailable);
}
let Some(slot_meta) = slot_meta_cf.get(slot)? else {
info!("SlotMeta not found for slot {}", slot);
return Err(BlockstoreError::SlotUnavailable);
};
if slot_meta.is_full() {
let slot_entries = self.get_slot_entries(slot, 0)?;
Expand Down
5 changes: 2 additions & 3 deletions ledger/src/blockstore_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,8 @@ impl ErasureMeta {
// Returns true if the erasure fields on the shred
// are consistent with the erasure-meta.
pub(crate) fn check_coding_shred(&self, shred: &Shred) -> bool {
let mut other = match Self::from_coding_shred(shred) {
Some(erasure_meta) => erasure_meta,
None => return false,
let Some(mut other) = Self::from_coding_shred(shred) else {
return false;
};
other.__unused_size = self.__unused_size;
self == &other
Expand Down
Loading

0 comments on commit d54b620

Please sign in to comment.