fix(clippy): resolve or disable new nightly clippy lints (#4739)

* Fix new dead_code lints in generated pin-project code

* Fix and ignore new needless_borrow lints
This commit is contained in:
teor 2022-07-05 11:04:47 +10:00 committed by GitHub
parent 766dd9357b
commit 42ef8846b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 82 additions and 44 deletions

34
Cargo.lock generated
View File

@ -231,7 +231,7 @@ dependencies = [
"futures-core", "futures-core",
"futures-task", "futures-task",
"futures-util", "futures-util",
"pin-project 1.0.10", "pin-project 1.0.11",
"rustc_version", "rustc_version",
"tokio", "tokio",
] ]
@ -3310,11 +3310,11 @@ dependencies = [
[[package]] [[package]]
name = "pin-project" name = "pin-project"
version = "1.0.10" version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e" checksum = "78203e83c48cffbe01e4a2d35d566ca4de445d79a85372fc64e378bfc812a260"
dependencies = [ dependencies = [
"pin-project-internal 1.0.10", "pin-project-internal 1.0.11",
] ]
[[package]] [[package]]
@ -3330,9 +3330,9 @@ dependencies = [
[[package]] [[package]]
name = "pin-project-internal" name = "pin-project-internal"
version = "1.0.10" version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb" checksum = "710faf75e1b33345361201d36d04e98ac1ed8909151a017ed384700836104c74"
dependencies = [ dependencies = [
"proc-macro2 1.0.36", "proc-macro2 1.0.36",
"quote 1.0.15", "quote 1.0.15",
@ -3429,7 +3429,7 @@ dependencies = [
"atomic", "atomic",
"crossbeam-queue", "crossbeam-queue",
"futures", "futures",
"pin-project 1.0.10", "pin-project 1.0.11",
"static_assertions", "static_assertions",
"thiserror", "thiserror",
] ]
@ -5003,7 +5003,7 @@ dependencies = [
"hyper", "hyper",
"hyper-timeout", "hyper-timeout",
"percent-encoding", "percent-encoding",
"pin-project 1.0.10", "pin-project 1.0.11",
"prost", "prost",
"prost-derive", "prost-derive",
"tokio", "tokio",
@ -5116,7 +5116,7 @@ dependencies = [
"futures", "futures",
"humantime-serde", "humantime-serde",
"itertools", "itertools",
"pin-project 1.0.10", "pin-project 1.0.11",
"rand 0.8.5", "rand 0.8.5",
"retry-error", "retry-error",
"serde", "serde",
@ -5230,7 +5230,7 @@ dependencies = [
"futures", "futures",
"humantime-serde", "humantime-serde",
"itertools", "itertools",
"pin-project 1.0.10", "pin-project 1.0.11",
"rand 0.8.5", "rand 0.8.5",
"retain_mut", "retain_mut",
"serde", "serde",
@ -5400,7 +5400,7 @@ dependencies = [
"async_executors", "async_executors",
"futures", "futures",
"native-tls", "native-tls",
"pin-project 1.0.10", "pin-project 1.0.11",
"tokio", "tokio",
"tokio-native-tls", "tokio-native-tls",
"tokio-util 0.6.9", "tokio-util 0.6.9",
@ -5426,7 +5426,7 @@ dependencies = [
"futures-util", "futures-util",
"hdrhistogram", "hdrhistogram",
"indexmap", "indexmap",
"pin-project 1.0.10", "pin-project 1.0.11",
"pin-project-lite", "pin-project-lite",
"rand 0.8.5", "rand 0.8.5",
"slab", "slab",
@ -5445,7 +5445,7 @@ dependencies = [
"ed25519-zebra", "ed25519-zebra",
"futures", "futures",
"futures-core", "futures-core",
"pin-project 1.0.10", "pin-project 1.0.11",
"rand 0.8.5", "rand 0.8.5",
"tokio", "tokio",
"tokio-test", "tokio-test",
@ -5507,7 +5507,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4546773ffeab9e4ea02b8872faa49bb616a80a7da66afc2f32688943f97efa7" checksum = "a4546773ffeab9e4ea02b8872faa49bb616a80a7da66afc2f32688943f97efa7"
dependencies = [ dependencies = [
"futures-util", "futures-util",
"pin-project 1.0.10", "pin-project 1.0.11",
"tokio", "tokio",
"tokio-test", "tokio-test",
"tower-layer", "tower-layer",
@ -5575,7 +5575,7 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2"
dependencies = [ dependencies = [
"pin-project 1.0.10", "pin-project 1.0.11",
"tracing", "tracing",
] ]
@ -6400,7 +6400,7 @@ dependencies = [
"lazy_static", "lazy_static",
"metrics", "metrics",
"ordered-map", "ordered-map",
"pin-project 1.0.10", "pin-project 1.0.11",
"proptest", "proptest",
"proptest-derive", "proptest-derive",
"rand 0.8.5", "rand 0.8.5",
@ -6569,7 +6569,7 @@ dependencies = [
"metrics-exporter-prometheus", "metrics-exporter-prometheus",
"num-integer", "num-integer",
"once_cell", "once_cell",
"pin-project 1.0.10", "pin-project 1.0.11",
"proptest", "proptest",
"proptest-derive", "proptest-derive",
"prost", "prost",

View File

@ -1,5 +1,8 @@
//! Future types for the `Fallback` middleware. //! 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::{ use std::{
fmt::Debug, fmt::Debug,
future::Future, future::Future,

View File

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

View File

@ -1,5 +1,21 @@
//! Blocks and block-related structures (heights, headers, etc.) //! 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 commitment;
mod error; mod error;
mod hash; mod hash;
@ -14,8 +30,6 @@ pub mod arbitrary;
#[cfg(any(test, feature = "bench", feature = "proptest-impl"))] #[cfg(any(test, feature = "bench", feature = "proptest-impl"))]
pub mod tests; pub mod tests;
use std::{collections::HashMap, fmt, ops::Neg};
pub use commitment::{ pub use commitment::{
ChainHistoryBlockTxAuthCommitmentHash, ChainHistoryMmrRootHash, Commitment, CommitmentError, ChainHistoryBlockTxAuthCommitmentHash, ChainHistoryMmrRootHash, Commitment, CommitmentError,
}; };
@ -27,20 +41,6 @@ pub use serialize::{SerializedBlock, MAX_BLOCK_BYTES};
#[cfg(any(test, feature = "proptest-impl"))] #[cfg(any(test, feature = "proptest-impl"))]
pub use arbitrary::LedgerState; 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. /// A Zcash block, containing a header and a list of transactions.
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Serialize))] #[cfg_attr(any(test, feature = "proptest-impl"), derive(Serialize))]
@ -219,7 +219,7 @@ impl Block {
impl<'a> From<&'a Block> for Hash { impl<'a> From<&'a Block> for Hash {
fn from(block: &'a Block) -> Hash { fn from(block: &'a Block) -> Hash {
(&block.header).into() block.header.into()
} }
} }

View File

@ -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 { impl ZcashSerialize for Hash {
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> { fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
writer.write_all(&self.0)?; writer.write_all(&self.0)?;

View File

@ -56,8 +56,8 @@ pub enum Network {
Testnet, Testnet,
} }
impl From<&Network> for &'static str { impl From<Network> for &'static str {
fn from(network: &Network) -> &'static str { fn from(network: Network) -> &'static str {
match network { match network {
Network::Mainnet => "Mainnet", Network::Mainnet => "Mainnet",
Network::Testnet => "Testnet", Network::Testnet => "Testnet",
@ -65,9 +65,9 @@ impl From<&Network> for &'static str {
} }
} }
impl From<Network> for &'static str { impl From<&Network> for &'static str {
fn from(network: Network) -> &'static str { fn from(network: &Network) -> &'static str {
(&network).into() (*network).into()
} }
} }

View File

@ -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. /// Compute a signature hash using librustzcash.
/// ///
/// # Inputs /// # Inputs
@ -223,7 +232,7 @@ pub(crate) fn sighash(
let signable_input = match input_index { let signable_input = match input_index {
Some(input_index) => { Some(input_index) => {
let output = all_previous_outputs[input_index].clone(); let output = all_previous_outputs[input_index].clone();
script = (&output.lock_script).into(); script = output.lock_script.into();
zp_tx::sighash::SignableInput::Transparent { zp_tx::sighash::SignableInput::Transparent {
hash_type: hash_type.bits() as _, hash_type: hash_type.bits() as _,
index: input_index, index: input_index,

View File

@ -1,3 +1,5 @@
//! Sprout funds transfers using [`JoinSplit`]s.
use std::io; use std::io;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -82,18 +84,25 @@ impl<P: ZkSnarkProof> ZcashSerialize for JoinSplit<P> {
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> { fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
self.vpub_old.zcash_serialize(&mut writer)?; self.vpub_old.zcash_serialize(&mut writer)?;
self.vpub_new.zcash_serialize(&mut writer)?; self.vpub_new.zcash_serialize(&mut writer)?;
writer.write_32_bytes(&self.anchor.into())?; writer.write_32_bytes(&self.anchor.into())?;
writer.write_32_bytes(&self.nullifiers[0].into())?; writer.write_32_bytes(&self.nullifiers[0].into())?;
writer.write_32_bytes(&self.nullifiers[1].into())?; writer.write_32_bytes(&self.nullifiers[1].into())?;
writer.write_32_bytes(&self.commitments[0].into())?; writer.write_32_bytes(&self.commitments[0].into())?;
writer.write_32_bytes(&self.commitments[1].into())?; writer.write_32_bytes(&self.commitments[1].into())?;
writer.write_all(&self.ephemeral_key.as_bytes()[..])?; 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())?; writer.write_32_bytes(&(&self.random_seed).into())?;
self.vmacs[0].zcash_serialize(&mut writer)?; self.vmacs[0].zcash_serialize(&mut writer)?;
self.vmacs[1].zcash_serialize(&mut writer)?; self.vmacs[1].zcash_serialize(&mut writer)?;
self.zkproof.zcash_serialize(&mut writer)?; self.zkproof.zcash_serialize(&mut writer)?;
self.enc_ciphertexts[0].zcash_serialize(&mut writer)?; self.enc_ciphertexts[0].zcash_serialize(&mut writer)?;
self.enc_ciphertexts[1].zcash_serialize(&mut writer)?; self.enc_ciphertexts[1].zcash_serialize(&mut writer)?;
Ok(()) Ok(())
} }
} }

View File

@ -959,7 +959,7 @@ pub fn fake_v5_transactions_for_network<'b>(
.transactions .transactions
.into_iter() .into_iter()
.map(move |transaction| { .map(move |transaction| {
transaction_to_fake_v5(&*transaction, network, block::Height(*height)) transaction_to_fake_v5(&transaction, network, block::Height(*height))
}) })
.map(Transaction::from) .map(Transaction::from)
}) })

View File

@ -1,4 +1,4 @@
use std::convert::{TryFrom, TryInto}; //! Fixed test vectors for transactions.
use chrono::{DateTime, NaiveDateTime, Utc}; use chrono::{DateTime, NaiveDateTime, Utc};
use color_eyre::eyre::Result; use color_eyre::eyre::Result;
@ -275,7 +275,7 @@ fn deserialize_large_transaction() {
fn empty_v5_round_trip() { fn empty_v5_round_trip() {
zebra_test::init(); 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 data = tx.zcash_serialize_to_vec().expect("tx should serialize");
let tx2: &Transaction = &data let tx2: &Transaction = &data
@ -327,7 +327,7 @@ fn empty_v4_round_trip() {
fn empty_v5_librustzcash_round_trip() { fn empty_v5_librustzcash_round_trip() {
zebra_test::init(); 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( let _alt_tx: zcash_primitives::transaction::Transaction = tx.try_into().expect(
"librustzcash deserialization might work for empty zebra serialized transactions. \ "librustzcash deserialization might work for empty zebra serialized transactions. \
Hint: if empty transactions fail, but other transactions work, delete this test", Hint: if empty transactions fail, but other transactions work, delete this test",
@ -572,6 +572,8 @@ fn zip244_round_trip() -> Result<()> {
let reencoded = transaction.zcash_serialize_to_vec()?; let reencoded = transaction.zcash_serialize_to_vec()?;
assert_eq!(test.tx, reencoded); 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) let _alt_tx: zcash_primitives::transaction::Transaction = (&transaction)
.try_into() .try_into()
.expect("librustzcash deserialization must work for zebra serialized transactions"); .expect("librustzcash deserialization must work for zebra serialized transactions");

View File

@ -221,6 +221,8 @@ impl From<Transaction> for UnminedTx {
"unexpected serialization failure: all structurally valid transactions have a size", "unexpected serialization failure: all structurally valid transactions have a size",
); );
// The borrow is actually needed to avoid taking ownership
#[allow(clippy::needless_borrow)]
Self { Self {
id: (&transaction).into(), id: (&transaction).into(),
size, size,

View File

@ -251,6 +251,9 @@ impl Description for (&JoinSplit<Groth16Proof>, &ed25519::VerificationKeyBytes)
/// This is not yet officially documented; see the reference implementation: /// 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://github.com/zcash/librustzcash/blob/0ec7f97c976d55e1a194a37b27f247e8887fca1d/zcash_proofs/src/sprout.rs#L152-L166>
/// <https://zips.z.cash/protocol/protocol.pdf#joinsplitdesc> /// <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> { fn primary_inputs(&self) -> Vec<jubjub::Fq> {
let (joinsplit, joinsplit_pub_key) = self; let (joinsplit, joinsplit_pub_key) = self;