Skip to content

Commit

Permalink
Fix Rust 1.83 Clippy lints (#6629)
Browse files Browse the repository at this point in the history
* Fix Rust 1.83 Clippy lints

* Cargo fmt
  • Loading branch information
michaelsproul authored Nov 29, 2024
1 parent 38f5f66 commit fa6c4c0
Show file tree
Hide file tree
Showing 35 changed files with 73 additions and 77 deletions.
10 changes: 5 additions & 5 deletions beacon_node/beacon_chain/src/attestation_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ pub struct VerifiedAggregatedAttestation<'a, T: BeaconChainTypes> {
indexed_attestation: IndexedAttestation<T::EthSpec>,
}

impl<'a, T: BeaconChainTypes> VerifiedAggregatedAttestation<'a, T> {
impl<T: BeaconChainTypes> VerifiedAggregatedAttestation<'_, T> {
pub fn into_indexed_attestation(self) -> IndexedAttestation<T::EthSpec> {
self.indexed_attestation
}
Expand All @@ -319,15 +319,15 @@ pub struct VerifiedUnaggregatedAttestation<'a, T: BeaconChainTypes> {
subnet_id: SubnetId,
}

impl<'a, T: BeaconChainTypes> VerifiedUnaggregatedAttestation<'a, T> {
impl<T: BeaconChainTypes> VerifiedUnaggregatedAttestation<'_, T> {
pub fn into_indexed_attestation(self) -> IndexedAttestation<T::EthSpec> {
self.indexed_attestation
}
}

