From be91ab29eeabe1b6d4fdc64653b954f260e76f1b Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 26 May 2022 06:56:32 +1000 Subject: [PATCH] fix(clippy): resolve various clippy warnings (#4473) * clippy: unused import on non-linux platforms * Fix some instances of clippy::derive_partial_eq_without_eq * Move a deref to fix clippy::significant_drop_in_scrutinee Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- zebra-chain/src/block/error.rs | 2 +- zebra-chain/src/orchard/commitment.rs | 10 +++------- zebra-chain/src/orchard/keys.rs | 8 +++----- zebra-chain/src/orchard/tree.rs | 4 ++-- zebra-chain/src/sapling/commitment.rs | 10 +++------- zebra-chain/src/sapling/tree.rs | 4 ++-- zebra-chain/src/sprout/commitment.rs | 8 ++------ zebra-chain/src/sprout/tree.rs | 4 ++-- zebra-network/src/peer/handshake.rs | 2 +- zebrad/tests/acceptance.rs | 4 +++- 10 files changed, 22 insertions(+), 34 deletions(-) diff --git a/zebra-chain/src/block/error.rs b/zebra-chain/src/block/error.rs index 882f38a6..ced7d491 100644 --- a/zebra-chain/src/block/error.rs +++ b/zebra-chain/src/block/error.rs @@ -3,7 +3,7 @@ use thiserror::Error; #[allow(dead_code, missing_docs)] -#[derive(Error, Debug, PartialEq)] +#[derive(Error, Debug, PartialEq, Eq)] pub enum BlockError { #[error("transaction has wrong consensus branch id for block network upgrade")] WrongTransactionConsensusBranchId, diff --git a/zebra-chain/src/orchard/commitment.rs b/zebra-chain/src/orchard/commitment.rs index f8c956a7..e4de9366 100644 --- a/zebra-chain/src/orchard/commitment.rs +++ b/zebra-chain/src/orchard/commitment.rs @@ -38,7 +38,7 @@ where } /// The randomness used in the Simsemilla hash for note commitment. -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct CommitmentRandomness(pallas::Scalar); impl From for CommitmentRandomness { @@ -54,7 +54,7 @@ impl From for CommitmentRandomness { } /// Note commitments for the output notes. -#[derive(Clone, Copy, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Copy, Deserialize, PartialEq, Eq, Serialize)] pub struct NoteCommitment(#[serde(with = "serde_helpers::Affine")] pub pallas::Affine); impl fmt::Debug for NoteCommitment { @@ -76,8 +76,6 @@ impl fmt::Debug for NoteCommitment { } } -impl Eq for NoteCommitment {} - impl From for NoteCommitment { fn from(projective_point: pallas::Point) -> Self { Self(pallas::Affine::from(projective_point)) @@ -159,7 +157,7 @@ impl NoteCommitment { /// Action descriptions. /// /// https://zips.z.cash/protocol/nu5.pdf#concretehomomorphiccommit -#[derive(Clone, Copy, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Copy, Deserialize, PartialEq, Eq, Serialize)] pub struct ValueCommitment(#[serde(with = "serde_helpers::Affine")] pub pallas::Affine); impl<'a> std::ops::Add<&'a ValueCommitment> for ValueCommitment { @@ -209,8 +207,6 @@ impl From for ValueCommitment { } } -impl Eq for ValueCommitment {} - /// LEBS2OSP256(repr_P(cv)) /// /// https://zips.z.cash/protocol/nu5.pdf#pallasandvesta diff --git a/zebra-chain/src/orchard/keys.rs b/zebra-chain/src/orchard/keys.rs index 920f0658..8124983f 100644 --- a/zebra-chain/src/orchard/keys.rs +++ b/zebra-chain/src/orchard/keys.rs @@ -1,7 +1,7 @@ //! Orchard key types. //! //! -#![allow(clippy::unit_arg)] + #![allow(dead_code)] #[cfg(test)] @@ -983,7 +983,7 @@ impl PartialEq<[u8; 32]> for TransmissionKey { /// /// // TODO: derive `OutgoingCipherKey`: https://github.com/ZcashFoundation/zebra/issues/2041 -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq, Eq)] pub struct OutgoingCipherKey([u8; 32]); impl fmt::Debug for OutgoingCipherKey { @@ -1040,7 +1040,7 @@ impl PartialEq<[u8; 32]> for EphemeralPrivateKey { /// /// /// -#[derive(Copy, Clone, Deserialize, PartialEq, Serialize)] +#[derive(Copy, Clone, Deserialize, PartialEq, Eq, Serialize)] pub struct EphemeralPublicKey(#[serde(with = "serde_helpers::Affine")] pub(crate) pallas::Affine); impl fmt::Debug for EphemeralPublicKey { @@ -1062,8 +1062,6 @@ impl fmt::Debug for EphemeralPublicKey { } } -impl Eq for EphemeralPublicKey {} - impl From for [u8; 32] { fn from(epk: EphemeralPublicKey) -> [u8; 32] { epk.0.to_bytes() diff --git a/zebra-chain/src/orchard/tree.rs b/zebra-chain/src/orchard/tree.rs index f80ec822..b7432084 100644 --- a/zebra-chain/src/orchard/tree.rs +++ b/zebra-chain/src/orchard/tree.rs @@ -334,9 +334,9 @@ impl NoteCommitmentTree { .cached_root .write() .expect("a thread that previously held exclusive lock access panicked"); - match write_root.deref() { + match *write_root { // Another thread got write access first, return cached root. - Some(root) => *root, + Some(root) => root, None => { // Compute root and cache it. let root = Root(self.inner.root().0); diff --git a/zebra-chain/src/sapling/commitment.rs b/zebra-chain/src/sapling/commitment.rs index af13fa15..4668c2e4 100644 --- a/zebra-chain/src/sapling/commitment.rs +++ b/zebra-chain/src/sapling/commitment.rs @@ -44,11 +44,11 @@ where } /// The randomness used in the Pedersen Hash for note commitment. -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct CommitmentRandomness(jubjub::Fr); /// Note commitments for the output notes. -#[derive(Clone, Copy, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Copy, Deserialize, PartialEq, Eq, Serialize)] pub struct NoteCommitment(#[serde(with = "serde_helpers::AffinePoint")] pub jubjub::AffinePoint); impl fmt::Debug for NoteCommitment { @@ -60,8 +60,6 @@ impl fmt::Debug for NoteCommitment { } } -impl Eq for NoteCommitment {} - impl From for NoteCommitment { fn from(extended_point: jubjub::ExtendedPoint) -> Self { Self(jubjub::AffinePoint::from(extended_point)) @@ -157,7 +155,7 @@ impl NoteCommitment { /// [`NotSmallOrderValueCommitment`]. /// /// https://zips.z.cash/protocol/protocol.pdf#concretehomomorphiccommit -#[derive(Clone, Copy, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Copy, Deserialize, PartialEq, Eq, Serialize)] pub struct ValueCommitment(#[serde(with = "serde_helpers::AffinePoint")] jubjub::AffinePoint); impl<'a> std::ops::Add<&'a ValueCommitment> for ValueCommitment { @@ -199,8 +197,6 @@ impl From for ValueCommitment { } } -impl Eq for ValueCommitment {} - /// LEBS2OSP256(repr_J(cv)) /// /// https://zips.z.cash/protocol/protocol.pdf#spendencoding diff --git a/zebra-chain/src/sapling/tree.rs b/zebra-chain/src/sapling/tree.rs index 03461509..8d50332c 100644 --- a/zebra-chain/src/sapling/tree.rs +++ b/zebra-chain/src/sapling/tree.rs @@ -340,9 +340,9 @@ impl NoteCommitmentTree { .cached_root .write() .expect("a thread that previously held exclusive lock access panicked"); - match write_root.deref() { + match *write_root { // Another thread got write access first, return cached root. - Some(root) => *root, + Some(root) => root, None => { // Compute root and cache it. let root = Root::try_from(self.inner.root().0).unwrap(); diff --git a/zebra-chain/src/sprout/commitment.rs b/zebra-chain/src/sprout/commitment.rs index ae128a99..fa61ed4f 100644 --- a/zebra-chain/src/sprout/commitment.rs +++ b/zebra-chain/src/sprout/commitment.rs @@ -1,13 +1,11 @@ //! Sprout commitment types. -#![allow(clippy::unit_arg)] - use sha2::{Digest, Sha256}; use super::note::Note; /// The randomness used in the Pedersen Hash for note commitment. -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[cfg_attr( any(test, feature = "proptest-impl"), derive(proptest_derive::Arbitrary) @@ -21,15 +19,13 @@ impl AsRef<[u8]> for CommitmentRandomness { } /// Note commitments for the output notes. -#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize)] #[cfg_attr( any(test, feature = "proptest-impl"), derive(proptest_derive::Arbitrary) )] pub struct NoteCommitment(pub(crate) [u8; 32]); -impl Eq for NoteCommitment {} - impl From<[u8; 32]> for NoteCommitment { fn from(bytes: [u8; 32]) -> Self { Self(bytes) diff --git a/zebra-chain/src/sprout/tree.rs b/zebra-chain/src/sprout/tree.rs index 617456cc..1c009041 100644 --- a/zebra-chain/src/sprout/tree.rs +++ b/zebra-chain/src/sprout/tree.rs @@ -273,9 +273,9 @@ impl NoteCommitmentTree { .cached_root .write() .expect("a thread that previously held exclusive lock access panicked"); - match write_root.deref() { + match *write_root { // Another thread got write access first, return cached root. - Some(root) => *root, + Some(root) => root, None => { // Compute root and cache it. let root = Root(self.inner.root().0); diff --git a/zebra-network/src/peer/handshake.rs b/zebra-network/src/peer/handshake.rs index cc784a46..079af217 100644 --- a/zebra-network/src/peer/handshake.rs +++ b/zebra-network/src/peer/handshake.rs @@ -102,7 +102,7 @@ where /// /// Typically, we can rely on outbound addresses, but inbound addresses don't /// give us enough information to reconnect to that peer. -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq, Eq)] pub enum ConnectedAddr { /// The address we used to make a direct outbound connection. /// diff --git a/zebrad/tests/acceptance.rs b/zebrad/tests/acceptance.rs index cfb0ee6f..fed20366 100644 --- a/zebrad/tests/acceptance.rs +++ b/zebrad/tests/acceptance.rs @@ -24,7 +24,7 @@ use std::{collections::HashSet, convert::TryInto, env, path::PathBuf}; use color_eyre::{ - eyre::{eyre, Result, WrapErr}, + eyre::{Result, WrapErr}, Help, }; @@ -1439,6 +1439,8 @@ where // See #1781. #[cfg(target_os = "linux")] if node2.is_running() { + use color_eyre::eyre::eyre; + return node2 .kill_on_error::<(), _>(Err(eyre!( "conflicted node2 was still running, but the test expected a panic"