Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Apply Clippy lint redundant_clone #5713

Merged
merged 9 commits into from
Jan 23, 2025
4 changes: 1 addition & 3 deletions clarity/src/vm/docs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2734,9 +2734,7 @@ fn make_all_api_reference() -> ReferenceAPIs {
#[allow(clippy::expect_used)]
pub fn make_json_api_reference() -> String {
let api_out = make_all_api_reference();
serde_json::to_string(&api_out)
.expect("Failed to serialize documentation")
.to_string()
serde_json::to_string(&api_out).expect("Failed to serialize documentation")
}

#[cfg(test)]
Expand Down
1 change: 0 additions & 1 deletion pox-locking/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ fn create_event_info_data_code(
"#,
delegate_to = opt
.data
.clone()
.map(|boxed_value| *boxed_value)
.unwrap()
.expect_tuple()
Expand Down
2 changes: 1 addition & 1 deletion stacks-common/src/util/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ impl<T: Default + Clone> TestFlag<T> {
/// assert_eq!(test_flag.get(), 123);
/// ```
pub fn get(&self) -> T {
self.0.lock().unwrap().clone().unwrap_or_default().clone()
self.0.lock().unwrap().clone().unwrap_or_default()
}
}
9 changes: 4 additions & 5 deletions stacks-signer/src/signerdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ mod tests {
.unwrap()
.expect("Unable to get block from db");

assert_eq!(BlockInfo::from(block_proposal_1.clone()), block_info);
assert_eq!(BlockInfo::from(block_proposal_1), block_info);

// Test looking up a block with an unknown hash
let block_info = db
Expand All @@ -1250,7 +1250,7 @@ mod tests {
.unwrap()
.expect("Unable to get block from db");

assert_eq!(BlockInfo::from(block_proposal_2.clone()), block_info);
assert_eq!(BlockInfo::from(block_proposal_2), block_info);
}

#[test]
Expand Down Expand Up @@ -1677,12 +1677,11 @@ mod tests {
&StacksPrivateKey::new(),
)),
};
let tenure_change_tx_payload =
TransactionPayload::TenureChange(tenure_change_payload.clone());
let tenure_change_tx_payload = TransactionPayload::TenureChange(tenure_change_payload);
let tenure_change_tx = StacksTransaction::new(
TransactionVersion::Testnet,
TransactionAuth::from_p2pkh(&StacksPrivateKey::new()).unwrap(),
tenure_change_tx_payload.clone(),
tenure_change_tx_payload,
);

let consensus_hash_1 = ConsensusHash([0x01; 20]);
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/burnchains/affirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ pub fn update_pox_affirmation_maps<B: BurnchainHeaderReader>(
let (prepare_ops, pox_anchor_block_info_opt) =
find_pox_anchor_block(&tx, reward_cycle, indexer, burnchain)?;

if let Some((anchor_block, descendancy)) = pox_anchor_block_info_opt.clone() {
if let Some((anchor_block, descendancy)) = pox_anchor_block_info_opt {
debug!(
"PoX anchor block elected in reward cycle {} for reward cycle {} is {}",
reward_cycle,
Expand Down
20 changes: 7 additions & 13 deletions stackslib/src/burnchains/bitcoin/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,11 +1343,9 @@ mod test {
let mut spv_client_reorg =
SpvClient::new(path_2, 0, None, BitcoinNetworkType::Regtest, true, false).unwrap();

spv_client
.insert_block_headers_after(0, headers_1.clone())
.unwrap();
spv_client.insert_block_headers_after(0, headers_1).unwrap();
spv_client_reorg
.insert_block_headers_after(0, headers_2.clone())
.insert_block_headers_after(0, headers_2)
.unwrap();

spv_client.update_chain_work().unwrap();
Expand Down Expand Up @@ -1521,11 +1519,9 @@ mod test {
let mut spv_client_reorg =
SpvClient::new(path_2, 0, None, BitcoinNetworkType::Regtest, true, false).unwrap();

spv_client
.insert_block_headers_after(0, headers_1.clone())
.unwrap();
spv_client.insert_block_headers_after(0, headers_1).unwrap();
spv_client_reorg
.insert_block_headers_after(0, headers_2.clone())
.insert_block_headers_after(0, headers_2)
.unwrap();

assert_eq!(spv_client.read_block_headers(0, 10).unwrap().len(), 4);
Expand Down Expand Up @@ -3338,7 +3334,7 @@ mod test {

// put these bad headers into the "main" chain
spv_client
.insert_block_headers_after(40318, bad_headers.clone())
.insert_block_headers_after(40318, bad_headers)
.unwrap();

// *now* calculate main chain work
Expand Down Expand Up @@ -3485,9 +3481,7 @@ mod test {
)
.unwrap();

spv_client
.test_write_block_headers(0, headers.clone())
.unwrap();
spv_client.test_write_block_headers(0, headers).unwrap();
assert_eq!(spv_client.get_highest_header_height().unwrap(), 2);

let mut indexer = BitcoinIndexer::new(
Expand Down Expand Up @@ -3518,7 +3512,7 @@ mod test {

let should_keep_running = Arc::new(AtomicBool::new(true));
let mut indexer = BitcoinIndexer::new(
BitcoinIndexerConfig::test_default(db_path.to_string()),
BitcoinIndexerConfig::test_default(db_path),
BitcoinIndexerRuntime::new(BitcoinNetworkType::Mainnet),
Some(should_keep_running.clone()),
);
Expand Down
11 changes: 3 additions & 8 deletions stackslib/src/burnchains/bitcoin/spv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ mod test {
.unwrap();
assert_eq!(spv_client.read_block_headers(1, 10).unwrap(), headers);

let mut all_headers = vec![genesis_regtest_header.clone()];
let mut all_headers = vec![genesis_regtest_header];
all_headers.append(&mut headers.clone());

assert_eq!(spv_client.read_block_headers(0, 10).unwrap(), all_headers);
Expand All @@ -1650,9 +1650,7 @@ mod test {
}

// should succeed
spv_client
.insert_block_headers_before(9, headers.clone())
.unwrap();
spv_client.insert_block_headers_before(9, headers).unwrap();
}

#[test]
Expand Down Expand Up @@ -1771,10 +1769,7 @@ mod test {
];

// should fail
if let btc_error::InvalidPoW = spv_client
.handle_headers(40317, bad_headers.clone())
.unwrap_err()
{
if let btc_error::InvalidPoW = spv_client.handle_headers(40317, bad_headers).unwrap_err() {
} else {
panic!("Bad PoW headers accepted");
}
Expand Down
6 changes: 3 additions & 3 deletions stackslib/src/burnchains/tests/affirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ fn test_parent_block_commits() {
// orphan
assert_eq!(parent_commits.len(), all_ops_with_orphan.len() - 1);

let mut all_ops_with_same_parent = all_ops.clone();
let mut all_ops_with_same_parent = all_ops;
for ops in all_ops_with_same_parent.iter_mut() {
for opdata in ops.iter_mut() {
opdata.parent_block_ptr = 3;
Expand Down Expand Up @@ -948,7 +948,7 @@ fn test_find_heaviest_block_commit() {
// X------- 4,0
//
// X------------ 5,0
let mut all_ops_no_majority = filtered_ops.clone();
let mut all_ops_no_majority = filtered_ops;
all_ops_no_majority[0][0].parent_block_ptr = 2;
all_ops_no_majority[0][0].parent_vtxindex = 10;
all_ops_no_majority[0][0].burn_fee = 0;
Expand Down Expand Up @@ -1153,7 +1153,7 @@ fn test_find_heaviest_parent_commit_many_commits() {
// 1,0 <-- 2,0 <--- 3,0 <--- 4,0 <--- 5,0
// \
// `---- 2,1 <--- 3,1 <--- 4,1 <--- 5,1 (winner)
let mut all_ops_no_majority = filtered_ops.clone();
let mut all_ops_no_majority = filtered_ops;

// 3,0
all_ops_no_majority[0][0].parent_block_ptr = 2;
Expand Down
8 changes: 2 additions & 6 deletions stackslib/src/burnchains/tests/burnchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,16 +428,12 @@ fn test_process_block_ops() {
],
vec![
BlockstackOperationType::LeaderBlockCommit(block_commit_1.clone()),
BlockstackOperationType::LeaderBlockCommit(block_commit_2.clone()),
BlockstackOperationType::LeaderBlockCommit(block_commit_2),
BlockstackOperationType::LeaderBlockCommit(block_commit_3.clone()),
],
];

let block_124_winners = vec![
block_commit_1.clone(),
block_commit_3.clone(),
block_commit_1.clone(),
];
let block_124_winners = vec![block_commit_1.clone(), block_commit_3, block_commit_1];

let mut db = SortitionDB::connect_test(first_block_height, &first_burn_hash).unwrap();

Expand Down
8 changes: 4 additions & 4 deletions stackslib/src/burnchains/tests/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn test_store_and_fetch() {
&BurnchainHeaderHash::sentinel()
);

let headers = vec![first_block_header.clone()];
let headers = vec![first_block_header];
let canon_hash = BurnchainHeaderHash([1; 32]);

let canonical_block =
Expand Down Expand Up @@ -1098,7 +1098,7 @@ fn test_classify_delegate_stx() {

let canonical_block =
BurnchainBlock::Bitcoin(BitcoinBlock::new(500, &canon_hash, &first_bhh, vec![], 485));
let mut headers = vec![first_block_header.clone(), canonical_block.header().clone()];
let mut headers = vec![first_block_header, canonical_block.header()];

let ops = burnchain_db
.store_new_burnchain_block(
Expand Down Expand Up @@ -1291,8 +1291,8 @@ fn test_classify_delegate_stx() {
360,
));

headers.push(block_0.header().clone());
headers.push(block_1.header().clone());
headers.push(block_0.header());
headers.push(block_1.header());

test_debug!("store ops ({}) for block 0", ops_0_length);
let processed_ops_0 = burnchain_db
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/burn/db/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl SortitionHandleTx<'_> {

let next_pox = SortitionDB::make_next_pox_id(parent_pox.clone(), next_pox_info.as_ref());
let next_sortition_id = SortitionDB::make_next_sortition_id(
parent_pox.clone(),
parent_pox,
&this_block_hash,
next_pox_info.as_ref(),
);
Expand Down
16 changes: 5 additions & 11 deletions stackslib/src/chainstate/burn/db/sortdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7330,9 +7330,9 @@ pub mod tests {
{
let mut ic = SortitionHandleTx::begin(&mut db, &snapshot.sortition_id).unwrap();
let keys = ic
.get_consumed_leader_keys(&fork_snapshot, &vec![block_commit.clone()])
.get_consumed_leader_keys(&fork_snapshot, &vec![block_commit])
.unwrap();
assert_eq!(keys, vec![leader_key.clone()]);
assert_eq!(keys, vec![leader_key]);
}
}

Expand Down Expand Up @@ -7381,9 +7381,7 @@ pub mod tests {
let key_snapshot = test_append_snapshot(
&mut db,
BurnchainHeaderHash([0x03; 32]),
&[BlockstackOperationType::LeaderKeyRegister(
leader_key.clone(),
)],
&[BlockstackOperationType::LeaderKeyRegister(leader_key)],
);

let has_key_after = {
Expand Down Expand Up @@ -7908,9 +7906,7 @@ pub mod tests {
let key_snapshot = test_append_snapshot(
&mut db,
BurnchainHeaderHash([0x01; 32]),
&[BlockstackOperationType::LeaderKeyRegister(
leader_key.clone(),
)],
&[BlockstackOperationType::LeaderKeyRegister(leader_key)],
);

let commit_snapshot = test_append_snapshot(
Expand Down Expand Up @@ -10254,9 +10250,7 @@ pub mod tests {
let key_snapshot = test_append_snapshot(
&mut db,
BurnchainHeaderHash([0x01; 32]),
&[BlockstackOperationType::LeaderKeyRegister(
leader_key.clone(),
)],
&[BlockstackOperationType::LeaderKeyRegister(leader_key)],
);

let genesis_commit_snapshot = test_append_snapshot_with_winner(
Expand Down
14 changes: 5 additions & 9 deletions stackslib/src/chainstate/burn/distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ mod tests {
let mut result = BurnSamplePoint::make_min_median_distribution(
MINING_COMMITMENT_WINDOW,
commits.clone(),
missed_commits.clone(),
missed_commits,
vec![false, false, false, false, false, false],
);

Expand Down Expand Up @@ -1261,11 +1261,7 @@ mod tests {
],
},
BurnDistFixture {
consumed_leader_keys: vec![
leader_key_1.clone(),
leader_key_2.clone(),
leader_key_3.clone(),
],
consumed_leader_keys: vec![leader_key_1, leader_key_2, leader_key_3],
block_commits: vec![
block_commit_1.clone(),
block_commit_2.clone(),
Expand All @@ -1283,7 +1279,7 @@ mod tests {
0x70989faf596c8b65,
0x41a3ed94d3cb0a84,
]),
candidate: block_commit_1.clone(),
candidate: block_commit_1,
},
BurnSamplePoint {
burns: block_commit_2.burn_fee.into(),
Expand All @@ -1301,7 +1297,7 @@ mod tests {
0xe1313f5eb2d916ca,
0x8347db29a7961508,
]),
candidate: block_commit_2.clone(),
candidate: block_commit_2,
},
BurnSamplePoint {
burns: (block_commit_3.burn_fee).into(),
Expand All @@ -1314,7 +1310,7 @@ mod tests {
0x8347db29a7961508,
]),
range_end: Uint256::max(),
candidate: block_commit_3.clone(),
candidate: block_commit_3,
},
],
},
Expand Down
10 changes: 5 additions & 5 deletions stackslib/src/chainstate/burn/operations/delegate_stx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ mod tests {
let op = DelegateStxOp::parse_from_tx(
16843022,
&BurnchainHeaderHash([0; 32]),
&BurnchainTransaction::Bitcoin(tx.clone()),
&BurnchainTransaction::Bitcoin(tx),
&sender,
)
.unwrap();
Expand Down Expand Up @@ -456,7 +456,7 @@ mod tests {
let err = DelegateStxOp::parse_from_tx(
16843022,
&BurnchainHeaderHash([0; 32]),
&BurnchainTransaction::Bitcoin(tx.clone()),
&BurnchainTransaction::Bitcoin(tx),
&sender,
)
.unwrap_err();
Expand Down Expand Up @@ -498,7 +498,7 @@ mod tests {
let err = DelegateStxOp::parse_from_tx(
16843022,
&BurnchainHeaderHash([0; 32]),
&BurnchainTransaction::Bitcoin(tx.clone()),
&BurnchainTransaction::Bitcoin(tx),
&sender,
)
.unwrap_err();
Expand Down Expand Up @@ -544,7 +544,7 @@ mod tests {
let err = DelegateStxOp::parse_from_tx(
16843022,
&BurnchainHeaderHash([0; 32]),
&BurnchainTransaction::Bitcoin(tx.clone()),
&BurnchainTransaction::Bitcoin(tx),
&sender,
)
.unwrap_err();
Expand Down Expand Up @@ -583,7 +583,7 @@ mod tests {
let err = DelegateStxOp::parse_from_tx(
16843022,
&BurnchainHeaderHash([0; 32]),
&BurnchainTransaction::Bitcoin(tx.clone()),
&BurnchainTransaction::Bitcoin(tx),
&sender,
)
.unwrap_err();
Expand Down
Loading
Loading