Skip to content

Commit

Permalink
fix(clippy): resolve or disable new nightly clippy lints (#4739)
Browse files Browse the repository at this point in the history
* Fix new dead_code lints in generated pin-project code

* Fix and ignore new needless_borrow lints
  • Loading branch information
teor2345 authored Jul 5, 2022
1 parent 766dd93 commit 42ef884
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 44 deletions.
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tower-fallback/src/future.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Future types for the `Fallback` middleware.
// TODO: remove this lint exception after upgrading to pin-project 1.0.11 or later (#2355)
#![allow(dead_code)]

use std::{
fmt::Debug,
future::Future,
Expand Down
2 changes: 2 additions & 0 deletions zebra-chain/src/amount/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ fn add_with_diff_constraints() -> Result<()> {
}

#[test]
// The borrows are actually needed to call the correct trait impl
#[allow(clippy::needless_borrow)]
fn deserialize_checks_bounds() -> Result<()> {
zebra_test::init();

Expand Down
34 changes: 17 additions & 17 deletions zebra-chain/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
//! Blocks and block-related structures (heights, headers, etc.)
use std::{collections::HashMap, fmt, ops::Neg};

use crate::{
amount::NegativeAllowed,
block::merkle::AuthDataRoot,
fmt::DisplayToDebug,
orchard,
parameters::{Network, NetworkUpgrade},
sapling,
serialization::{TrustedPreallocate, MAX_PROTOCOL_MESSAGE_LEN},
sprout,
transaction::Transaction,
transparent,
value_balance::{ValueBalance, ValueBalanceError},
};

mod commitment;
mod error;
mod hash;
Expand All @@ -14,8 +30,6 @@ pub mod arbitrary;
#[cfg(any(test, feature = "bench", feature = "proptest-impl"))]
pub mod tests;

use std::{collections::HashMap, fmt, ops::Neg};

pub use commitment::{
ChainHistoryBlockTxAuthCommitmentHash, ChainHistoryMmrRootHash, Commitment, CommitmentError,
};
Expand All @@ -27,20 +41,6 @@ pub use serialize::{SerializedBlock, MAX_BLOCK_BYTES};
#[cfg(any(test, feature = "proptest-impl"))]
pub use arbitrary::LedgerState;

use crate::{
amount::NegativeAllowed,
block::merkle::AuthDataRoot,
fmt::DisplayToDebug,
orchard,
parameters::{Network, NetworkUpgrade},
sapling,
serialization::{TrustedPreallocate, MAX_PROTOCOL_MESSAGE_LEN},
sprout,
transaction::Transaction,
transparent,
value_balance::{ValueBalance, ValueBalanceError},
};

/// A Zcash block, containing a header and a list of transactions.
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Serialize))]
Expand Down Expand Up @@ -219,7 +219,7 @@ impl Block {

impl<'a> From<&'a Block> for Hash {
fn from(block: &'a Block) -> Hash {
(&block.header).into()
block.header.into()
}
}

Expand Down
8 changes: 8 additions & 0 deletions zebra-chain/src/block/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ impl<'a> From<&'a Header> for Hash {
}
}

impl From<Header> for Hash {
// The borrow is actually needed to use From<&Header>
#[allow(clippy::needless_borrow)]
fn from(block_header: Header) -> Self {
(&block_header).into()
}
}

impl ZcashSerialize for Hash {
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
writer.write_all(&self.0)?;
Expand Down
10 changes: 5 additions & 5 deletions zebra-chain/src/parameters/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ pub enum Network {
Testnet,
}

impl From<&Network> for &'static str {
fn from(network: &Network) -> &'static str {
impl From<Network> for &'static str {
fn from(network: Network) -> &'static str {
match network {
Network::Mainnet => "Mainnet",
Network::Testnet => "Testnet",
}
}
}

impl From<Network> for &'static str {
fn from(network: Network) -> &'static str {
(&network).into()
impl From<&Network> for &'static str {
fn from(network: &Network) -> &'static str {
(*network).into()
}
}

Expand Down
11 changes: 10 additions & 1 deletion zebra-chain/src/primitives/zcash_primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ impl From<&Script> for zcash_primitives::legacy::Script {
}
}

/// Convert a Zebra Script into a librustzcash one.
impl From<Script> for zcash_primitives::legacy::Script {
// The borrow is actually needed to use From<&Script>
#[allow(clippy::needless_borrow)]
fn from(script: Script) -> Self {
(&script).into()
}
}

