From 256b1c00088b360bef2096fdf94394fc1892ca3f Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 18 Jan 2023 10:27:42 +1000 Subject: [PATCH] fix(clippy): Fix new lints in nightly clippy (#5959) * Derive default using #[default] * Implement PartialEq manually to satisfy clippy * Allow a manual derive in test-only code * Fix some missing docs warnings in the Docker build --- zebra-chain/src/orchard/tree.rs | 11 ++++++++--- zebra-chain/src/parameters/network.rs | 14 ++++++-------- zebra-network/src/meta_addr.rs | 3 ++- zebra-test/tests/command.rs | 2 ++ zebra-test/tests/transcript.rs | 6 ++++-- zebra-utils/src/bin/zebra-checkpoints/main.rs | 1 + zebrad/build.rs | 1 + zebrad/src/bin/zebrad/main.rs | 2 +- zebrad/src/components/mempool.rs | 14 +++++++------- 9 files changed, 32 insertions(+), 22 deletions(-) diff --git a/zebra-chain/src/orchard/tree.rs b/zebra-chain/src/orchard/tree.rs index e0beb71c..978ba5b6 100644 --- a/zebra-chain/src/orchard/tree.rs +++ b/zebra-chain/src/orchard/tree.rs @@ -10,8 +10,6 @@ //! //! A root of a note commitment tree is associated with each treestate. -#![allow(clippy::derive_hash_xor_eq)] - use std::{ fmt, hash::{Hash, Hasher}, @@ -99,7 +97,7 @@ lazy_static! { /// The root hash in LEBS2OSP256(rt) encoding of the Orchard note commitment /// tree corresponding to the final Orchard treestate of this block. A root of a /// note commitment tree is associated with each treestate. -#[derive(Clone, Copy, Default, Eq, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Copy, Default, Eq, Serialize, Deserialize)] pub struct Root(#[serde(with = "serde_helpers::Base")] pub(crate) pallas::Base); impl fmt::Debug for Root { @@ -128,6 +126,13 @@ impl Hash for Root { } } +impl PartialEq for Root { + fn eq(&self, other: &Self) -> bool { + // TODO: should we compare canonical forms here using `.to_repr()`? + self.0 == other.0 + } +} + impl TryFrom<[u8; 32]> for Root { type Error = SerializationError; diff --git a/zebra-chain/src/parameters/network.rs b/zebra-chain/src/parameters/network.rs index aa2178b0..d23abe94 100644 --- a/zebra-chain/src/parameters/network.rs +++ b/zebra-chain/src/parameters/network.rs @@ -1,4 +1,6 @@ -use std::{convert::From, fmt, str::FromStr}; +//! Consensus parameters for each Zcash network. + +use std::{fmt, str::FromStr}; use thiserror::Error; @@ -47,11 +49,13 @@ mod tests; const ZIP_212_GRACE_PERIOD_DURATION: i32 = 32_256; /// An enum describing the possible network choices. -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash, Serialize, Deserialize)] #[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))] pub enum Network { /// The production mainnet. + #[default] Mainnet, + /// The testnet. Testnet, } @@ -114,12 +118,6 @@ impl Network { } } -impl Default for Network { - fn default() -> Self { - Network::Mainnet - } -} - impl FromStr for Network { type Err = InvalidNetworkError; diff --git a/zebra-network/src/meta_addr.rs b/zebra-network/src/meta_addr.rs index 63e68bf0..6b0b1f46 100644 --- a/zebra-network/src/meta_addr.rs +++ b/zebra-network/src/meta_addr.rs @@ -2,12 +2,12 @@ use std::{ cmp::{Ord, Ordering}, - convert::TryInto, net::SocketAddr, time::Instant, }; use chrono::Utc; + use zebra_chain::{parameters::Network, serialization::DateTime32}; use crate::{ @@ -80,6 +80,7 @@ impl PeerAddrState { // non-test code should explicitly specify the peer address state #[cfg(test)] +#[allow(clippy::derivable_impls)] impl Default for PeerAddrState { fn default() -> Self { NeverAttemptedGossiped diff --git a/zebra-test/tests/command.rs b/zebra-test/tests/command.rs index 402ddf3b..21c93626 100644 --- a/zebra-test/tests/command.rs +++ b/zebra-test/tests/command.rs @@ -1,3 +1,5 @@ +//! Tests for the [`zebra_test::command`] module. + use std::{process::Command, time::Duration}; use color_eyre::eyre::{eyre, Result}; diff --git a/zebra-test/tests/transcript.rs b/zebra-test/tests/transcript.rs index a24d4af1..e51b53ac 100644 --- a/zebra-test/tests/transcript.rs +++ b/zebra-test/tests/transcript.rs @@ -1,6 +1,8 @@ +//! Tests for the [`zebra_test::transcript`] module. + use tower::{Service, ServiceExt}; -use zebra_test::transcript::ExpectedTranscriptError; -use zebra_test::transcript::Transcript; + +use zebra_test::transcript::{ExpectedTranscriptError, Transcript}; const TRANSCRIPT_DATA: [(&str, Result<&str, ExpectedTranscriptError>); 4] = [ ("req1", Ok("rsp1")), diff --git a/zebra-utils/src/bin/zebra-checkpoints/main.rs b/zebra-utils/src/bin/zebra-checkpoints/main.rs index f15043e4..27923627 100644 --- a/zebra-utils/src/bin/zebra-checkpoints/main.rs +++ b/zebra-utils/src/bin/zebra-checkpoints/main.rs @@ -60,6 +60,7 @@ fn cmd_output(cmd: &mut std::process::Command) -> Result { Ok(s) } +/// Process entry point for `zebra-checkpoints` #[allow(clippy::print_stdout)] fn main() -> Result<()> { // initialise diff --git a/zebrad/build.rs b/zebrad/build.rs index e90c46eb..eb8f5880 100644 --- a/zebrad/build.rs +++ b/zebrad/build.rs @@ -28,6 +28,7 @@ fn disable_non_reproducible(_config: &mut Config) { */ } +/// Process entry point for `zebrad`'s build script #[allow(clippy::print_stderr)] fn main() { let mut config = Config::default(); diff --git a/zebrad/src/bin/zebrad/main.rs b/zebrad/src/bin/zebrad/main.rs index 9856713a..962be240 100644 --- a/zebrad/src/bin/zebrad/main.rs +++ b/zebrad/src/bin/zebrad/main.rs @@ -2,7 +2,7 @@ use zebrad::application::APPLICATION; -/// Boot Zebrad +/// Process entry point for `zebrad` fn main() { abscissa_core::boot(&APPLICATION); } diff --git a/zebrad/src/components/mempool.rs b/zebrad/src/components/mempool.rs index de42ccc2..3d3ea826 100644 --- a/zebrad/src/components/mempool.rs +++ b/zebrad/src/components/mempool.rs @@ -86,27 +86,27 @@ type InboundTxDownloads = TxDownloads, Timeout, St // // Zebra only has one mempool, so the enum variant size difference doesn't matter. #[allow(clippy::large_enum_variant)] +#[derive(Default)] enum ActiveState { /// The Mempool is disabled. + #[default] Disabled, + /// The Mempool is enabled. Enabled { /// The Mempool storage itself. /// - /// ##: Correctness: only components internal to the [`Mempool`] struct are allowed to + /// # Correctness + /// + /// Only components internal to the [`Mempool`] struct are allowed to /// inject transactions into `storage`, as transactions must be verified beforehand. storage: storage::Storage, + /// The transaction download and verify stream. tx_downloads: Pin>, }, } -impl Default for ActiveState { - fn default() -> Self { - ActiveState::Disabled - } -} - impl ActiveState { /// Returns the current state, leaving [`Self::Disabled`] in its place. fn take(&mut self) -> Self {