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

View File

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

View File

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

View File

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

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

View File

@ -56,8 +56,8 @@ 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",
@ -65,9 +65,9 @@ impl From<&Network> for &'static str {
}
}
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()
}
}

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.
///
/// # Inputs
@ -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,

View File

@ -1,3 +1,5 @@
//! Sprout funds transfers using [`JoinSplit`]s.
use std::io;
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> {
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(())
}
}

View File

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

View File

@ -1,4 +1,4 @@
use std::convert::{TryFrom, TryInto};
//! Fixed test vectors for transactions.
use chrono::{DateTime, NaiveDateTime, Utc};
use color_eyre::eyre::Result;
@ -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
@ -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",
@ -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");

View File

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

View File

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