Skip to content

Commit 9139fb2

Browse files
authored
Merge pull request #5654 from jbencin/chore/clippy-collection-is-never-read
chore: Apply Clippy lint `collection_is_never_used`
2 parents 99ef43c + d57bff5 commit 9139fb2

File tree

24 files changed

+20
-206
lines changed

24 files changed

+20
-206
lines changed

stackslib/src/burnchains/tests/burnchain.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -694,32 +694,21 @@ fn test_burn_snapshot_sequence() {
694694
initial_reward_start_block: first_block_height,
695695
};
696696

697-
let mut leader_private_keys = vec![];
698697
let mut leader_public_keys = vec![];
699698
let mut leader_bitcoin_public_keys = vec![];
700-
let mut leader_bitcoin_addresses = vec![];
701699

702700
for i in 0..32 {
703701
let mut csprng: ThreadRng = thread_rng();
704702
let vrf_privkey = VRFPrivateKey(ed25519_dalek::SigningKey::generate(&mut csprng));
705703
let vrf_pubkey = VRFPublicKey::from_private(&vrf_privkey);
706704

707-
let privkey_hex = vrf_privkey.to_hex();
708-
leader_private_keys.push(privkey_hex);
709-
710705
let pubkey_hex = vrf_pubkey.to_hex();
711706
leader_public_keys.push(pubkey_hex);
712707

713708
let bitcoin_privkey = Secp256k1PrivateKey::random();
714709
let bitcoin_publickey = BitcoinPublicKey::from_private(&bitcoin_privkey);
715710

716711
leader_bitcoin_public_keys.push(to_hex(&bitcoin_publickey.to_bytes()));
717-
718-
leader_bitcoin_addresses.push(BitcoinAddress::from_bytes_legacy(
719-
BitcoinNetworkType::Testnet,
720-
LegacyBitcoinAddressType::PublicKeyHash,
721-
&Hash160::from_data(&bitcoin_publickey.to_bytes()).0,
722-
));
723712
}
724713

