Skip to content

Commit

Permalink
fix(clippy): Fix new lints in nightly clippy (#5959)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
teor2345 authored Jan 18, 2023
1 parent 7e5253e commit 256b1c0
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 22 deletions.
11 changes: 8 additions & 3 deletions zebra-chain/src/orchard/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down
14 changes: 6 additions & 8 deletions zebra-chain/src/parameters/network.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -114,12 +118,6 @@ impl Network {
}
}

impl Default for Network {
fn default() -> Self {
Network::Mainnet
}
}

impl FromStr for Network {
type Err = InvalidNetworkError;

Expand Down
3 changes: 2 additions & 1 deletion zebra-network/src/meta_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions zebra-test/tests/command.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Tests for the [`zebra_test::command`] module.
use std::{process::Command, time::Duration};

use color_eyre::eyre::{eyre, Result};
Expand Down
6 changes: 4 additions & 2 deletions zebra-test/tests/transcript.rs
Original file line number Diff line number Diff line change
@@ -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")),
Expand Down
1 change: 1 addition & 0 deletions zebra-utils/src/bin/zebra-checkpoints/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fn cmd_output(cmd: &mut std::process::Command) -> Result<String> {
Ok(s)
}

/// Process entry point for `zebra-checkpoints`
#[allow(clippy::print_stdout)]
fn main() -> Result<()> {
// initialise
Expand Down
1 change: 1 addition & 0 deletions zebrad/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion zebrad/src/bin/zebrad/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use zebrad::application::APPLICATION;

/// Boot Zebrad
/// Process entry point for `zebrad`
fn main() {
abscissa_core::boot(&APPLICATION);
}
14 changes: 7 additions & 7 deletions zebrad/src/components/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,27 @@ type InboundTxDownloads = TxDownloads<Timeout<Outbound>, Timeout<TxVerifier>, 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<Box<InboundTxDownloads>>,
},
}

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 {
Expand Down

0 comments on commit 256b1c0

Please sign in to comment.