From 42ef8846b34887ecd3635202451d75819e2994db Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 5 Jul 2022 11:04:47 +1000 Subject: [PATCH] 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 --- Cargo.lock | 34 +++++++++---------- tower-fallback/src/future.rs | 3 ++ zebra-chain/src/amount/tests/vectors.rs | 2 ++ zebra-chain/src/block.rs | 34 +++++++++---------- zebra-chain/src/block/hash.rs | 8 +++++ zebra-chain/src/parameters/network.rs | 10 +++--- .../src/primitives/zcash_primitives.rs | 11 +++++- zebra-chain/src/sprout/joinsplit.rs | 9 +++++ zebra-chain/src/transaction/arbitrary.rs | 2 +- zebra-chain/src/transaction/tests/vectors.rs | 8 +++-- zebra-chain/src/transaction/unmined.rs | 2 ++ zebra-consensus/src/primitives/groth16.rs | 3 ++ 12 files changed, 82 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6bcd865cb5d..ffa4e4b99ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/tower-fallback/src/future.rs b/tower-fallback/src/future.rs index 92dd9ea9a9e..dbbea911ce9 100644 --- a/tower-fallback/src/future.rs +++ b/tower-fallback/src/future.rs @@ -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, diff --git a/zebra-chain/src/amount/tests/vectors.rs b/zebra-chain/src/amount/tests/vectors.rs index d1f764b4b94..b4fe100d5a7 100644 --- a/zebra-chain/src/amount/tests/vectors.rs +++ b/zebra-chain/src/amount/tests/vectors.rs @@ -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(); diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 078d80aaa51..d21406c3042 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -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() } } diff --git a/zebra-chain/src/block/hash.rs b/zebra-chain/src/block/hash.rs index ce679a8d8b1..f9ba8502c99 100644 --- a/zebra-chain/src/block/hash.rs +++ b/zebra-chain/src/block/hash.rs @@ -97,6 +97,14 @@ impl<'a> From<&'a Header> for Hash { } } +impl From
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(&self, mut writer: W) -> Result<(), io::Error> { writer.write_all(&self.0)?; diff --git a/zebra-chain/src/parameters/network.rs b/zebra-chain/src/parameters/network.rs index b6abd95e3dd..aa2178b0476 100644 --- a/zebra-chain/src/parameters/network.rs +++ b/zebra-chain/src/parameters/network.rs @@ -56,8 +56,8 @@ pub enum Network { Testnet, } -impl From<&Network> for &'static str { - fn from(network: &Network) -> &'static str { +impl From 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 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() } } diff --git a/zebra-chain/src/primitives/zcash_primitives.rs b/zebra-chain/src/primitives/zcash_primitives.rs index 8ddf35cbb66..517d66dda3c 100644 --- a/zebra-chain/src/primitives/zcash_primitives.rs +++ b/zebra-chain/src/primitives/zcash_primitives.rs @@ -198,6 +198,15 @@ impl From<&Script> for zcash_primitives::legacy::Script { } } +/// Convert a Zebra Script into a librustzcash one. +impl From