From a5fb7fdf505a53b5865ed83d53745e7efa5e7818 Mon Sep 17 00:00:00 2001 From: Daniela Brozzoni Date: Thu, 2 May 2024 14:53:37 +0200 Subject: [PATCH] fix: Cargo clippy lints after rust 1.78 --- crates/bdk/src/wallet/export.rs | 10 ++++++---- crates/chain/src/local_chain.rs | 4 ++-- crates/chain/src/spk_client.rs | 3 +++ crates/chain/src/spk_iter.rs | 1 + crates/chain/src/spk_txout_index.rs | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/bdk/src/wallet/export.rs b/crates/bdk/src/wallet/export.rs index 95252a01..b6349309 100644 --- a/crates/bdk/src/wallet/export.rs +++ b/crates/bdk/src/wallet/export.rs @@ -53,7 +53,8 @@ //! # Ok::<_, Box>(()) //! ``` -use alloc::string::{String, ToString}; +use alloc::string::String; +use core::fmt; use core::str::FromStr; use serde::{Deserialize, Serialize}; @@ -79,9 +80,9 @@ pub struct FullyNodedExport { pub label: String, } -impl ToString for FullyNodedExport { - fn to_string(&self) -> String { - serde_json::to_string(self).unwrap() +impl fmt::Display for FullyNodedExport { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", serde_json::to_string(self).unwrap()) } } @@ -213,6 +214,7 @@ impl FullyNodedExport { mod test { use core::str::FromStr; + use crate::std::string::ToString; use bdk_chain::{BlockId, ConfirmationTime}; use bitcoin::hashes::Hash; use bitcoin::{transaction, BlockHash, Network, Transaction}; diff --git a/crates/chain/src/local_chain.rs b/crates/chain/src/local_chain.rs index 157b9db2..2c396cb3 100644 --- a/crates/chain/src/local_chain.rs +++ b/crates/chain/src/local_chain.rs @@ -265,7 +265,7 @@ impl Iterator for CheckPointIter { fn next(&mut self) -> Option { let current = self.current.clone()?; - self.current = current.prev.clone(); + self.current.clone_from(¤t.prev); Some(CheckPoint(current)) } } @@ -359,7 +359,7 @@ impl LocalChain { /// The [`BTreeMap`] enforces the height order. However, the caller must ensure the blocks are /// all of the same chain. pub fn from_blocks(blocks: BTreeMap) -> Result { - if blocks.get(&0).is_none() { + if !blocks.contains_key(&0) { return Err(MissingGenesisError); } diff --git a/crates/chain/src/spk_client.rs b/crates/chain/src/spk_client.rs index eefa211c..6eb32da7 100644 --- a/crates/chain/src/spk_client.rs +++ b/crates/chain/src/spk_client.rs @@ -255,6 +255,9 @@ impl FullScanRequest { spks: impl IntoIterator + Send + 'static>, ) -> Self { match self.spks_by_keychain.remove(&keychain) { + // clippy here suggests to remove `into_iter` from `spks.into_iter()`, but doing so + // results in a compilation error + #[allow(clippy::useless_conversion)] Some(keychain_spks) => self .spks_by_keychain .insert(keychain, Box::new(keychain_spks.chain(spks.into_iter()))), diff --git a/crates/chain/src/spk_iter.rs b/crates/chain/src/spk_iter.rs index 6846e66d..a3944c95 100644 --- a/crates/chain/src/spk_iter.rs +++ b/crates/chain/src/spk_iter.rs @@ -260,6 +260,7 @@ mod test { } // The following dummy traits were created to test if SpkIterator is working properly. + #[allow(unused)] trait TestSendStatic: Send + 'static { fn test(&self) -> u32 { 20 diff --git a/crates/chain/src/spk_txout_index.rs b/crates/chain/src/spk_txout_index.rs index a3ad48d0..3f3db2ae 100644 --- a/crates/chain/src/spk_txout_index.rs +++ b/crates/chain/src/spk_txout_index.rs @@ -229,7 +229,7 @@ impl SpkTxOutIndex { /// Here, "unused" means that after the script pubkey was stored in the index, the index has /// never scanned a transaction output with it. pub fn is_used(&self, index: &I) -> bool { - self.unused.get(index).is_none() + !self.unused.contains(index) } /// Marks the script pubkey at `index` as used even though it hasn't seen an output spending to it.