Update to Rust 1.59 and 2021 edition (#3038)

## Proposed Changes

Lots of lint updates related to `flat_map`, `unwrap_or_else` and string patterns. I did a little more creative refactoring in the op pool, but otherwise followed Clippy's suggestions.

## Additional Info

We need this PR to unblock CI.
This commit is contained in:
Michael Sproul
2022-02-25 00:10:17 +00:00
parent c1df5d29cb
commit 5e1f8a8480
115 changed files with 173 additions and 188 deletions

View File

@@ -2289,7 +2289,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.position(|(_root, block)| {
block.slot().epoch(T::EthSpec::slots_per_epoch()) > start_epoch
})
.unwrap_or_else(|| filtered_chain_segment.len());
.unwrap_or(filtered_chain_segment.len());
// Split off the first section blocks that are all either within the current epoch of
// the first block. These blocks can all be signature-verified with the same

View File

@@ -421,10 +421,7 @@ impl<T: AggregateMap> NaiveAggregationPool<T> {
/// Iterate all items in all slots of `self`.
pub fn iter(&self) -> impl Iterator<Item = &T::Value> {
self.maps
.iter()
.map(|(_slot, map)| map.get_map().iter().map(|(_key, value)| value))
.flatten()
self.maps.values().flat_map(|map| map.get_map().values())
}
/// Removes any items with a slot lower than `current_slot` and bars any future

View File

@@ -635,7 +635,7 @@ pub fn verify_sync_committee_message<T: BeaconChainTypes>(
let pubkey = pubkey_cache
.get_pubkey_from_pubkey_bytes(pubkey_bytes)
.map(Cow::Borrowed)
.ok_or_else(|| Error::UnknownValidatorPubkey(*pubkey_bytes))?;
.ok_or(Error::UnknownValidatorPubkey(*pubkey_bytes))?;
let next_slot_epoch = (sync_message.get_slot() + 1).epoch(T::EthSpec::slots_per_epoch());
let fork = chain.spec.fork_at_epoch(next_slot_epoch);

View File

@@ -198,14 +198,11 @@ impl MonitoredValidator {
/// as the value recorded by the validator monitor ignores skip slots.
fn min_inclusion_distance(&self, epoch: &Epoch) -> Option<u64> {
let summaries = self.summaries.read();
summaries
.get(epoch)
.map(|summary| {
summary
.attestation_min_block_inclusion_distance
.map(Into::into)
})
.flatten()
summaries.get(epoch).and_then(|summary| {
summary
.attestation_min_block_inclusion_distance
.map(Into::into)
})
}
/// Maps `func` across the `self.summaries`.

View File

@@ -175,9 +175,7 @@ impl<T: BeaconChainTypes> ValidatorPubkeyCache<T> {
/// Get the `PublicKey` for a validator with `PublicKeyBytes`.
pub fn get_pubkey_from_pubkey_bytes(&self, pubkey: &PublicKeyBytes) -> Option<&PublicKey> {
self.get_index(pubkey)
.map(|index| self.get(index))
.flatten()
self.get_index(pubkey).and_then(|index| self.get(index))
}
/// Get the public key (in bytes form) for a validator with index `i`.