Skip to content

Commit b6909e1

Browse files
Merge #1421: fix: Cargo clippy lints
a5fb7fd fix: Cargo clippy lints after rust 1.78 (Daniela Brozzoni) Pull request description: <!-- You can erase any parts of this template not applicable to your Pull Request. --> ### Description Caught when trying to release (#1420), clippy failed randomly although it worked on master, this happened because rust 1.78 had just been release and we use clippy stable. IMHO we should pin the clippy version in CI and bump it manually at each new rust release. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: notmandatory: ACK a5fb7fd Tree-SHA512: c803366367576224f9e9690cdee2c0161fc083550355415f9174e93ada2f597440f54ac966bb3ebecdc916824d43de17ac72801e4ef0f75c8a1df640fe40df6d
2 parents 08fac47 + a5fb7fd commit b6909e1

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

crates/bdk/src/wallet/export.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
//! # Ok::<_, Box<dyn std::error::Error>>(())
5454
//! ```
5555
56-
use alloc::string::{String, ToString};
56+
use alloc::string::String;
57+
use core::fmt;
5758
use core::str::FromStr;
5859
use serde::{Deserialize, Serialize};
5960

@@ -79,9 +80,9 @@ pub struct FullyNodedExport {
7980
pub label: String,
8081
}
8182

82-
impl ToString for FullyNodedExport {
83-
fn to_string(&self) -> String {
84-
serde_json::to_string(self).unwrap()
83+
impl fmt::Display for FullyNodedExport {
84+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
85+
write!(f, "{}", serde_json::to_string(self).unwrap())
8586
}
8687
}
8788

@@ -213,6 +214,7 @@ impl FullyNodedExport {
213214
mod test {
214215
use core::str::FromStr;
215216

217+
use crate::std::string::ToString;
216218
use bdk_chain::{BlockId, ConfirmationTime};
217219
use bitcoin::hashes::Hash;
218220
use bitcoin::{transaction, BlockHash, Network, Transaction};

crates/chain/src/local_chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl Iterator for CheckPointIter {
265265

266266
fn next(&mut self) -> Option<Self::Item> {
267267
let current = self.current.clone()?;
268-
self.current = current.prev.clone();
268+
self.current.clone_from(&current.prev);
269269
Some(CheckPoint(current))
270270
}
271271
}
@@ -359,7 +359,7 @@ impl LocalChain {
359359
/// The [`BTreeMap`] enforces the height order. However, the caller must ensure the blocks are
360360
/// all of the same chain.
361361
pub fn from_blocks(blocks: BTreeMap<u32, BlockHash>) -> Result<Self, MissingGenesisError> {
362-
if blocks.get(&0).is_none() {
362+
if !blocks.contains_key(&0) {
363363
return Err(MissingGenesisError);
364364
}
365365

crates/chain/src/spk_client.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ impl<K: Ord + Clone> FullScanRequest<K> {
255255
spks: impl IntoIterator<IntoIter = impl Iterator<Item = (u32, ScriptBuf)> + Send + 'static>,
256256
) -> Self {
257257
match self.spks_by_keychain.remove(&keychain) {
258+
// clippy here suggests to remove `into_iter` from `spks.into_iter()`, but doing so
259+
// results in a compilation error
260+
#[allow(clippy::useless_conversion)]
258261
Some(keychain_spks) => self
259262
.spks_by_keychain
260263
.insert(keychain, Box::new(keychain_spks.chain(spks.into_iter()))),

crates/chain/src/spk_iter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ mod test {
260260
}
261261

262262
// The following dummy traits were created to test if SpkIterator is working properly.
263+
#[allow(unused)]
263264
trait TestSendStatic: Send + 'static {
264265
fn test(&self) -> u32 {
265266
20

crates/chain/src/spk_txout_index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<I: Clone + Ord> SpkTxOutIndex<I> {
229229
/// Here, "unused" means that after the script pubkey was stored in the index, the index has
230230
/// never scanned a transaction output with it.
231231
pub fn is_used(&self, index: &I) -> bool {
232-
self.unused.get(index).is_none()
232+
!self.unused.contains(index)
233233
}
234234

235235
/// Marks the script pubkey at `index` as used even though it hasn't seen an output spending to it.

0 commit comments

Comments
 (0)