refactor: remove redundant clones in bitcoin crate
What changed, and why it matters
This commit is a minor code cleanup that removes unnecessary copy operations (clones) inside test code only. It does not change any production behavior and has no security relevance.
No action required. This is a non-security refactoring change in test code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit removes redundant .clone() calls in three test modules: blockdata/block.rs, merkle_tree/block.rs, and psbt/mod.rs. All changes are inside #[cfg(test)] mod tests blocks. The affected values are passed by reference or consumed, so the clones were unnecessary. There are no functional changes, no API changes, and no changes to non-test code.
Changed components
bitcoin/src/blockdata/block.rs (tests only)bitcoin/src/merkle_tree/block.rs (tests only)bitcoin/src/psbt/mod.rs (tests only)Inspect captured patch +5 / −5
diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs
index 9185064f..7cb8c62c 100644
--- a/bitcoin/src/blockdata/block.rs
+++ b/bitcoin/src/blockdata/block.rs
@@ -878,7 +878,7 @@ mod tests {
let header = *genesis.header();
let transactions = genesis.transactions().to_vec();
- let checked_block = Block::new_checked(header, transactions.clone());
+ let checked_block = Block::new_checked(header, transactions);
assert!(checked_block.is_ok(), "Genesis block should validate via new_checked");
// Test validation failure with empty transactions
diff --git a/bitcoin/src/merkle_tree/block.rs b/bitcoin/src/merkle_tree/block.rs
index 580923c3..e670cef1 100644
--- a/bitcoin/src/merkle_tree/block.rs
+++ b/bitcoin/src/merkle_tree/block.rs
@@ -701,7 +701,7 @@ mod tests {
let merkle_block = MerkleBlock::from_block_with_predicate(&block, |t| txids.contains(t));
- assert_eq!(merkle_block.header.block_hash(), block.clone().block_hash());
+ assert_eq!(merkle_block.header.block_hash(), block.block_hash());
let mut matches: Vec<Txid> = vec![];
let mut index: Vec<u32> = vec![];
@@ -731,7 +731,7 @@ mod tests {
let merkle_block = MerkleBlock::from_block_with_predicate(&block, |t| txids.contains(t));
- assert_eq!(merkle_block.header.block_hash(), block.clone().block_hash());
+ assert_eq!(merkle_block.header.block_hash(), block.block_hash());
let mut matches: Vec<Txid> = vec![];
let mut index: Vec<u32> = vec![];
diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs
index ed3cddec..6e5c87a3 100644
--- a/bitcoin/src/psbt/mod.rs
+++ b/bitcoin/src/psbt/mod.rs
@@ -1464,7 +1464,7 @@ mod tests {
Err(error_fee_rate)
);
assert_eq!(
- psbt.clone().extract_tx_fee_rate_limit().map_err(|e| match e {
+ psbt.extract_tx_fee_rate_limit().map_err(|e| match e {
ExtractTxError::AbsurdFeeRate { fee_rate, .. } => fee_rate,
other => panic!("expected AbsurdFeeRate error, got {other:?}"),
}),
@@ -2443,7 +2443,7 @@ mod tests {
let derived_xpriv = parent_xpriv.derive_xpriv(&secp, &path_prefix).unwrap();
let derived_key = derived_xpriv
- .get_key(&KeyRequest::Bip32((parent_xpriv.fingerprint(&secp), path.clone())), &secp)
+ .get_key(&KeyRequest::Bip32((parent_xpriv.fingerprint(&secp), path)), &secp)
.unwrap();
assert_eq!(derived_key, Some(expected_private_key));
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.