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>
This commit is contained in:
teor 2022-05-26 06:56:32 +10:00 committed by GitHub
parent 2ee52f808c
commit be91ab29ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 22 additions and 34 deletions

View File

@ -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,

View File

@ -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<SeedRandomness> for CommitmentRandomness {
@ -54,7 +54,7 @@ impl From<SeedRandomness> 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<pallas::Point> 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<pallas::Point> for ValueCommitment {
}
}
impl Eq for ValueCommitment {}
/// LEBS2OSP256(repr_P(cv))
///
/// https://zips.z.cash/protocol/nu5.pdf#pallasandvesta

View File

@ -1,7 +1,7 @@
//! Orchard key types.
//!
//! <https://zips.z.cash/protocol/nu5.pdf#orchardkeycomponents>
#![allow(clippy::unit_arg)]
#![allow(dead_code)]
#[cfg(test)]
@ -983,7 +983,7 @@ impl PartialEq<[u8; 32]> for TransmissionKey {
///
/// <https://zips.z.cash/protocol/nu5.pdf#saplingandorchardencrypt>
// 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 {
///
/// <https://zips.z.cash/protocol/nu5.pdf#concreteorchardkeyagreement>
/// <https://zips.z.cash/protocol/nu5.pdf#saplingandorchardencrypt>
#[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<EphemeralPublicKey> for [u8; 32] {
fn from(epk: EphemeralPublicKey) -> [u8; 32] {
epk.0.to_bytes()

View File

@ -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);

View File

@ -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<jubjub::ExtendedPoint> 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<jubjub::ExtendedPoint> for ValueCommitment {
}
}
impl Eq for ValueCommitment {}
/// LEBS2OSP256(repr_J(cv))
///
/// https://zips.z.cash/protocol/protocol.pdf#spendencoding

View File

@ -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();

View File

@ -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)

View File

@ -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);

View File

@ -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.
///

View File

@ -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"