add use_self clippy lint (#8325)

This commit is contained in:
Thomas Coratger
2024-05-29 15:14:14 +02:00
committed by GitHub
parent 0cb5358fef
commit 19c529e8df
200 changed files with 1817 additions and 1954 deletions

View File

@ -33,7 +33,7 @@ impl MiningMode {
/// Creates a new instant mining mode that listens for new transactions and tries to build
/// non-empty blocks as soon as transactions arrive.
pub fn instant(max_transactions: usize, listener: Receiver<TxHash>) -> Self {
MiningMode::Auto(ReadyTransactionMiner {
Self::Auto(ReadyTransactionMiner {
max_transactions,
has_pending_txs: None,
rx: ReceiverStream::new(listener).fuse(),
@ -42,7 +42,7 @@ impl MiningMode {
/// Creates a new interval miner that builds a block ever `duration`.
pub fn interval(duration: Duration) -> Self {
MiningMode::FixedBlockTime(FixedBlockTimeMiner::new(duration))
Self::FixedBlockTime(FixedBlockTimeMiner::new(duration))
}
/// polls the Pool and returns those transactions that should be put in a block, if any.
@ -55,9 +55,9 @@ impl MiningMode {
Pool: TransactionPool,
{
match self {
MiningMode::None => Poll::Pending,
MiningMode::Auto(miner) => miner.poll(pool, cx),
MiningMode::FixedBlockTime(miner) => miner.poll(pool, cx),
Self::None => Poll::Pending,
Self::Auto(miner) => miner.poll(pool, cx),
Self::FixedBlockTime(miner) => miner.poll(pool, cx),
}
}
}
@ -65,9 +65,9 @@ impl MiningMode {
impl fmt::Display for MiningMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let kind = match self {
MiningMode::None => "None",
MiningMode::Auto(_) => "Auto",
MiningMode::FixedBlockTime(_) => "FixedBlockTime",
Self::None => "None",
Self::Auto(_) => "Auto",
Self::FixedBlockTime(_) => "FixedBlockTime",
};
write!(f, "{kind}")
}

View File

@ -107,15 +107,15 @@ pub enum ForkchoiceStatus {
impl ForkchoiceStatus {
pub(crate) fn is_valid(&self) -> bool {
matches!(self, ForkchoiceStatus::Valid)
matches!(self, Self::Valid)
}
pub(crate) fn is_invalid(&self) -> bool {
matches!(self, ForkchoiceStatus::Invalid)
matches!(self, Self::Invalid)
}
pub(crate) fn is_syncing(&self) -> bool {
matches!(self, ForkchoiceStatus::Syncing)
matches!(self, Self::Syncing)
}
/// Converts the general purpose [PayloadStatusEnum] into a [ForkchoiceStatus].
@ -123,17 +123,17 @@ impl ForkchoiceStatus {
match status {
PayloadStatusEnum::Valid | PayloadStatusEnum::Accepted => {
// `Accepted` is only returned on `newPayload`. It would be a valid state here.
ForkchoiceStatus::Valid
Self::Valid
}
PayloadStatusEnum::Invalid { .. } => ForkchoiceStatus::Invalid,
PayloadStatusEnum::Syncing => ForkchoiceStatus::Syncing,
PayloadStatusEnum::Invalid { .. } => Self::Invalid,
PayloadStatusEnum::Syncing => Self::Syncing,
}
}
}
impl From<PayloadStatusEnum> for ForkchoiceStatus {
fn from(status: PayloadStatusEnum) -> Self {
ForkchoiceStatus::from_payload_status(&status)
Self::from_payload_status(&status)
}
}
@ -149,11 +149,11 @@ impl ForkchoiceStateHash {
/// Tries to find a matching hash in the given [ForkchoiceState].
pub(crate) fn find(state: &ForkchoiceState, hash: B256) -> Option<Self> {
if state.head_block_hash == hash {
Some(ForkchoiceStateHash::Head(hash))
Some(Self::Head(hash))
} else if state.safe_block_hash == hash {
Some(ForkchoiceStateHash::Safe(hash))
Some(Self::Safe(hash))
} else if state.finalized_block_hash == hash {
Some(ForkchoiceStateHash::Finalized(hash))
Some(Self::Finalized(hash))
} else {
None
}
@ -161,16 +161,14 @@ impl ForkchoiceStateHash {
/// Returns true if this is the head hash of the [ForkchoiceState]
pub(crate) fn is_head(&self) -> bool {
matches!(self, ForkchoiceStateHash::Head(_))
matches!(self, Self::Head(_))
}
}
impl AsRef<B256> for ForkchoiceStateHash {
fn as_ref(&self) -> &B256 {
match self {
ForkchoiceStateHash::Head(h) |
ForkchoiceStateHash::Safe(h) |
ForkchoiceStateHash::Finalized(h) => h,
Self::Head(h) | Self::Safe(h) | Self::Finalized(h) => h,
}
}
}

View File

@ -167,7 +167,7 @@ impl From<PrunerError> for EngineHookError {
fn from(err: PrunerError) -> Self {
match err {
PrunerError::PruneSegment(_) | PrunerError::InconsistentData(_) => {
EngineHookError::Internal(Box::new(err))
Self::Internal(Box::new(err))
}
PrunerError::Database(err) => RethError::Database(err).into(),
PrunerError::Provider(err) => RethError::Provider(err).into(),

View File

@ -419,7 +419,7 @@ enum PipelineState<DB: Database> {
impl<DB: Database> PipelineState<DB> {
/// Returns `true` if the state matches idle.
fn is_idle(&self) -> bool {
matches!(self, PipelineState::Idle(_))
matches!(self, Self::Idle(_))
}
}

View File

@ -328,7 +328,7 @@ pub enum ConsensusError {
impl ConsensusError {
/// Returns `true` if the error is a state root error.
pub fn is_state_root_error(&self) -> bool {
matches!(self, ConsensusError::BodyStateRootDiff(_))
matches!(self, Self::BodyStateRootDiff(_))
}
}