Fix clippy lints for rust 1.62 (#3300)

## Issue Addressed

Fixes some new clippy lints after the last rust release
### Lints fixed for the curious:
- [cast_abs_to_unsigned](https://rust-lang.github.io/rust-clippy/master/index.html#cast_abs_to_unsigned)
- [map_identity](https://rust-lang.github.io/rust-clippy/master/index.html#map_identity) 
- [let_unit_value](https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value)
- [crate_in_macro_def](https://rust-lang.github.io/rust-clippy/master/index.html#crate_in_macro_def) 
- [extra_unused_lifetimes](https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes)
- [format_push_string](https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string)
This commit is contained in:
Divma 2022-06-30 22:51:49 +00:00
parent f6ec44f0dd
commit d40c76e667
9 changed files with 15 additions and 18 deletions

View File

@ -1079,12 +1079,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
} }
/// Apply a function to the canonical head without cloning it. /// Apply a function to the canonical head without cloning it.
pub fn with_head<U, E>( pub fn with_head<U, E, F>(&self, f: F) -> Result<U, E>
&self,
f: impl FnOnce(&BeaconSnapshot<T::EthSpec>) -> Result<U, E>,
) -> Result<U, E>
where where
E: From<Error>, E: From<Error>,
F: FnOnce(&BeaconSnapshot<T::EthSpec>) -> Result<U, E>,
{ {
let head_lock = self let head_lock = self
.canonical_head .canonical_head

View File

@ -1717,14 +1717,13 @@ fn verify_header_signature<T: BeaconChainTypes>(
.get(header.message.proposer_index as usize) .get(header.message.proposer_index as usize)
.cloned() .cloned()
.ok_or(BlockError::UnknownValidator(header.message.proposer_index))?; .ok_or(BlockError::UnknownValidator(header.message.proposer_index))?;
let (fork, genesis_validators_root) = chain let (fork, genesis_validators_root) =
.with_head(|head| { chain.with_head::<_, BlockError<T::EthSpec>, _>(|head| {
Ok(( Ok((
head.beacon_state.fork(), head.beacon_state.fork(),
head.beacon_state.genesis_validators_root(), head.beacon_state.genesis_validators_root(),
)) ))
}) })?;
.map_err(|e: BlockError<T::EthSpec>| e)?;
if header.verify_signature::<T::EthSpec>( if header.verify_signature::<T::EthSpec>(
&proposer_pubkey, &proposer_pubkey,

View File

@ -45,7 +45,7 @@ struct VerifiedUnaggregate<T: BeaconChainTypes> {
/// This implementation allows `Self` to be imported to fork choice and other functions on the /// This implementation allows `Self` to be imported to fork choice and other functions on the
/// `BeaconChain`. /// `BeaconChain`.
impl<'a, T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedUnaggregate<T> { impl<T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedUnaggregate<T> {
fn attestation(&self) -> &Attestation<T::EthSpec> { fn attestation(&self) -> &Attestation<T::EthSpec> {
&self.attestation &self.attestation
} }
@ -72,7 +72,7 @@ struct VerifiedAggregate<T: BeaconChainTypes> {
/// This implementation allows `Self` to be imported to fork choice and other functions on the /// This implementation allows `Self` to be imported to fork choice and other functions on the
/// `BeaconChain`. /// `BeaconChain`.
impl<'a, T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedAggregate<T> { impl<T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedAggregate<T> {
fn attestation(&self) -> &Attestation<T::EthSpec> { fn attestation(&self) -> &Attestation<T::EthSpec> {
&self.signed_aggregate.message.aggregate &self.signed_aggregate.message.aggregate
} }

View File

@ -623,7 +623,7 @@ impl<T: BeaconChainTypes> Stream for AttestationService<T> {
// process any known validator expiries // process any known validator expiries
match self.known_validators.poll_next_unpin(cx) { match self.known_validators.poll_next_unpin(cx) {
Poll::Ready(Some(Ok(_validator_index))) => { Poll::Ready(Some(Ok(_validator_index))) => {
let _ = self.handle_known_validator_expiry(); self.handle_known_validator_expiry();
} }
Poll::Ready(Some(Err(e))) => { Poll::Ready(Some(Err(e))) => {
error!(self.log, "Failed to check for random subnet cycles"; "error"=> e); error!(self.log, "Failed to check for random subnet cycles"; "error"=> e);

View File

@ -11,6 +11,7 @@ use slog::{info, warn, Logger};
use std::cmp; use std::cmp;
use std::cmp::max; use std::cmp::max;
use std::fmt::Debug; use std::fmt::Debug;
use std::fmt::Write;
use std::fs; use std::fs;
use std::net::{IpAddr, Ipv4Addr, ToSocketAddrs}; use std::net::{IpAddr, Ipv4Addr, ToSocketAddrs};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -784,7 +785,8 @@ pub fn set_network_config(
None None
}) })
{ {
addr.push_str(&format!(":{}", enr_udp_port)); write!(addr, ":{}", enr_udp_port)
.map_err(|e| format!("Failed to write enr address {}", e))?;
} else { } else {
return Err( return Err(
"enr-udp-port must be set for node to be discoverable with dns address" "enr-udp-port must be set for node to be discoverable with dns address"

View File

@ -50,7 +50,7 @@ pub fn run(
let logger = Logger::root(drain.fuse(), o!()); let logger = Logger::root(drain.fuse(), o!());
let _scope_guard = slog_scope::set_global_logger(logger); let _scope_guard = slog_scope::set_global_logger(logger);
let _log_guard = slog_stdlog::init_with_level(debug_level).unwrap(); slog_stdlog::init_with_level(debug_level).unwrap();
let log = slog_scope::logger(); let log = slog_scope::logger();
// Run the main function emitting any errors // Run the main function emitting any errors

View File

@ -105,7 +105,6 @@ impl ForkChoiceTestDefinition {
Hash256::zero(), Hash256::zero(),
&spec, &spec,
) )
.map_err(|e| e)
.unwrap_or_else(|e| { .unwrap_or_else(|e| {
panic!("find_head op at index {} returned error {}", op_index, e) panic!("find_head op at index {} returned error {}", op_index, e)
}); });
@ -132,7 +131,6 @@ impl ForkChoiceTestDefinition {
proposer_boost_root, proposer_boost_root,
&spec, &spec,
) )
.map_err(|e| e)
.unwrap_or_else(|e| { .unwrap_or_else(|e| {
panic!("find_head op at index {} returned error {}", op_index, e) panic!("find_head op at index {} returned error {}", op_index, e)
}); });

View File

@ -240,7 +240,7 @@ impl ProtoArray {
// not exist. // not exist.
node.weight = node node.weight = node
.weight .weight
.checked_sub(node_delta.abs() as u64) .checked_sub(node_delta.unsigned_abs())
.ok_or(Error::DeltaOverflow(node_index))?; .ok_or(Error::DeltaOverflow(node_index))?;
} else { } else {
node.weight = node node.weight = node

View File

@ -13,8 +13,8 @@ macro_rules! ssz_tests {
($type: ty) => { ($type: ty) => {
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use ssz::{ssz_encode, Decode}; use ssz::{ssz_encode, Decode};
use $crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
let mut rng = XorShiftRng::from_seed([42; 16]); let mut rng = XorShiftRng::from_seed([42; 16]);
let original = <$type>::random_for_test(&mut rng); let original = <$type>::random_for_test(&mut rng);
@ -33,8 +33,8 @@ macro_rules! tree_hash_tests {
($type: ty) => { ($type: ty) => {
#[test] #[test]
pub fn test_tree_hash_root() { pub fn test_tree_hash_root() {
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use tree_hash::TreeHash; use tree_hash::TreeHash;
use $crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
let mut rng = XorShiftRng::from_seed([42; 16]); let mut rng = XorShiftRng::from_seed([42; 16]);
let original = <$type>::random_for_test(&mut rng); let original = <$type>::random_for_test(&mut rng);