From 0fa362fa99fcbe91c1f05e45cff590ba801c19a6 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Wed, 29 Jan 2025 11:46:54 -0700 Subject: [PATCH] Fix clippy beta lints. --- components/zcash_protocol/src/consensus.rs | 2 +- pczt/src/roles/creator/mod.rs | 2 +- pczt/src/roles/redactor/mod.rs | 2 +- pczt/src/roles/redactor/orchard.rs | 4 ++-- pczt/src/roles/redactor/sapling.rs | 6 +++--- pczt/src/roles/redactor/transparent.rs | 6 +++--- pczt/src/roles/updater/mod.rs | 2 +- zcash_client_backend/src/data_api/testing.rs | 2 +- .../src/data_api/wallet/input_selection.rs | 2 +- zcash_client_backend/src/fees/common.rs | 4 ++-- zcash_client_backend/src/scan.rs | 2 +- zcash_client_sqlite/src/lib.rs | 5 ++--- zcash_client_sqlite/src/wallet/db.rs | 1 + zcash_history/src/tree.rs | 2 +- zcash_primitives/src/transaction/builder.rs | 6 +++--- zcash_primitives/src/transaction/fees/zip317.rs | 2 +- zcash_primitives/src/transaction/sighash.rs | 2 +- zcash_proofs/src/circuit/sprout/mod.rs | 2 +- zcash_transparent/src/address.rs | 2 +- zcash_transparent/src/builder.rs | 7 +++---- zcash_transparent/src/pczt/updater.rs | 6 +++--- 21 files changed, 34 insertions(+), 35 deletions(-) diff --git a/components/zcash_protocol/src/consensus.rs b/components/zcash_protocol/src/consensus.rs index 2dc74d6a11..b32be4ddb0 100644 --- a/components/zcash_protocol/src/consensus.rs +++ b/components/zcash_protocol/src/consensus.rs @@ -331,7 +331,7 @@ pub trait Parameters: Clone { /// Determines whether the specified network upgrade is active as of the /// provided block height on the network to which this Parameters value applies. fn is_nu_active(&self, nu: NetworkUpgrade, height: BlockHeight) -> bool { - self.activation_height(nu).map_or(false, |h| h <= height) + self.activation_height(nu).is_some_and(|h| h <= height) } } diff --git a/pczt/src/roles/creator/mod.rs b/pczt/src/roles/creator/mod.rs index dd6b8dd386..8b310e571b 100644 --- a/pczt/src/roles/creator/mod.rs +++ b/pczt/src/roles/creator/mod.rs @@ -120,7 +120,7 @@ impl Creator { // Spends and outputs not modifiable. let mut tx_modifiable = 0b0000_0000; // Check if any input is using `SIGHASH_SINGLE` (with or without `ANYONECANPAY`). - if parts.transparent.as_ref().map_or(false, |bundle| { + if parts.transparent.as_ref().is_some_and(|bundle| { bundle.inputs().iter().any(|input| { (input.sighash_type().encode() & !SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE }) diff --git a/pczt/src/roles/redactor/mod.rs b/pczt/src/roles/redactor/mod.rs index c0080f1fbd..7dad3a8262 100644 --- a/pczt/src/roles/redactor/mod.rs +++ b/pczt/src/roles/redactor/mod.rs @@ -32,7 +32,7 @@ impl Redactor { /// An Redactor for the global transaction details. pub struct GlobalRedactor<'a>(&'a mut Global); -impl<'a> GlobalRedactor<'a> { +impl GlobalRedactor<'_> { /// Redacts the proprietary value at the given key. pub fn redact_proprietary(&mut self, key: &str) { self.0.proprietary.remove(key); diff --git a/pczt/src/roles/redactor/orchard.rs b/pczt/src/roles/redactor/orchard.rs index 5cbff1cb15..d094a810d7 100644 --- a/pczt/src/roles/redactor/orchard.rs +++ b/pczt/src/roles/redactor/orchard.rs @@ -14,7 +14,7 @@ impl super::Redactor { /// A Redactor for the Orchard bundle. pub struct OrchardRedactor<'a>(&'a mut Bundle); -impl<'a> OrchardRedactor<'a> { +impl OrchardRedactor<'_> { /// Redacts all actions in the same way. pub fn redact_actions(&mut self, f: F) where @@ -54,7 +54,7 @@ enum Actions<'a> { One(&'a mut Action), } -impl<'a> ActionRedactor<'a> { +impl ActionRedactor<'_> { fn redact(&mut self, f: F) where F: Fn(&mut Action), diff --git a/pczt/src/roles/redactor/sapling.rs b/pczt/src/roles/redactor/sapling.rs index 4499dd465e..67035db51b 100644 --- a/pczt/src/roles/redactor/sapling.rs +++ b/pczt/src/roles/redactor/sapling.rs @@ -14,7 +14,7 @@ impl super::Redactor { /// A Redactor for the Sapling bundle. pub struct SaplingRedactor<'a>(&'a mut Bundle); -impl<'a> SaplingRedactor<'a> { +impl SaplingRedactor<'_> { /// Redacts all spends in the same way. pub fn redact_spends(&mut self, f: F) where @@ -69,7 +69,7 @@ enum Spends<'a> { One(&'a mut Spend), } -impl<'a> SpendRedactor<'a> { +impl SpendRedactor<'_> { fn redact(&mut self, f: F) where F: Fn(&mut Spend), @@ -194,7 +194,7 @@ enum Outputs<'a> { One(&'a mut Output), } -impl<'a> OutputRedactor<'a> { +impl OutputRedactor<'_> { fn redact(&mut self, f: F) where F: Fn(&mut Output), diff --git a/pczt/src/roles/redactor/transparent.rs b/pczt/src/roles/redactor/transparent.rs index f920b4b48a..8eac4c184e 100644 --- a/pczt/src/roles/redactor/transparent.rs +++ b/pczt/src/roles/redactor/transparent.rs @@ -14,7 +14,7 @@ impl super::Redactor { /// A Redactor for the transparent bundle. pub struct TransparentRedactor<'a>(&'a mut Bundle); -impl<'a> TransparentRedactor<'a> { +impl TransparentRedactor<'_> { /// Redacts all inputs in the same way. pub fn redact_inputs(&mut self, f: F) where @@ -64,7 +64,7 @@ enum Inputs<'a> { One(&'a mut Input), } -impl<'a> InputRedactor<'a> { +impl InputRedactor<'_> { fn redact(&mut self, f: F) where F: Fn(&mut Input), @@ -202,7 +202,7 @@ enum Outputs<'a> { One(&'a mut Output), } -impl<'a> OutputRedactor<'a> { +impl OutputRedactor<'_> { fn redact(&mut self, f: F) where F: Fn(&mut Output), diff --git a/pczt/src/roles/updater/mod.rs b/pczt/src/roles/updater/mod.rs index 1012f835e4..0f688a1c9a 100644 --- a/pczt/src/roles/updater/mod.rs +++ b/pczt/src/roles/updater/mod.rs @@ -61,7 +61,7 @@ impl Updater { /// An updater for a transparent PCZT output. pub struct GlobalUpdater<'a>(&'a mut Global); -impl<'a> GlobalUpdater<'a> { +impl GlobalUpdater<'_> { /// Stores the given proprietary value at the given key. pub fn set_proprietary(&mut self, key: String, value: Vec) { self.0.proprietary.insert(key, value); diff --git a/zcash_client_backend/src/data_api/testing.rs b/zcash_client_backend/src/data_api/testing.rs index 21d9a25090..96d469d259 100644 --- a/zcash_client_backend/src/data_api/testing.rs +++ b/zcash_client_backend/src/data_api/testing.rs @@ -1745,7 +1745,7 @@ pub trait TestFvk: Clone { ) -> Self::Nullifier; } -impl<'a, A: TestFvk> TestFvk for &'a A { +impl TestFvk for &A { type Nullifier = A::Nullifier; fn sapling_ovk(&self) -> Option<::sapling::keys::OutgoingViewingKey> { diff --git a/zcash_client_backend/src/data_api/wallet/input_selection.rs b/zcash_client_backend/src/data_api/wallet/input_selection.rs index 0e5debcde0..15b604effb 100644 --- a/zcash_client_backend/src/data_api/wallet/input_selection.rs +++ b/zcash_client_backend/src/data_api/wallet/input_selection.rs @@ -438,7 +438,7 @@ impl InputSelector for GreedyInputSelector { .expect("cannot fail because memo is None"), ); total_ephemeral = (total_ephemeral + payment.amount()) - .ok_or_else(|| GreedyInputSelectorError::Balance(BalanceError::Overflow))?; + .ok_or(GreedyInputSelectorError::Balance(BalanceError::Overflow))?; } #[cfg(not(feature = "transparent-inputs"))] Address::Tex(_) => { diff --git a/zcash_client_backend/src/fees/common.rs b/zcash_client_backend/src/fees/common.rs index 99a585e65a..132622f059 100644 --- a/zcash_client_backend/src/fees/common.rs +++ b/zcash_client_backend/src/fees/common.rs @@ -641,8 +641,8 @@ pub(crate) fn check_for_uneconomic_inputs( } let (t_inputs_len, t_outputs_len) = ( - transparent_inputs.len() + usize::from(ephemeral_balance.map_or(false, |b| b.is_input())), - transparent_outputs.len() + usize::from(ephemeral_balance.map_or(false, |b| b.is_output())), + transparent_inputs.len() + usize::from(ephemeral_balance.is_some_and(|b| b.is_input())), + transparent_outputs.len() + usize::from(ephemeral_balance.is_some_and(|b| b.is_output())), ); let (s_inputs_len, s_outputs_len) = (sapling.inputs().len(), sapling.outputs().len()); #[cfg(feature = "orchard")] diff --git a/zcash_client_backend/src/scan.rs b/zcash_client_backend/src/scan.rs index b59d5803fb..bb7b85406b 100644 --- a/zcash_client_backend/src/scan.rs +++ b/zcash_client_backend/src/scan.rs @@ -145,7 +145,7 @@ impl DynamicUsage for BatchReceiver { // linked list. `crossbeam_channel` allocates memory for the linked list in blocks // of 31 items. const ITEMS_PER_BLOCK: usize = 31; - let num_blocks = (num_items + ITEMS_PER_BLOCK - 1) / ITEMS_PER_BLOCK; + let num_blocks = num_items.div_ceil(ITEMS_PER_BLOCK); // The structure of a block is: // - A pointer to the next block. diff --git a/zcash_client_sqlite/src/lib.rs b/zcash_client_sqlite/src/lib.rs index 3ca1a07c71..cf6615d691 100644 --- a/zcash_client_sqlite/src/lib.rs +++ b/zcash_client_sqlite/src/lib.rs @@ -618,7 +618,7 @@ impl, P: consensus::Parameters> WalletRead for W } fn get_account_birthday(&self, account: Self::AccountId) -> Result { - wallet::account_birthday(self.conn.borrow(), account).map_err(SqliteClientError::from) + wallet::account_birthday(self.conn.borrow(), account) } fn get_wallet_birthday(&self) -> Result, Self::Error> { @@ -665,7 +665,6 @@ impl, P: consensus::Parameters> WalletRead for W fn suggest_scan_ranges(&self) -> Result, Self::Error> { wallet::scanning::suggest_scan_ranges(self.conn.borrow(), ScanPriority::Historic) - .map_err(SqliteClientError::from) } fn get_target_and_anchor_heights( @@ -1780,7 +1779,7 @@ impl, P: consensus::Parameters> WalletCommitm } } -impl<'conn, P: consensus::Parameters> WalletCommitmentTrees for WalletDb, P> { +impl WalletCommitmentTrees for WalletDb, P> { type Error = commitment_tree::Error; type SaplingShardStore<'a> = SqliteShardStore<&'a rusqlite::Transaction<'a>, sapling::Node, SAPLING_SHARD_HEIGHT>; diff --git a/zcash_client_sqlite/src/wallet/db.rs b/zcash_client_sqlite/src/wallet/db.rs index 9c84351c3e..24dea283e0 100644 --- a/zcash_client_sqlite/src/wallet/db.rs +++ b/zcash_client_sqlite/src/wallet/db.rs @@ -81,6 +81,7 @@ pub(super) const INDEX_HD_ACCOUNT: &str = /// sequential transparent addresses. /// - Transparent change addresses. /// - ZIP 320 ephemeral addresses. +/// /// This column exists because the diversifier index is stored as a byte array, meaning that we /// cannot use SQL integer operations on it for gap limit calculations, and thus need it as an /// integer as well. diff --git a/zcash_history/src/tree.rs b/zcash_history/src/tree.rs index 3a16ea005a..e5a207ec58 100644 --- a/zcash_history/src/tree.rs +++ b/zcash_history/src/tree.rs @@ -291,7 +291,7 @@ pub struct IndexedNode<'a, V: Version> { link: EntryLink, } -impl<'a, V: Version> IndexedNode<'a, V> { +impl IndexedNode<'_, V> { fn left(&self) -> Result { self.node.left().map_err(|e| e.augment(self.link)) } diff --git a/zcash_primitives/src/transaction/builder.rs b/zcash_primitives/src/transaction/builder.rs index 21a08bd55f..a7cd1a1c37 100644 --- a/zcash_primitives/src/transaction/builder.rs +++ b/zcash_primitives/src/transaction/builder.rs @@ -315,7 +315,7 @@ pub struct Builder<'a, P, U: sapling::builder::ProverProgress> { _progress_notifier: U, } -impl<'a, P, U: sapling::builder::ProverProgress> Builder<'a, P, U> { +impl Builder<'_, P, U> { /// Returns the network parameters that the builder has been configured for. pub fn params(&self) -> &P { &self.params @@ -424,7 +424,7 @@ impl<'a, P: consensus::Parameters> Builder<'a, P, ()> { } } -impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder<'a, P, U> { +impl Builder<'_, P, U> { /// Adds an Orchard note to be spent in this bundle. /// /// Returns an error if the given Merkle path does not have the required anchor for @@ -1011,7 +1011,7 @@ mod testing { use super::{BuildResult, Builder, Error}; use crate::transaction::fees::zip317; - impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder<'a, P, U> { + impl Builder<'_, P, U> { /// Build the transaction using mocked randomness and proving capabilities. /// DO NOT USE EXCEPT FOR UNIT TESTING. pub fn mock_build( diff --git a/zcash_primitives/src/transaction/fees/zip317.rs b/zcash_primitives/src/transaction/fees/zip317.rs index 41199bff92..52ba98bfe9 100644 --- a/zcash_primitives/src/transaction/fees/zip317.rs +++ b/zcash_primitives/src/transaction/fees/zip317.rs @@ -182,7 +182,7 @@ impl super::FeeRule for FeeRule { let t_out_total_size = transparent_output_sizes.into_iter().sum(); - let ceildiv = |num: usize, den: usize| (num + den - 1) / den; + let ceildiv = |num: usize, den: usize| num.div_ceil(den); let logical_actions = max( ceildiv(t_in_total_size, self.p2pkh_standard_input_size), diff --git a/zcash_primitives/src/transaction/sighash.rs b/zcash_primitives/src/transaction/sighash.rs index 90b7641666..3e0117f3d7 100644 --- a/zcash_primitives/src/transaction/sighash.rs +++ b/zcash_primitives/src/transaction/sighash.rs @@ -34,7 +34,7 @@ pub enum SignableInput<'a> { }, } -impl<'a> SignableInput<'a> { +impl SignableInput<'_> { pub fn hash_type(&self) -> u8 { match self { SignableInput::Shielded => ::transparent::sighash::SIGHASH_ALL, diff --git a/zcash_proofs/src/circuit/sprout/mod.rs b/zcash_proofs/src/circuit/sprout/mod.rs index ff1bd83fda..676b70c752 100644 --- a/zcash_proofs/src/circuit/sprout/mod.rs +++ b/zcash_proofs/src/circuit/sprout/mod.rs @@ -294,7 +294,7 @@ where let mut tmp = vec![]; for b in value .iter() - .flat_map(|&m| (0..8).rev().map(move |i| m >> i & 1 == 1)) + .flat_map(|&m| (0..8).rev().map(move |i| (m >> i) & 1 == 1)) .skip(skip_bits) { tmp.push(Some(b)); diff --git a/zcash_transparent/src/address.rs b/zcash_transparent/src/address.rs index 464652d047..4a9d8515d6 100644 --- a/zcash_transparent/src/address.rs +++ b/zcash_transparent/src/address.rs @@ -275,7 +275,7 @@ pub struct Script(pub Vec); impl fmt::Debug for Script { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { struct ScriptPrinter<'s>(&'s [u8]); - impl<'s> fmt::Debug for ScriptPrinter<'s> { + impl fmt::Debug for ScriptPrinter<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut l = f.debug_list(); let mut unknown: Option = None; diff --git a/zcash_transparent/src/builder.rs b/zcash_transparent/src/builder.rs index 792a20d983..00bd5a06f0 100644 --- a/zcash_transparent/src/builder.rs +++ b/zcash_transparent/src/builder.rs @@ -303,15 +303,14 @@ impl TransparentAuthorizingContext for Unauthorized { #[cfg(feature = "transparent-inputs")] impl TransparentAuthorizingContext for Unauthorized { fn input_amounts(&self) -> Vec { - return self.inputs.iter().map(|txin| txin.coin.value).collect(); + self.inputs.iter().map(|txin| txin.coin.value).collect() } fn input_scriptpubkeys(&self) -> Vec