From 60e10ab6c2c2329c579667f86cf812e62bdc2fd9 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Fri, 10 Mar 2023 10:01:17 +0100 Subject: [PATCH] Fix new Clippy warnings introduced in Rust 1.68 (#1284) --- config/src/config.rs | 9 ++------- tendermint/src/abci/code.rs | 9 ++------- tendermint/src/abci/request/check_tx.rs | 8 ++------ tendermint/src/abci/response/process_proposal.rs | 9 ++------- tendermint/src/hash.rs | 9 ++------- tendermint/src/node/id.rs | 2 +- tendermint/src/node/info.rs | 9 ++------- 7 files changed, 13 insertions(+), 42 deletions(-) diff --git a/config/src/config.rs b/config/src/config.rs index e5c12532c..3ea21fe5e 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -611,7 +611,7 @@ pub struct TxIndexConfig { } /// What indexer to use for transactions -#[derive(Copy, Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] +#[derive(Copy, Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Default)] pub enum TxIndexer { /// "null" // TODO(tarcieri): use an `Option` type here? @@ -621,15 +621,10 @@ pub enum TxIndexer { /// "kv" (default) - the simplest possible indexer, backed by key-value storage (defaults to /// levelDB; see DBBackend). #[serde(rename = "kv")] + #[default] Kv, } -impl Default for TxIndexer { - fn default() -> TxIndexer { - TxIndexer::Kv - } -} - /// instrumentation configuration options #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub struct InstrumentationConfig { diff --git a/tendermint/src/abci/code.rs b/tendermint/src/abci/code.rs index 81c379570..dfd78325d 100644 --- a/tendermint/src/abci/code.rs +++ b/tendermint/src/abci/code.rs @@ -12,21 +12,16 @@ use serde::{ /// /// /// Note that in the future there may potentially be non-zero success codes. -#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Default)] pub enum Code { /// Success + #[default] Ok, /// Error codes Err(NonZeroU32), } -impl Default for Code { - fn default() -> Code { - Code::Ok - } -} - impl Code { /// Was the response OK? pub fn is_ok(self) -> bool { diff --git a/tendermint/src/abci/request/check_tx.rs b/tendermint/src/abci/request/check_tx.rs index 8afbc5af7..df33ab020 100644 --- a/tendermint/src/abci/request/check_tx.rs +++ b/tendermint/src/abci/request/check_tx.rs @@ -22,19 +22,15 @@ pub struct CheckTx { /// to avoid confusion with Rust types. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[repr(i32)] +#[derive(Default)] pub enum CheckTxKind { /// A full check is required (the default). + #[default] New = 0, /// Indicates that the mempool is initiating a recheck of the transaction. Recheck = 1, } -impl Default for CheckTxKind { - fn default() -> Self { - CheckTxKind::New - } -} - // ============================================================================= // Protobuf conversions // ============================================================================= diff --git a/tendermint/src/abci/response/process_proposal.rs b/tendermint/src/abci/response/process_proposal.rs index acaf45ef9..9e3d6d50c 100644 --- a/tendermint/src/abci/response/process_proposal.rs +++ b/tendermint/src/abci/response/process_proposal.rs @@ -3,19 +3,14 @@ use crate::prelude::*; #[doc = include_str!("../doc/response-processproposal.md")] #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(i32)] +#[derive(Default)] pub enum ProcessProposal { + #[default] Unknown = 0, Accept = 1, Reject = 2, } -impl Default for ProcessProposal { - #[inline] - fn default() -> Self { - ProcessProposal::Unknown - } -} - // ============================================================================= // Protobuf conversions // ============================================================================= diff --git a/tendermint/src/hash.rs b/tendermint/src/hash.rs index 799dfa579..93c313468 100644 --- a/tendermint/src/hash.rs +++ b/tendermint/src/hash.rs @@ -24,11 +24,12 @@ pub enum Algorithm { } /// Hash digests -#[derive(Copy, Clone, Hash, Eq, PartialEq, PartialOrd, Ord)] +#[derive(Copy, Clone, Hash, Eq, PartialEq, PartialOrd, Ord, Default)] pub enum Hash { /// SHA-256 hashes Sha256([u8; SHA256_HASH_SIZE]), /// Empty hash + #[default] None, } @@ -144,12 +145,6 @@ impl Debug for Hash { } } -impl Default for Hash { - fn default() -> Self { - Hash::None - } -} - impl Display for Hash { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let hex = match self { diff --git a/tendermint/src/node/id.rs b/tendermint/src/node/id.rs index bba7cdb2a..437190f29 100644 --- a/tendermint/src/node/id.rs +++ b/tendermint/src/node/id.rs @@ -15,7 +15,7 @@ use crate::{error::Error, prelude::*}; pub const LENGTH: usize = 20; /// Node IDs -#[allow(clippy::derive_hash_xor_eq)] +#[allow(clippy::derived_hash_with_manual_eq)] #[derive(Copy, Clone, Eq, Hash, PartialOrd, Ord)] pub struct Id([u8; LENGTH]); diff --git a/tendermint/src/node/info.rs b/tendermint/src/node/info.rs index 4d069bef4..7e29c9fbf 100644 --- a/tendermint/src/node/info.rs +++ b/tendermint/src/node/info.rs @@ -82,10 +82,11 @@ pub struct OtherInfo { } /// Transaction index status -#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Serialize, Default)] pub enum TxIndexStatus { /// Index is on #[serde(rename = "on")] + #[default] On, /// Index is off @@ -93,12 +94,6 @@ pub enum TxIndexStatus { Off, } -impl Default for TxIndexStatus { - fn default() -> TxIndexStatus { - TxIndexStatus::On - } -} - impl From for bool { fn from(status: TxIndexStatus) -> bool { match status {