removes manual let...else (#33089)
https://rust-lang.github.io/rust-clippy/master/index.html#/manual_let_else
This commit is contained in:
parent
c87f9cdfc9
commit
39615bd075
|
@ -1107,19 +1107,18 @@ impl ClusterInfo {
|
||||||
self.time_gossip_read_lock("gossip_read_push_vote", &self.stats.push_vote_read);
|
self.time_gossip_read_lock("gossip_read_push_vote", &self.stats.push_vote_read);
|
||||||
(0..MAX_LOCKOUT_HISTORY as u8).find(|ix| {
|
(0..MAX_LOCKOUT_HISTORY as u8).find(|ix| {
|
||||||
let vote = CrdsValueLabel::Vote(*ix, self_pubkey);
|
let vote = CrdsValueLabel::Vote(*ix, self_pubkey);
|
||||||
if let Some(vote) = gossip_crds.get::<&CrdsData>(&vote) {
|
let Some(vote) = gossip_crds.get::<&CrdsData>(&vote) else {
|
||||||
match &vote {
|
return false;
|
||||||
CrdsData::Vote(_, prev_vote) => match prev_vote.slot() {
|
};
|
||||||
Some(prev_vote_slot) => prev_vote_slot == vote_slot,
|
let CrdsData::Vote(_, prev_vote) = &vote else {
|
||||||
None => {
|
panic!("this should not happen!");
|
||||||
error!("crds vote with no slots!");
|
};
|
||||||
false
|
match prev_vote.slot() {
|
||||||
}
|
Some(prev_vote_slot) => prev_vote_slot == vote_slot,
|
||||||
},
|
None => {
|
||||||
_ => panic!("this should not happen!"),
|
error!("crds vote with no slots!");
|
||||||
|
false
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
@ -1153,11 +1152,10 @@ impl ClusterInfo {
|
||||||
.time_gossip_read_lock("get_votes", &self.stats.get_votes)
|
.time_gossip_read_lock("get_votes", &self.stats.get_votes)
|
||||||
.get_votes(cursor)
|
.get_votes(cursor)
|
||||||
.map(|vote| {
|
.map(|vote| {
|
||||||
let transaction = match &vote.value.data {
|
let CrdsData::Vote(_, vote) = &vote.value.data else {
|
||||||
CrdsData::Vote(_, vote) => vote.transaction().clone(),
|
panic!("this should not happen!");
|
||||||
_ => panic!("this should not happen!"),
|
|
||||||
};
|
};
|
||||||
transaction
|
vote.transaction().clone()
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
self.stats.get_votes_count.add_relaxed(txs.len() as u64);
|
self.stats.get_votes_count.add_relaxed(txs.len() as u64);
|
||||||
|
@ -1173,11 +1171,11 @@ impl ClusterInfo {
|
||||||
.time_gossip_read_lock("get_votes", &self.stats.get_votes)
|
.time_gossip_read_lock("get_votes", &self.stats.get_votes)
|
||||||
.get_votes(cursor)
|
.get_votes(cursor)
|
||||||
.map(|vote| {
|
.map(|vote| {
|
||||||
let transaction = match &vote.value.data {
|
let label = vote.value.label();
|
||||||
CrdsData::Vote(_, vote) => vote.transaction().clone(),
|
let CrdsData::Vote(_, vote) = &vote.value.data else {
|
||||||
_ => panic!("this should not happen!"),
|
panic!("this should not happen!");
|
||||||
};
|
};
|
||||||
(vote.value.label(), transaction)
|
(label, vote.transaction().clone())
|
||||||
})
|
})
|
||||||
.unzip();
|
.unzip();
|
||||||
self.stats.get_votes_count.add_relaxed(txs.len() as u64);
|
self.stats.get_votes_count.add_relaxed(txs.len() as u64);
|
||||||
|
@ -3898,12 +3896,10 @@ mod tests {
|
||||||
let gossip_crds = cluster_info.gossip.crds.read().unwrap();
|
let gossip_crds = cluster_info.gossip.crds.read().unwrap();
|
||||||
let mut vote_slots = HashSet::new();
|
let mut vote_slots = HashSet::new();
|
||||||
for label in labels {
|
for label in labels {
|
||||||
match &gossip_crds.get::<&CrdsData>(&label).unwrap() {
|
let CrdsData::Vote(_, vote) = &gossip_crds.get::<&CrdsData>(&label).unwrap() else {
|
||||||
CrdsData::Vote(_, vote) => {
|
panic!("this should not happen!");
|
||||||
assert!(vote_slots.insert(vote.slot().unwrap()));
|
};
|
||||||
}
|
assert!(vote_slots.insert(vote.slot().unwrap()));
|
||||||
_ => panic!("this should not happen!"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
vote_slots.into_iter().collect()
|
vote_slots.into_iter().collect()
|
||||||
};
|
};
|
||||||
|
|
|
@ -549,9 +549,8 @@ impl Crds {
|
||||||
self.entries.remove(&value.ordinal);
|
self.entries.remove(&value.ordinal);
|
||||||
// Remove the index from records associated with the value's pubkey.
|
// Remove the index from records associated with the value's pubkey.
|
||||||
let pubkey = value.value.pubkey();
|
let pubkey = value.value.pubkey();
|
||||||
let mut records_entry = match self.records.entry(pubkey) {
|
let hash_map::Entry::Occupied(mut records_entry) = self.records.entry(pubkey) else {
|
||||||
hash_map::Entry::Vacant(_) => panic!("this should not happen!"),
|
panic!("this should not happen!");
|
||||||
hash_map::Entry::Occupied(entry) => entry,
|
|
||||||
};
|
};
|
||||||
records_entry.get_mut().swap_remove(&index);
|
records_entry.get_mut().swap_remove(&index);
|
||||||
if records_entry.get().is_empty() {
|
if records_entry.get().is_empty() {
|
||||||
|
@ -905,10 +904,7 @@ mod tests {
|
||||||
let other = NodeInstance::new(&mut rng, pubkey, now + k);
|
let other = NodeInstance::new(&mut rng, pubkey, now + k);
|
||||||
let other = other.with_wallclock(now - 1);
|
let other = other.with_wallclock(now - 1);
|
||||||
let other = make_crds_value(other);
|
let other = make_crds_value(other);
|
||||||
match crds.insert(other, now, GossipRoute::LocalMessage) {
|
assert_matches!(crds.insert(other, now, GossipRoute::LocalMessage), Ok(()));
|
||||||
Ok(()) => (),
|
|
||||||
_ => panic!(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1148,10 +1144,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
for value in crds.get_epoch_slots(&mut Cursor(since)) {
|
for value in crds.get_epoch_slots(&mut Cursor(since)) {
|
||||||
assert!(value.ordinal >= since);
|
assert!(value.ordinal >= since);
|
||||||
match value.value.data {
|
assert_matches!(value.value.data, CrdsData::EpochSlots(_, _));
|
||||||
CrdsData::EpochSlots(_, _) => (),
|
|
||||||
_ => panic!("not an epoch-slot!"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let num_votes = crds
|
let num_votes = crds
|
||||||
.table
|
.table
|
||||||
|
@ -1174,10 +1167,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
for value in crds.get_votes(&mut Cursor(since)) {
|
for value in crds.get_votes(&mut Cursor(since)) {
|
||||||
assert!(value.ordinal >= since);
|
assert!(value.ordinal >= since);
|
||||||
match value.value.data {
|
assert_matches!(value.value.data, CrdsData::Vote(_, _));
|
||||||
CrdsData::Vote(_, _) => (),
|
|
||||||
_ => panic!("not a vote!"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let num_entries = crds
|
let num_entries = crds
|
||||||
.table
|
.table
|
||||||
|
@ -1224,16 +1214,10 @@ mod tests {
|
||||||
crds.get_epoch_slots(&mut Cursor::default()).count()
|
crds.get_epoch_slots(&mut Cursor::default()).count()
|
||||||
);
|
);
|
||||||
for vote in crds.get_votes(&mut Cursor::default()) {
|
for vote in crds.get_votes(&mut Cursor::default()) {
|
||||||
match vote.value.data {
|
assert_matches!(vote.value.data, CrdsData::Vote(_, _));
|
||||||
CrdsData::Vote(_, _) => (),
|
|
||||||
_ => panic!("not a vote!"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for epoch_slots in crds.get_epoch_slots(&mut Cursor::default()) {
|
for epoch_slots in crds.get_epoch_slots(&mut Cursor::default()) {
|
||||||
match epoch_slots.value.data {
|
assert_matches!(epoch_slots.value.data, CrdsData::EpochSlots(_, _));
|
||||||
CrdsData::EpochSlots(_, _) => (),
|
|
||||||
_ => panic!("not an epoch-slot!"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
(num_nodes, num_votes, num_epoch_slots)
|
(num_nodes, num_votes, num_epoch_slots)
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,18 +209,16 @@ impl BankForks {
|
||||||
pub fn remove(&mut self, slot: Slot) -> Option<Arc<Bank>> {
|
pub fn remove(&mut self, slot: Slot) -> Option<Arc<Bank>> {
|
||||||
let bank = self.banks.remove(&slot)?;
|
let bank = self.banks.remove(&slot)?;
|
||||||
for parent in bank.proper_ancestors() {
|
for parent in bank.proper_ancestors() {
|
||||||
let mut entry = match self.descendants.entry(parent) {
|
let Entry::Occupied(mut entry) = self.descendants.entry(parent) else {
|
||||||
Entry::Vacant(_) => panic!("this should not happen!"),
|
panic!("this should not happen!");
|
||||||
Entry::Occupied(entry) => entry,
|
|
||||||
};
|
};
|
||||||
entry.get_mut().remove(&slot);
|
entry.get_mut().remove(&slot);
|
||||||
if entry.get().is_empty() && !self.banks.contains_key(&parent) {
|
if entry.get().is_empty() && !self.banks.contains_key(&parent) {
|
||||||
entry.remove_entry();
|
entry.remove_entry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let entry = match self.descendants.entry(slot) {
|
let Entry::Occupied(entry) = self.descendants.entry(slot) else {
|
||||||
Entry::Vacant(_) => panic!("this should not happen!"),
|
panic!("this should not happen!");
|
||||||
Entry::Occupied(entry) => entry,
|
|
||||||
};
|
};
|
||||||
if entry.get().is_empty() {
|
if entry.get().is_empty() {
|
||||||
entry.remove_entry();
|
entry.remove_entry();
|
||||||
|
|
|
@ -198,15 +198,15 @@ impl VoteAccounts {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if let Some(node_pubkey) = vote_account.node_pubkey() {
|
if let Some(node_pubkey) = vote_account.node_pubkey() {
|
||||||
match Arc::make_mut(staked_nodes).entry(node_pubkey) {
|
let Entry::Occupied(mut entry) = Arc::make_mut(staked_nodes).entry(node_pubkey) else {
|
||||||
Entry::Vacant(_) => panic!("this should not happen!"),
|
panic!("this should not happen!");
|
||||||
Entry::Occupied(mut entry) => match entry.get().cmp(&stake) {
|
};
|
||||||
Ordering::Less => panic!("subtraction value exceeds node's stake"),
|
match entry.get().cmp(&stake) {
|
||||||
Ordering::Equal => {
|
Ordering::Less => panic!("subtraction value exceeds node's stake"),
|
||||||
entry.remove_entry();
|
Ordering::Equal => {
|
||||||
}
|
entry.remove_entry();
|
||||||
Ordering::Greater => *entry.get_mut() -= stake,
|
}
|
||||||
},
|
Ordering::Greater => *entry.get_mut() -= stake,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue