From d40c76e667dcc2db66478d96c8ce76aafdbb747d Mon Sep 17 00:00:00 2001 From: Divma Date: Thu, 30 Jun 2022 22:51:49 +0000 Subject: [PATCH] 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) --- beacon_node/beacon_chain/src/beacon_chain.rs | 6 ++---- beacon_node/beacon_chain/src/block_verification.rs | 7 +++---- .../network/src/beacon_processor/worker/gossip_methods.rs | 4 ++-- .../network/src/subnet_service/attestation_subnets.rs | 2 +- beacon_node/src/config.rs | 4 +++- boot_node/src/lib.rs | 2 +- consensus/proto_array/src/fork_choice_test_definition.rs | 2 -- consensus/proto_array/src/proto_array.rs | 2 +- consensus/types/src/test_utils/macros.rs | 4 ++-- 9 files changed, 15 insertions(+), 18 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 5d2b35727..568179a06 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -1079,12 +1079,10 @@ impl BeaconChain { } /// Apply a function to the canonical head without cloning it. - pub fn with_head( - &self, - f: impl FnOnce(&BeaconSnapshot) -> Result, - ) -> Result + pub fn with_head(&self, f: F) -> Result where E: From, + F: FnOnce(&BeaconSnapshot) -> Result, { let head_lock = self .canonical_head diff --git a/beacon_node/beacon_chain/src/block_verification.rs b/beacon_node/beacon_chain/src/block_verification.rs index c791a35f6..a6cd98c25 100644 --- a/beacon_node/beacon_chain/src/block_verification.rs +++ b/beacon_node/beacon_chain/src/block_verification.rs @@ -1717,14 +1717,13 @@ fn verify_header_signature( .get(header.message.proposer_index as usize) .cloned() .ok_or(BlockError::UnknownValidator(header.message.proposer_index))?; - let (fork, genesis_validators_root) = chain - .with_head(|head| { + let (fork, genesis_validators_root) = + chain.with_head::<_, BlockError, _>(|head| { Ok(( head.beacon_state.fork(), head.beacon_state.genesis_validators_root(), )) - }) - .map_err(|e: BlockError| e)?; + })?; if header.verify_signature::( &proposer_pubkey, diff --git a/beacon_node/network/src/beacon_processor/worker/gossip_methods.rs b/beacon_node/network/src/beacon_processor/worker/gossip_methods.rs index aa0184110..f014af4c5 100644 --- a/beacon_node/network/src/beacon_processor/worker/gossip_methods.rs +++ b/beacon_node/network/src/beacon_processor/worker/gossip_methods.rs @@ -45,7 +45,7 @@ struct VerifiedUnaggregate { /// This implementation allows `Self` to be imported to fork choice and other functions on the /// `BeaconChain`. -impl<'a, T: BeaconChainTypes> VerifiedAttestation for VerifiedUnaggregate { +impl VerifiedAttestation for VerifiedUnaggregate { fn attestation(&self) -> &Attestation { &self.attestation } @@ -72,7 +72,7 @@ struct VerifiedAggregate { /// This implementation allows `Self` to be imported to fork choice and other functions on the /// `BeaconChain`. -impl<'a, T: BeaconChainTypes> VerifiedAttestation for VerifiedAggregate { +impl VerifiedAttestation for VerifiedAggregate { fn attestation(&self) -> &Attestation { &self.signed_aggregate.message.aggregate } diff --git a/beacon_node/network/src/subnet_service/attestation_subnets.rs b/beacon_node/network/src/subnet_service/attestation_subnets.rs index 2b0fe6f55..475bd7f17 100644 --- a/beacon_node/network/src/subnet_service/attestation_subnets.rs +++ b/beacon_node/network/src/subnet_service/attestation_subnets.rs @@ -623,7 +623,7 @@ impl Stream for AttestationService { // process any known validator expiries match self.known_validators.poll_next_unpin(cx) { Poll::Ready(Some(Ok(_validator_index))) => { - let _ = self.handle_known_validator_expiry(); + self.handle_known_validator_expiry(); } Poll::Ready(Some(Err(e))) => { error!(self.log, "Failed to check for random subnet cycles"; "error"=> e); diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index 0421df342..63cc9214f 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -11,6 +11,7 @@ use slog::{info, warn, Logger}; use std::cmp; use std::cmp::max; use std::fmt::Debug; +use std::fmt::Write; use std::fs; use std::net::{IpAddr, Ipv4Addr, ToSocketAddrs}; use std::path::{Path, PathBuf}; @@ -784,7 +785,8 @@ pub fn set_network_config( None }) { - addr.push_str(&format!(":{}", enr_udp_port)); + write!(addr, ":{}", enr_udp_port) + .map_err(|e| format!("Failed to write enr address {}", e))?; } else { return Err( "enr-udp-port must be set for node to be discoverable with dns address" diff --git a/boot_node/src/lib.rs b/boot_node/src/lib.rs index f4391f987..3d9dada0f 100644 --- a/boot_node/src/lib.rs +++ b/boot_node/src/lib.rs @@ -50,7 +50,7 @@ pub fn run( let logger = Logger::root(drain.fuse(), o!()); 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(); // Run the main function emitting any errors diff --git a/consensus/proto_array/src/fork_choice_test_definition.rs b/consensus/proto_array/src/fork_choice_test_definition.rs index 2980c019e..2be46cc59 100644 --- a/consensus/proto_array/src/fork_choice_test_definition.rs +++ b/consensus/proto_array/src/fork_choice_test_definition.rs @@ -105,7 +105,6 @@ impl ForkChoiceTestDefinition { Hash256::zero(), &spec, ) - .map_err(|e| e) .unwrap_or_else(|e| { panic!("find_head op at index {} returned error {}", op_index, e) }); @@ -132,7 +131,6 @@ impl ForkChoiceTestDefinition { proposer_boost_root, &spec, ) - .map_err(|e| e) .unwrap_or_else(|e| { panic!("find_head op at index {} returned error {}", op_index, e) }); diff --git a/consensus/proto_array/src/proto_array.rs b/consensus/proto_array/src/proto_array.rs index 3f7909553..acdb42897 100644 --- a/consensus/proto_array/src/proto_array.rs +++ b/consensus/proto_array/src/proto_array.rs @@ -240,7 +240,7 @@ impl ProtoArray { // not exist. node.weight = node .weight - .checked_sub(node_delta.abs() as u64) + .checked_sub(node_delta.unsigned_abs()) .ok_or(Error::DeltaOverflow(node_index))?; } else { node.weight = node diff --git a/consensus/types/src/test_utils/macros.rs b/consensus/types/src/test_utils/macros.rs index df449c712..1e275a576 100644 --- a/consensus/types/src/test_utils/macros.rs +++ b/consensus/types/src/test_utils/macros.rs @@ -13,8 +13,8 @@ macro_rules! ssz_tests { ($type: ty) => { #[test] pub fn test_ssz_round_trip() { - use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng}; use ssz::{ssz_encode, Decode}; + use $crate::test_utils::{SeedableRng, TestRandom, XorShiftRng}; let mut rng = XorShiftRng::from_seed([42; 16]); let original = <$type>::random_for_test(&mut rng); @@ -33,8 +33,8 @@ macro_rules! tree_hash_tests { ($type: ty) => { #[test] pub fn test_tree_hash_root() { - use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng}; use tree_hash::TreeHash; + use $crate::test_utils::{SeedableRng, TestRandom, XorShiftRng}; let mut rng = XorShiftRng::from_seed([42; 16]); let original = <$type>::random_for_test(&mut rng);