/// Compute a signature hash using librustzcash.
///
/// # Inputs
Expand All @@ -223,7 +232,7 @@ pub(crate) fn sighash(
let signable_input = match input_index {
Some(input_index) => {
let output = all_previous_outputs[input_index].clone();
script = (&output.lock_script).into();
script = output.lock_script.into();
zp_tx::sighash::SignableInput::Transparent {
hash_type: hash_type.bits() as _,
index: input_index,
Expand Down
9 changes: 9 additions & 0 deletions zebra-chain/src/sprout/joinsplit.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Sprout funds transfers using [`JoinSplit`]s.
use std::io;

use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -82,18 +84,25 @@ impl<P: ZkSnarkProof> ZcashSerialize for JoinSplit<P> {
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
self.vpub_old.zcash_serialize(&mut writer)?;
self.vpub_new.zcash_serialize(&mut writer)?;

writer.write_32_bytes(&self.anchor.into())?;
writer.write_32_bytes(&self.nullifiers[0].into())?;
writer.write_32_bytes(&self.nullifiers[1].into())?;
writer.write_32_bytes(&self.commitments[0].into())?;
writer.write_32_bytes(&self.commitments[1].into())?;

writer.write_all(&self.ephemeral_key.as_bytes()[..])?;
// The borrow is actually needed to avoid taking ownership
#[allow(clippy::needless_borrow)]
writer.write_32_bytes(&(&self.random_seed).into())?;

self.vmacs[0].zcash_serialize(&mut writer)?;
self.vmacs[1].zcash_serialize(&mut writer)?;
self.zkproof.zcash_serialize(&mut writer)?;

self.enc_ciphertexts[0].zcash_serialize(&mut writer)?;
self.enc_ciphertexts[1].zcash_serialize(&mut writer)?;

Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/transaction/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ pub fn fake_v5_transactions_for_network<'b>(
.transactions
.into_iter()
.map(move |transaction| {
transaction_to_fake_v5(&*transaction, network, block::Height(*height))
transaction_to_fake_v5(&transaction, network, block::Height(*height))
})
.map(Transaction::from)
})
Expand Down
8 changes: 5 additions & 3 deletions zebra-chain/src/transaction/tests/vectors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::convert::{TryFrom, TryInto};
//! Fixed test vectors for transactions.
use chrono::{DateTime, NaiveDateTime, Utc};
use color_eyre::eyre::Result;
Expand Down Expand Up @@ -275,7 +275,7 @@ fn deserialize_large_transaction() {
fn empty_v5_round_trip() {
zebra_test::init();

let tx: &Transaction = &*EMPTY_V5_TX;
let tx: &Transaction = &EMPTY_V5_TX;

let data = tx.zcash_serialize_to_vec().expect("tx should serialize");
let tx2: &Transaction = &data
Expand Down Expand Up @@ -327,7 +327,7 @@ fn empty_v4_round_trip() {
fn empty_v5_librustzcash_round_trip() {
zebra_test::init();

let tx: &Transaction = &*EMPTY_V5_TX;
let tx: &Transaction = &EMPTY_V5_TX;
let _alt_tx: zcash_primitives::transaction::Transaction = tx.try_into().expect(
"librustzcash deserialization might work for empty zebra serialized transactions. \
Hint: if empty transactions fail, but other transactions work, delete this test",
Expand Down Expand Up @@ -572,6 +572,8 @@ fn zip244_round_trip() -> Result<()> {
let reencoded = transaction.zcash_serialize_to_vec()?;
assert_eq!(test.tx, reencoded);

// The borrow is actually needed to call the correct trait impl
#[allow(clippy::needless_borrow)]
let _alt_tx: zcash_primitives::transaction::Transaction = (&transaction)
.try_into()
.expect("librustzcash deserialization must work for zebra serialized transactions");
Expand Down
2 changes: 2 additions & 0 deletions zebra-chain/src/transaction/unmined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ impl From<Transaction> for UnminedTx {
"unexpected serialization failure: all structurally valid transactions have a size",
);

// The borrow is actually needed to avoid taking ownership
#[allow(clippy::needless_borrow)]
Self {
id: (&transaction).into(),
size,
Expand Down
3 changes: 3 additions & 0 deletions zebra-consensus/src/primitives/groth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ impl Description for (&JoinSplit<Groth16Proof>, &ed25519::VerificationKeyBytes)
/// This is not yet officially documented; see the reference implementation:
/// <https://github.com/zcash/librustzcash/blob/0ec7f97c976d55e1a194a37b27f247e8887fca1d/zcash_proofs/src/sprout.rs#L152-L166>
/// <https://zips.z.cash/protocol/protocol.pdf#joinsplitdesc>
//
// The borrows are actually needed to avoid taking ownership
#[allow(clippy::needless_borrow)]
fn primary_inputs(&self) -> Vec<jubjub::Fq> {
let (joinsplit, joinsplit_pub_key) = self;

Expand Down

0 comments on commit 42ef884

Please sign in to comment.