725714
let mut expected_burn_total: u64 = 0;
@@ -728,7 +717,6 @@ fn test_burn_snapshot_sequence() {
728717
let mut db = SortitionDB::connect_test(first_block_height, &first_burn_hash).unwrap();
729718
let mut prev_snapshot =
730719
BlockSnapshot::initial(first_block_height, &first_burn_hash, first_block_height);
731-
let mut all_stacks_block_hashes = vec![];
732720

733721
for i in 0..32 {
734722
let mut block_ops = vec![];
@@ -819,7 +807,6 @@ fn test_burn_snapshot_sequence() {
819807
burn_header_hash: burn_block_hash.clone(),
820808
};
821809

822-
all_stacks_block_hashes.push(next_block_commit.block_header_hash.clone());
823810
block_ops.push(BlockstackOperationType::LeaderBlockCommit(
824811
next_block_commit,
825812
));

stackslib/src/burnchains/tests/db.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,6 @@ fn test_update_block_descendancy_with_fork() {
915915
let mut cmts_genesis = vec![];
916916
let mut cmts_invalid = vec![];
917917

918-
let mut fork_parent = None;
919-
let mut fork_parent_block_header: Option<BurnchainBlockHeader> = None;
920918
let mut fork_cmts = vec![];
921919

922920
for i in 0..5 {
@@ -950,7 +948,6 @@ fn test_update_block_descendancy_with_fork() {
950948
};
951949

952950
fork_headers.push(block_header.clone());
953-
fork_parent_block_header = Some(block_header);
954951
}
955952

956953
let mut am_id = 0;
@@ -1014,7 +1011,6 @@ fn test_update_block_descendancy_with_fork() {
10141011
fork_cmts.push(fork_cmt.clone());
10151012

10161013
parent = Some(cmt);
1017-
fork_parent = Some(fork_cmt);
10181014

10191015
if i == 0 {
10201016
am_id = {

stackslib/src/chainstate/coordinator/tests.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,7 +2253,6 @@ fn test_sortition_with_reward_set() {
22532253
let mut started_first_reward_cycle = false;
22542254
// process sequential blocks, and their sortitions...
22552255
let mut stacks_blocks: Vec<(SortitionId, StacksBlock)> = vec![];
2256-
let mut anchor_blocks = vec![];
22572256

22582257
// split up the vrf keys and committers so that we have some that will be mining "correctly"
22592258
// and some that will be producing bad outputs
@@ -2427,10 +2426,6 @@ fn test_sortition_with_reward_set() {
24272426
let new_burnchain_tip = burnchain.get_canonical_chain_tip().unwrap();
24282427
if b.is_reward_cycle_start(new_burnchain_tip.block_height) {
24292428
started_first_reward_cycle = true;
2430-
// store the anchor block for this sortition for later checking
2431-
let ic = sort_db.index_handle_at_tip();
2432-
let bhh = ic.get_last_anchor_block_hash().unwrap().unwrap();
2433-
anchor_blocks.push(bhh);
24342429
}
24352430

24362431
let tip = SortitionDB::get_canonical_burn_chain_tip(sort_db.conn()).unwrap();
@@ -2525,7 +2520,6 @@ fn test_sortition_with_burner_reward_set() {
25252520
let mut started_first_reward_cycle = false;
25262521
// process sequential blocks, and their sortitions...
25272522
let mut stacks_blocks: Vec<(SortitionId, StacksBlock)> = vec![];
2528-
let mut anchor_blocks = vec![];
25292523

25302524
// split up the vrf keys and committers so that we have some that will be mining "correctly"
25312525
// and some that will be producing bad outputs
@@ -2673,10 +2667,6 @@ fn test_sortition_with_burner_reward_set() {
26732667
let new_burnchain_tip = burnchain.get_canonical_chain_tip().unwrap();
26742668
if b.is_reward_cycle_start(new_burnchain_tip.block_height) {
26752669
started_first_reward_cycle = true;
2676-
// store the anchor block for this sortition for later checking
2677-
let ic = sort_db.index_handle_at_tip();
2678-
let bhh = ic.get_last_anchor_block_hash().unwrap().unwrap();
2679-
anchor_blocks.push(bhh);
26802670
}
26812671

26822672
let tip = SortitionDB::get_canonical_burn_chain_tip(sort_db.conn()).unwrap();
@@ -2789,7 +2779,6 @@ fn test_pox_btc_ops() {
27892779
let mut started_first_reward_cycle = false;
27902780
// process sequential blocks, and their sortitions...
27912781
let mut stacks_blocks: Vec<(SortitionId, StacksBlock)> = vec![];
2792-
let mut anchor_blocks = vec![];
27932782

27942783
// track the reward set consumption
27952784
let mut reward_cycle_count = 0;
@@ -2957,10 +2946,6 @@ fn test_pox_btc_ops() {
29572946
if b.is_reward_cycle_start(new_burnchain_tip.block_height) {
29582947
if new_burnchain_tip.block_height < sunset_ht {
29592948
started_first_reward_cycle = true;
2960-
// store the anchor block for this sortition for later checking
2961-
let ic = sort_db.index_handle_at_tip();
2962-
let bhh = ic.get_last_anchor_block_hash().unwrap().unwrap();
2963-
anchor_blocks.push(bhh);
29642949
} else {
29652950
// store the anchor block for this sortition for later checking
29662951
let ic = sort_db.index_handle_at_tip();
@@ -3081,7 +3066,6 @@ fn test_stx_transfer_btc_ops() {
30813066
let mut started_first_reward_cycle = false;
30823067
// process sequential blocks, and their sortitions...
30833068
let mut stacks_blocks: Vec<(SortitionId, StacksBlock)> = vec![];
3084-
let mut anchor_blocks = vec![];
30853069

30863070
// track the reward set consumption
30873071
let mut reward_recipients = HashSet::new();
@@ -3304,10 +3288,6 @@ fn test_stx_transfer_btc_ops() {
33043288
if b.is_reward_cycle_start(new_burnchain_tip.block_height) {
33053289
if new_burnchain_tip.block_height < sunset_ht {
33063290
started_first_reward_cycle = true;
3307-
// store the anchor block for this sortition for later checking
3308-
let ic = sort_db.index_handle_at_tip();
3309-
let bhh = ic.get_last_anchor_block_hash().unwrap().unwrap();
3310-
anchor_blocks.push(bhh);
33113291
} else {
33123292
// store the anchor block for this sortition for later checking
33133293
let ic = sort_db.index_handle_at_tip();
@@ -5288,7 +5268,6 @@ fn test_sortition_with_sunset() {
52885268
let mut started_first_reward_cycle = false;
52895269
// process sequential blocks, and their sortitions...
52905270
let mut stacks_blocks: Vec<(SortitionId, StacksBlock)> = vec![];
5291-
let mut anchor_blocks = vec![];
52925271

52935272
// split up the vrf keys and committers so that we have some that will be mining "correctly"
52945273
// and some that will be producing bad outputs
@@ -5472,10 +5451,6 @@ fn test_sortition_with_sunset() {
54725451
if b.is_reward_cycle_start(new_burnchain_tip.block_height) {
54735452
if new_burnchain_tip.block_height < sunset_ht {
54745453
started_first_reward_cycle = true;
5475-
// store the anchor block for this sortition for later checking
5476-
let ic = sort_db.index_handle_at_tip();
5477-
let bhh = ic.get_last_anchor_block_hash().unwrap().unwrap();
5478-
anchor_blocks.push(bhh);
54795454
} else {
54805455
// store the anchor block for this sortition for later checking
54815456
let ic = sort_db.index_handle_at_tip();
@@ -5601,7 +5576,6 @@ fn test_sortition_with_sunset_and_epoch_switch() {
56015576
let mut started_first_reward_cycle = false;
56025577
// process sequential blocks, and their sortitions...
56035578
let mut stacks_blocks: Vec<(SortitionId, StacksBlock)> = vec![];
5604-
let mut anchor_blocks = vec![];
56055579

56065580
// split up the vrf keys and committers so that we have some that will be mining "correctly"
56075581
// and some that will be producing bad outputs
@@ -5813,10 +5787,6 @@ fn test_sortition_with_sunset_and_epoch_switch() {
58135787
if b.is_reward_cycle_start(new_burnchain_tip.block_height) {
58145788
if new_burnchain_tip.block_height < sunset_ht {
58155789
started_first_reward_cycle = true;
5816-
// store the anchor block for this sortition for later checking
5817-
let ic = sort_db.index_handle_at_tip();
5818-
let bhh = ic.get_last_anchor_block_hash().unwrap().unwrap();
5819-
anchor_blocks.push(bhh);
58205790
} else {
58215791
// store the anchor block for this sortition for later checking
58225792
let ic = sort_db.index_handle_at_tip();
@@ -6464,7 +6434,6 @@ fn test_pox_fork_out_of_order() {
64646434
let mut sortition_ids_diverged = false;
64656435
// process sequential blocks, and their sortitions...
64666436
let mut stacks_blocks: Vec<(SortitionId, StacksBlock)> = vec![];
6467-
let mut anchor_blocks = vec![];
64686437

64696438
// setup:
64706439
// 2 forks: 0 - 1 - 2 - 3 - 4 - 5 - 11 - 12 - 13 - 14 - 15
@@ -6545,8 +6514,6 @@ fn test_pox_fork_out_of_order() {
65456514
.unwrap()
65466515
.block_height
65476516
);
6548-
6549-
anchor_blocks.push(bhh);
65506517
}
65516518

65526519
let tip = SortitionDB::get_canonical_burn_chain_tip(sort_db.conn()).unwrap();

stackslib/src/chainstate/nakamoto/coordinator/tests.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ fn advance_to_nakamoto(
112112
let default_pox_addr =
113113
PoxAddress::from_legacy(AddressHashMode::SerializeP2PKH, addr.bytes().clone());
114114

115-
let mut tip = None;
116115
for sortition_height in 0..11 {
117116
// stack to pox-3 in cycle 7
118117
let txs = if sortition_height == 6 {
@@ -156,7 +155,7 @@ fn advance_to_nakamoto(
156155
vec![]
157156
};
158157

159-
tip = Some(peer.tenure_with_txs(&txs, &mut peer_nonce));
158+
peer.tenure_with_txs(&txs, &mut peer_nonce);
160159
}
161160
// peer is at the start of cycle 8
162161
}
@@ -347,9 +346,6 @@ fn replay_reward_cycle(
347346
.step_by(reward_cycle_length)
348347
.collect();
349348

350-
let mut indexes: Vec<_> = (0..stacks_blocks.len()).collect();
351-
indexes.shuffle(&mut thread_rng());
352-
353349
for burn_ops in burn_ops.iter() {
354350
let (_, _, consensus_hash) = peer.next_burnchain_block(burn_ops.clone());
355351
}
@@ -842,7 +838,6 @@ fn block_descendant() {
842838
boot_plan.pox_constants = pox_constants;
843839

844840
let mut peer = boot_plan.boot_into_nakamoto_peer(vec![], None);
845-
let mut blocks = vec![];
846841
let pox_constants = peer.sortdb().pox_constants.clone();
847842
let first_burn_height = peer.sortdb().first_block_height;
848843

@@ -851,7 +846,6 @@ fn block_descendant() {
851846
loop {
852847
let (block, burn_height, ..) =
853848
peer.single_block_tenure(&private_key, |_| {}, |_| {}, |_| true);
854-
blocks.push(block);
855849

856850
if pox_constants.is_in_prepare_phase(first_burn_height, burn_height + 1) {
857851
info!("At prepare phase start"; "burn_height" => burn_height);
@@ -3196,9 +3190,6 @@ fn test_stacks_on_burnchain_ops() {
31963190
);
31973191

31983192
let mut all_blocks: Vec<NakamotoBlock> = vec![];
3199-
let mut all_burn_ops = vec![];
3200-
let mut consensus_hashes = vec![];
3201-
let mut fee_counts = vec![];
32023193
let stx_miner_key = peer.miner.nakamoto_miner_key();
32033194

32043195
let mut extra_burn_ops = vec![];
@@ -3395,8 +3386,6 @@ fn test_stacks_on_burnchain_ops() {
33953386
})
33963387
.sum::<u128>();
33973388

3398-
consensus_hashes.push(consensus_hash);
3399-
fee_counts.push(fees);
34003389
let mut blocks: Vec<NakamotoBlock> = blocks_and_sizes
34013390
.into_iter()
34023391
.map(|(block, _, _)| block)
@@ -3438,7 +3427,6 @@ fn test_stacks_on_burnchain_ops() {
34383427
);
34393428

34403429
all_blocks.append(&mut blocks);
3441-
all_burn_ops.push(burn_ops);
34423430
}
34433431

34443432
// check receipts for burn ops

stackslib/src/chainstate/nakamoto/tests/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,8 +2518,6 @@ fn parse_vote_for_aggregate_public_key_invalid() {
25182518
};
25192519
invalid_function_arg_reward_cycle.set_origin_nonce(1);
25202520

2521-
let mut account_nonces = std::collections::HashMap::new();
2522-
account_nonces.insert(invalid_contract_name.origin_address(), 1);
25232521
for (i, tx) in vec![
25242522
invalid_contract_address,
25252523
invalid_contract_name,

stackslib/src/chainstate/stacks/block.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,19 +1137,6 @@ mod test {
11371137
StacksEpochId::latest(),
11381138
);
11391139

1140-
// remove all coinbases
1141-
let mut txs_anchored = vec![];
1142-
1143-
for tx in all_txs.iter() {
1144-
match tx.payload {
1145-
TransactionPayload::Coinbase(..) => {
1146-
continue;
1147-
}
1148-
_ => {}
1149-
}
1150-
txs_anchored.push(tx);
1151-
}
1152-
11531140
// make microblocks with 3 transactions each (or fewer)
11541141
for i in 0..(all_txs.len() / 3) {
11551142
let txs = vec![

stackslib/src/chainstate/stacks/boot/pox_4_tests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,8 @@ fn pox_lock_unlock() {
928928

929929
assert_eq!(burnchain.pox_constants.reward_slots(), 6);
930930
let mut coinbase_nonce = 0;
931+
// Stores the result of a function with side effects, so have Clippy ignore it
932+
#[allow(clippy::collection_is_never_read)]
931933
let mut latest_block = None;
932934

933935
// Advance into pox4
@@ -2693,6 +2695,8 @@ fn pox_4_delegate_stack_increase_events() {
26932695

26942696
assert_eq!(burnchain.pox_constants.reward_slots(), 6);
26952697
let mut coinbase_nonce = 0;
2698+
// Stores the result of a function with side effects, so have Clippy ignore it
2699+
#[allow(clippy::collection_is_never_read)]
26962700
let mut latest_block = None;
26972701

26982702
let alice_key = keys.pop().unwrap();

stackslib/src/chainstate/stacks/db/transactions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ impl TryFrom<Value> for HashableClarityValue {
7272

7373
impl std::hash::Hash for HashableClarityValue {
7474
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
75-
#[allow(clippy::unwrap_used)]
75+
#[allow(clippy::unwrap_used, clippy::collection_is_never_read)]
7676
// this unwrap is safe _as long as_ TryFrom<Value> was used as a constructor
77+
// Also, this function has side effects, which cause Clippy to wrongly think `bytes` is unused
7778
let bytes = self.0.serialize_to_vec().unwrap();
7879
bytes.hash(state);
7980
}

stackslib/src/chainstate/stacks/index/test/trie.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,8 +1232,6 @@ fn trie_cursor_splice_leaf_4() {
12321232
let (nodes, node_ptrs, hashes) =
12331233
make_node_path(&mut f, node_id.to_u8(), &path_segments, [31u8; 40].to_vec());
12341234

1235-
let mut ptrs = vec![];
1236-
12371235
// splice in a node in each path segment
12381236
for k in 0..5 {
12391237
let mut path = vec![
@@ -1261,7 +1259,6 @@ fn trie_cursor_splice_leaf_4() {
12611259
&mut node,
12621260
)
12631261
.unwrap();
1264-
ptrs.push(new_ptr);
12651262

12661263
Trie::update_root_hash(&mut f, &c).unwrap();
12671264

@@ -1325,7 +1322,6 @@ fn trie_cursor_splice_leaf_2() {
13251322

13261323
let (nodes, node_ptrs, hashes) =
13271324
make_node_path(&mut f, node_id.to_u8(), &path_segments, [31u8; 40].to_vec());
1328-
let mut ptrs = vec![];
13291325

13301326
// splice in a node in each path segment
13311327
for k in 0..10 {
@@ -1350,7 +1346,6 @@ fn trie_cursor_splice_leaf_2() {
13501346
&mut node,
13511347
)
13521348
.unwrap();
1353-
ptrs.push(new_ptr);
13541349

13551350
Trie::update_root_hash(&mut f, &c).unwrap();
13561351

0 commit comments

Comments
 (0)