/// Custom `Clone` implementation is to avoid the restrictive trait bounds applied by the usual derive
/// macro.
impl<'a, T: BeaconChainTypes> Clone for IndexedUnaggregatedAttestation<'a, T> {
impl<T: BeaconChainTypes> Clone for IndexedUnaggregatedAttestation<'_, T> {
fn clone(&self) -> Self {
Self {
attestation: self.attestation,
Expand All @@ -353,7 +353,7 @@ pub trait VerifiedAttestation<T: BeaconChainTypes>: Sized {
}
}

impl<'a, T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedAggregatedAttestation<'a, T> {
impl<T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedAggregatedAttestation<'_, T> {
fn attestation(&self) -> AttestationRef<T::EthSpec> {
self.attestation()
}
Expand All @@ -363,7 +363,7 @@ impl<'a, T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedAggregatedAttes
}
}

impl<'a, T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedUnaggregatedAttestation<'a, T> {
impl<T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedUnaggregatedAttestation<'_, T> {
fn attestation(&self) -> AttestationRef<T::EthSpec> {
self.attestation
}
Expand Down
2 changes: 2 additions & 0 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// ## Errors
///
/// May return a database error.
#[allow(clippy::type_complexity)]
pub fn get_blocks_checking_caches(
self: &Arc<Self>,
block_roots: Vec<Hash256>,
Expand All @@ -1127,6 +1128,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
Ok(BeaconBlockStreamer::<T>::new(self, CheckCaches::Yes)?.launch_stream(block_roots))
}

#[allow(clippy::type_complexity)]
pub fn get_blocks(
self: &Arc<Self>,
block_roots: Vec<Hash256>,
Expand Down
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/src/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,7 @@ pub fn get_validator_pubkey_cache<T: BeaconChainTypes>(
///
/// The signature verifier is empty because it does not yet have any of this block's signatures
/// added to it. Use `Self::apply_to_signature_verifier` to apply the signatures.
#[allow(clippy::type_complexity)]
fn get_signature_verifier<'a, T: BeaconChainTypes>(
state: &'a BeaconState<T::EthSpec>,
validator_pubkey_cache: &'a ValidatorPubkeyCache<T>,
Expand Down
3 changes: 1 addition & 2 deletions beacon_node/beacon_chain/src/eth1_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ fn get_sync_status<E: EthSpec>(

// Determine how many voting periods are contained in distance between
// now and genesis, rounding up.
let voting_periods_past =
(seconds_till_genesis + voting_period_duration - 1) / voting_period_duration;
let voting_periods_past = seconds_till_genesis.div_ceil(voting_period_duration);

// Return the start time of the current voting period*.
//
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/src/observed_aggregates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub trait SubsetItem {
fn root(&self) -> Result<Hash256, Error>;
}

impl<'a, E: EthSpec> SubsetItem for AttestationRef<'a, E> {
impl<E: EthSpec> SubsetItem for AttestationRef<'_, E> {
type Item = BitList<E::MaxValidatorsPerSlot>;
fn is_subset(&self, other: &Self::Item) -> bool {
match self {
Expand Down Expand Up @@ -159,7 +159,7 @@ impl<'a, E: EthSpec> SubsetItem for AttestationRef<'a, E> {
}
}

impl<'a, E: EthSpec> SubsetItem for &'a SyncCommitteeContribution<E> {
impl<E: EthSpec> SubsetItem for &SyncCommitteeContribution<E> {
type Item = BitVector<E::SyncSubcommitteeSize>;
fn is_subset(&self, other: &Self::Item) -> bool {
self.aggregation_bits.is_subset(other)
Expand Down
3 changes: 1 addition & 2 deletions beacon_node/lighthouse_network/gossipsub/src/backoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ pub(crate) struct BackoffStorage {

impl BackoffStorage {
fn heartbeats(d: &Duration, heartbeat_interval: &Duration) -> usize {
((d.as_nanos() + heartbeat_interval.as_nanos() - 1) / heartbeat_interval.as_nanos())
as usize
d.as_nanos().div_ceil(heartbeat_interval.as_nanos()) as usize
}

pub(crate) fn new(
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/lighthouse_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<'de> Deserialize<'de> for PeerIdSerialized {
// A wrapper struct that prints a dial error nicely.
struct ClearDialError<'a>(&'a DialError);

impl<'a> ClearDialError<'a> {
impl ClearDialError<'_> {
fn most_inner_error(err: &(dyn std::error::Error)) -> &(dyn std::error::Error) {
let mut current = err;
while let Some(source) = current.source() {
Expand All @@ -73,7 +73,7 @@ impl<'a> ClearDialError<'a> {
}
}

impl<'a> std::fmt::Display for ClearDialError<'a> {
impl std::fmt::Display for ClearDialError<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
match &self.0 {
DialError::Transport(errors) => {
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/operation_pool/src/attestation_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<E: EthSpec> SplitAttestation<E> {
}
}

impl<'a, E: EthSpec> CompactAttestationRef<'a, E> {
impl<E: EthSpec> CompactAttestationRef<'_, E> {
pub fn attestation_data(&self) -> AttestationData {
AttestationData {
slot: self.data.slot,
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/store/src/chunked_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
}
}

impl<'a, F, E, Hot, Cold> Iterator for ChunkedVectorIter<'a, F, E, Hot, Cold>
impl<F, E, Hot, Cold> Iterator for ChunkedVectorIter<'_, F, E, Hot, Cold>
where
F: Field<E>,
E: EthSpec,
Expand Down
8 changes: 4 additions & 4 deletions beacon_node/store/src/forwards_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
}
}

impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for FrozenForwardsIterator<'a, E, Hot, Cold>
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for FrozenForwardsIterator<'_, E, Hot, Cold>
{
type Item = Result<(Hash256, Slot)>;

Expand Down Expand Up @@ -349,8 +349,8 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
}
}

impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for HybridForwardsIterator<'a, E, Hot, Cold>
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for HybridForwardsIterator<'_, E, Hot, Cold>
{
type Item = Result<(Hash256, Slot)>;

Expand Down
32 changes: 15 additions & 17 deletions beacon_node/store/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pub struct StateRootsIterator<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore
inner: RootsIterator<'a, E, Hot, Cold>,
}

impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Clone
for StateRootsIterator<'a, E, Hot, Cold>
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Clone
for StateRootsIterator<'_, E, Hot, Cold>
{
fn clone(&self) -> Self {
Self {
Expand All @@ -77,8 +77,8 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> StateRootsIterator<'
}
}

impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for StateRootsIterator<'a, E, Hot, Cold>
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for StateRootsIterator<'_, E, Hot, Cold>
{
type Item = Result<(Hash256, Slot), Error>;

Expand All @@ -101,8 +101,8 @@ pub struct BlockRootsIterator<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore
inner: RootsIterator<'a, E, Hot, Cold>,
}

impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Clone
for BlockRootsIterator<'a, E, Hot, Cold>
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Clone
for BlockRootsIterator<'_, E, Hot, Cold>
{
fn clone(&self) -> Self {
Self {
Expand Down Expand Up @@ -136,8 +136,8 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BlockRootsIterator<'
}
}

impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for BlockRootsIterator<'a, E, Hot, Cold>
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for BlockRootsIterator<'_, E, Hot, Cold>
{
type Item = Result<(Hash256, Slot), Error>;

Expand All @@ -155,9 +155,7 @@ pub struct RootsIterator<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
slot: Slot,
}

impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Clone
for RootsIterator<'a, E, Hot, Cold>
{
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Clone for RootsIterator<'_, E, Hot, Cold> {
fn clone(&self) -> Self {
Self {
store: self.store,
Expand Down Expand Up @@ -232,8 +230,8 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> RootsIterator<'a, E,
}
}

impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for RootsIterator<'a, E, Hot, Cold>
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for RootsIterator<'_, E, Hot, Cold>
{
/// (block_root, state_root, slot)
type Item = Result<(Hash256, Hash256, Slot), Error>;
Expand Down Expand Up @@ -295,8 +293,8 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
}
}

impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for ParentRootBlockIterator<'a, E, Hot, Cold>
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for ParentRootBlockIterator<'_, E, Hot, Cold>
{
type Item = Result<(Hash256, SignedBeaconBlock<E, BlindedPayload<E>>), Error>;

Expand Down Expand Up @@ -336,8 +334,8 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BlockIterator<'a, E,
}
}

impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for BlockIterator<'a, E, Hot, Cold>
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for BlockIterator<'_, E, Hot, Cold>
{
type Item = Result<SignedBeaconBlock<E, BlindedPayload<E>>, Error>;

Expand Down
6 changes: 3 additions & 3 deletions common/eth2/src/lighthouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,9 @@ impl BeaconNodeHttpClient {
self.post_with_response(path, &()).await
}

///
/// Analysis endpoints.
///
/*
Analysis endpoints.
*/

/// `GET` lighthouse/analysis/block_rewards?start_slot,end_slot
pub async fn get_lighthouse_analysis_block_rewards(
Expand Down
2 changes: 1 addition & 1 deletion common/eth2_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub struct Eth2NetArchiveAndDirectory<'a> {
pub genesis_state_source: GenesisStateSource,
}

impl<'a> Eth2NetArchiveAndDirectory<'a> {
impl Eth2NetArchiveAndDirectory<'_> {
/// The directory that should be used to store files downloaded for this net.
pub fn dir(&self) -> PathBuf {
env::var("CARGO_MANIFEST_DIR")
Expand Down
4 changes: 2 additions & 2 deletions common/logging/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'a> AlignedRecordDecorator<'a> {
}
}

impl<'a> Write for AlignedRecordDecorator<'a> {
impl Write for AlignedRecordDecorator<'_> {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
if buf.iter().any(u8::is_ascii_control) {
let filtered = buf
Expand All @@ -124,7 +124,7 @@ impl<'a> Write for AlignedRecordDecorator<'a> {
}
}

impl<'a> slog_term::RecordDecorator for AlignedRecordDecorator<'a> {
impl slog_term::RecordDecorator for AlignedRecordDecorator<'_> {
fn reset(&mut self) -> Result<()> {
self.message_active = false;
self.message_count = 0;
Expand Down
2 changes: 1 addition & 1 deletion common/validator_dir/src/insecure_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use types::test_utils::generate_deterministic_keypair;
/// A very weak password with which to encrypt the keystores.
pub const INSECURE_PASSWORD: &[u8] = &[50; 51];

impl<'a> Builder<'a> {
impl Builder<'_> {
/// Generate the voting keystore using a deterministic, well-known, **unsafe** keypair.
///
/// **NEVER** use these keys in production!
Expand Down
2 changes: 1 addition & 1 deletion consensus/state_processing/src/block_replayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ where
}
}

impl<'a, E, Error> BlockReplayer<'a, E, Error, StateRootIterDefault<Error>>
impl<E, Error> BlockReplayer<'_, E, Error, StateRootIterDefault<Error>>
where
E: EthSpec,
Error: From<BlockReplayError>,
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/aggregate_and_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ impl<E: EthSpec> AggregateAndProof<E> {
}

impl<E: EthSpec> SignedRoot for AggregateAndProof<E> {}
impl<'a, E: EthSpec> SignedRoot for AggregateAndProofRef<'a, E> {}
impl<E: EthSpec> SignedRoot for AggregateAndProofRef<'_, E> {}
4 changes: 2 additions & 2 deletions consensus/types/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl<E: EthSpec> Attestation<E> {
}
}

impl<'a, E: EthSpec> AttestationRef<'a, E> {
impl<E: EthSpec> AttestationRef<'_, E> {
pub fn clone_as_attestation(self) -> Attestation<E> {
match self {
Self::Base(att) => Attestation::Base(att.clone()),
Expand Down Expand Up @@ -422,7 +422,7 @@ impl<E: EthSpec> SlotData for Attestation<E> {
}
}

impl<'a, E: EthSpec> SlotData for AttestationRef<'a, E> {
impl<E: EthSpec> SlotData for AttestationRef<'_, E> {
fn get_slot(&self) -> Slot {
self.data().slot
}
Expand Down
5 changes: 1 addition & 4 deletions consensus/types/src/beacon_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ pub struct BeaconBlock<E: EthSpec, Payload: AbstractExecPayload<E> = FullPayload
pub type BlindedBeaconBlock<E> = BeaconBlock<E, BlindedPayload<E>>;

impl<E: EthSpec, Payload: AbstractExecPayload<E>> SignedRoot for BeaconBlock<E, Payload> {}
impl<'a, E: EthSpec, Payload: AbstractExecPayload<E>> SignedRoot
for BeaconBlockRef<'a, E, Payload>
{
}
impl<E: EthSpec, Payload: AbstractExecPayload<E>> SignedRoot for BeaconBlockRef<'_, E, Payload> {}

/// Empty block trait for each block variant to implement.
pub trait EmptyBlock {
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/beacon_block_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl<'a, E: EthSpec, Payload: AbstractExecPayload<E>> BeaconBlockBodyRefMut<'a,
}
}

impl<'a, E: EthSpec, Payload: AbstractExecPayload<E>> BeaconBlockBodyRef<'a, E, Payload> {
impl<E: EthSpec, Payload: AbstractExecPayload<E>> BeaconBlockBodyRef<'_, E, Payload> {
/// Get the fork_name of this object
pub fn fork_name(self) -> ForkName {
match self {
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/beacon_committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct BeaconCommittee<'a> {
pub committee: &'a [usize],
}

impl<'a> BeaconCommittee<'a> {
impl BeaconCommittee<'_> {
pub fn into_owned(self) -> OwnedBeaconCommittee {
OwnedBeaconCommittee {
slot: self.slot,
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/beacon_state/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'a, E: EthSpec> BlockRootsIter<'a, E> {
}
}

impl<'a, E: EthSpec> Iterator for BlockRootsIter<'a, E> {
impl<E: EthSpec> Iterator for BlockRootsIter<'_, E> {
type Item = Result<(Slot, Hash256), Error>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/execution_payload_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl<E: EthSpec> TryFrom<ExecutionPayloadHeader<E>> for ExecutionPayloadHeaderDe
}
}

impl<'a, E: EthSpec> ExecutionPayloadHeaderRefMut<'a, E> {
impl<E: EthSpec> ExecutionPayloadHeaderRefMut<'_, E> {
/// Mutate through
pub fn replace(self, header: ExecutionPayloadHeader<E>) -> Result<(), BeaconStateError> {
match self {
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/indexed_attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<E: EthSpec> IndexedAttestation<E> {
}
}

impl<'a, E: EthSpec> IndexedAttestationRef<'a, E> {
impl<E: EthSpec> IndexedAttestationRef<'_, E> {
pub fn is_double_vote(&self, other: Self) -> bool {
self.data().target.epoch == other.data().target.epoch && self.data() != other.data()
}
Expand Down
Loading

0 comments on commit fa6c4c0

Please sign in to comment.