Skip to content

Commit c147821

Browse files
authored
Merge pull request #5656 from jbencin/chore/clippy-vec-and-iter-lints
chore: Apply Clippy `vec_init_then_push`, `map_clone`, `map_entry`, and `iter_*` lints
2 parents 918a79b + 9978402 commit c147821

File tree

33 files changed

+149
-200
lines changed

33 files changed

+149
-200
lines changed

clarity/src/vm/tests/datamaps.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,15 +642,15 @@ fn bad_define_maps() {
642642
"(define-map lists { name: int } contents 5)",
643643
"(define-map lists { name: int } { contents: (list 5 0 int) })",
644644
];
645-
let mut expected: Vec<Error> = vec![
645+
let expected: Vec<Error> = vec![
646646
CheckErrors::BadSyntaxExpectedListOfPairs.into(),
647647
CheckErrors::UnknownTypeName("contents".to_string()).into(),
648648
CheckErrors::ExpectedName.into(),
649649
CheckErrors::IncorrectArgumentCount(3, 4).into(),
650650
CheckErrors::InvalidTypeDescription.into(),
651651
];
652652

653-
for (test, expected_err) in tests.iter().zip(expected.drain(..)) {
653+
for (test, expected_err) in tests.iter().zip(expected.into_iter()) {
654654
let outcome = execute(test).unwrap_err();
655655
assert_eq!(outcome, expected_err);
656656
}
@@ -666,7 +666,7 @@ fn bad_tuples() {
666666
"(get name five (tuple (name 1)))",
667667
"(get 1234 (tuple (name 1)))",
668668
];
669-
let mut expected = vec![
669+
let expected = vec![
670670
CheckErrors::NameAlreadyUsed("name".into()),
671671
CheckErrors::BadSyntaxBinding,
672672
CheckErrors::BadSyntaxBinding,
@@ -678,7 +678,7 @@ fn bad_tuples() {
678678
CheckErrors::ExpectedName,
679679
];
680680

681-
for (test, expected_err) in tests.iter().zip(expected.drain(..)) {
681+
for (test, expected_err) in tests.iter().zip(expected.into_iter()) {
682682
let outcome = execute(test).unwrap_err();
683683
assert_eq!(outcome, expected_err.into());
684684
}

stacks-common/src/address/c32_old.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn c32_encode(input_bytes: &[u8]) -> String {
6767
}
6868
}
6969

70-
let result: Vec<u8> = result.drain(..).rev().collect();
70+
let result: Vec<u8> = result.into_iter().rev().collect();
7171
String::from_utf8(result).unwrap()
7272
}
7373

stacks-common/src/util/chunked_encoding.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,14 @@ mod test {
504504

505505
#[test]
506506
fn test_segment_reader() {
507-
let mut tests = vec![
507+
let tests = vec![
508508
(vec_u8(vec!["a", "b"]), "ab"),
509509
(vec_u8(vec!["aa", "bbb", "cccc"]), "aabbbcccc"),
510510
(vec_u8(vec!["aaaa", "bbb", "cc", "d", ""]), "aaaabbbccd"),
511511
(vec_u8(vec!["", "a", "", "b", ""]), "ab"),
512512
(vec_u8(vec![""]), ""),
513513
];
514-
for (input_vec, expected) in tests.drain(..) {
514+
for (input_vec, expected) in tests.into_iter() {
515515
let num_segments = input_vec.len();
516516
let mut segment_io = SegmentReader::new(input_vec);
517517
let mut output = vec![0u8; expected.len()];

stackslib/src/burnchains/affirmation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ pub fn read_parent_block_commits<B: BurnchainHeaderReader>(
679679
}
680680
}
681681
}
682-
let mut parent_list: Vec<_> = parents.into_iter().map(|(_, cmt)| cmt).collect();
682+
let mut parent_list: Vec<_> = parents.into_values().collect();
683683
parent_list.sort_by(|a, b| {
684684
if a.block_height != b.block_height {
685685
a.block_height.cmp(&b.block_height)

stackslib/src/burnchains/burnchain.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl BurnchainStateTransition {
136136
return Some(block_total_burns[0]);
137137
} else if block_total_burns.len() % 2 != 0 {
138138
let idx = block_total_burns.len() / 2;
139-
return block_total_burns.get(idx).map(|b| *b);
139+
return block_total_burns.get(idx).copied();
140140
} else {
141141
// NOTE: the `- 1` is safe because block_total_burns.len() >= 2
142142
let idx_left = block_total_burns.len() / 2 - 1;
@@ -269,8 +269,7 @@ impl BurnchainStateTransition {
269269
let mut missed_commits_at_height =
270270
SortitionDB::get_missed_commits_by_intended(sort_tx.tx(), &sortition_id)?;
271271
if let Some(missed_commit_in_block) = missed_commits_map.remove(&sortition_id) {
272-
missed_commits_at_height
273-
.extend(missed_commit_in_block.into_iter().map(|x| x.clone()));
272+
missed_commits_at_height.extend(missed_commit_in_block.into_iter().cloned());
274273
}
275274

276275
windowed_missed_commits.push(missed_commits_at_height);

stackslib/src/burnchains/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,8 +1245,8 @@ impl BurnchainDB {
12451245

12461246
ops.extend(
12471247
pre_stx_ops
1248-
.into_iter()
1249-
.map(|(_, op)| BlockstackOperationType::PreStx(op)),
1248+
.into_values()
1249+
.map(BlockstackOperationType::PreStx),
12501250
);
12511251

12521252
ops.sort_by_key(|op| op.vtxindex());

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

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,54 +3238,53 @@ fn test_stacks_on_burnchain_ops() {
32383238
let (mut burn_ops, mut tenure_change, miner_key) =
32393239
peer.begin_nakamoto_tenure(TenureChangeCause::BlockFound);
32403240

3241-
let mut new_burn_ops = vec![];
3242-
new_burn_ops.push(BlockstackOperationType::DelegateStx(DelegateStxOp {
3243-
sender: addr.clone(),
3244-
delegate_to: recipient_addr.clone(),
3245-
reward_addr: None,
3246-
delegated_ustx: 1,
3247-
until_burn_height: None,
3248-
3249-
// mocked
3250-
txid: Txid([i; 32]),
3251-
vtxindex: 11,
3252-
block_height: block_height + 1,
3253-
burn_header_hash: BurnchainHeaderHash([0x00; 32]),
3254-
}));
3255-
new_burn_ops.push(BlockstackOperationType::StackStx(StackStxOp {
3256-
sender: addr.clone(),
3257-
reward_addr: PoxAddress::Standard(
3258-
recipient_addr.clone(),
3259-
Some(AddressHashMode::SerializeP2PKH),
3260-
),
3261-
stacked_ustx: 1,
3262-
num_cycles: 1,
3263-
signer_key: Some(StacksPublicKeyBuffer::from_public_key(
3264-
&StacksPublicKey::from_private(&recipient_private_key),
3265-
)),
3266-
max_amount: Some(1),
3267-
auth_id: Some(i as u32),
3268-
3269-
// mocked
3270-
txid: Txid([i | 0x80; 32]),
3271-
vtxindex: 12,
3272-
block_height: block_height + 1,
3273-
burn_header_hash: BurnchainHeaderHash([0x00; 32]),
3274-
}));
3275-
new_burn_ops.push(BlockstackOperationType::TransferStx(TransferStxOp {
3276-
sender: addr.clone(),
3277-
recipient: recipient_addr.clone(),
3278-
transfered_ustx: 1,
3279-
memo: vec![0x2],
3280-
3281-
// mocked
3282-
txid: Txid([i | 0x40; 32]),
3283-
vtxindex: 13,
3284-
block_height: block_height + 1,
3285-
burn_header_hash: BurnchainHeaderHash([0x00; 32]),
3286-
}));
3287-
new_burn_ops.push(BlockstackOperationType::VoteForAggregateKey(
3288-
VoteForAggregateKeyOp {
3241+
let mut new_burn_ops = vec![
3242+
BlockstackOperationType::DelegateStx(DelegateStxOp {
3243+
sender: addr.clone(),
3244+
delegate_to: recipient_addr.clone(),
3245+
reward_addr: None,
3246+
delegated_ustx: 1,
3247+
until_burn_height: None,
3248+
3249+
// mocked
3250+
txid: Txid([i; 32]),
3251+
vtxindex: 11,
3252+
block_height: block_height + 1,
3253+
burn_header_hash: BurnchainHeaderHash([0x00; 32]),
3254+
}),
3255+
BlockstackOperationType::StackStx(StackStxOp {
3256+
sender: addr.clone(),
3257+
reward_addr: PoxAddress::Standard(
3258+
recipient_addr.clone(),
3259+
Some(AddressHashMode::SerializeP2PKH),
3260+
),
3261+
stacked_ustx: 1,
3262+
num_cycles: 1,
3263+
signer_key: Some(StacksPublicKeyBuffer::from_public_key(
3264+
&StacksPublicKey::from_private(&recipient_private_key),
3265+
)),
3266+
max_amount: Some(1),
3267+
auth_id: Some(i as u32),
3268+
3269+
// mocked
3270+
txid: Txid([i | 0x80; 32]),
3271+
vtxindex: 12,
3272+
block_height: block_height + 1,
3273+
burn_header_hash: BurnchainHeaderHash([0x00; 32]),
3274+
}),
3275+
BlockstackOperationType::TransferStx(TransferStxOp {
3276+
sender: addr.clone(),
3277+
recipient: recipient_addr.clone(),
3278+
transfered_ustx: 1,
3279+
memo: vec![0x2],
3280+
3281+
// mocked
3282+
txid: Txid([i | 0x40; 32]),
3283+
vtxindex: 13,
3284+
block_height: block_height + 1,
3285+
burn_header_hash: BurnchainHeaderHash([0x00; 32]),
3286+
}),
3287+
BlockstackOperationType::VoteForAggregateKey(VoteForAggregateKeyOp {
32893288
sender: addr.clone(),
32903289
aggregate_key: StacksPublicKeyBuffer::from_public_key(
32913290
&StacksPublicKey::from_private(&agg_private_key),
@@ -3302,8 +3301,8 @@ fn test_stacks_on_burnchain_ops() {
33023301
vtxindex: 14,
33033302
block_height: block_height + 1,
33043303
burn_header_hash: BurnchainHeaderHash([0x00; 32]),
3305-
},
3306-
));
3304+
}),
3305+
];
33073306

33083307
extra_burn_ops.push(new_burn_ops.clone());
33093308
burn_ops.append(&mut new_burn_ops);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ impl UnconfirmedState {
443443
&self,
444444
txid: &Txid,
445445
) -> Option<(StacksTransaction, BlockHeaderHash, u16)> {
446-
self.mined_txs.get(txid).map(|x| x.clone())
446+
self.mined_txs.get(txid).cloned()
447447
}
448448

449449
pub fn num_microblocks(&self) -> u64 {

stackslib/src/chainstate/stacks/index/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl<T: MarfTrieId> TrieCacheState<T> {
151151

152152
/// Get the block ID, given its hash
153153
pub fn load_block_id(&self, block_hash: &T) -> Option<u32> {
154-
self.block_id_cache.get(block_hash).map(|id| *id)
154+
self.block_id_cache.get(block_hash).copied()
155155
}
156156
}
157157

stackslib/src/chainstate/stacks/miner.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,7 @@ pub struct MinerEpochInfo<'a> {
262262

263263
impl From<&UnconfirmedState> for MicroblockMinerRuntime {
264264
fn from(unconfirmed: &UnconfirmedState) -> MicroblockMinerRuntime {
265-
let considered = unconfirmed
266-
.mined_txs
267-
.iter()
268-
.map(|(txid, _)| txid.clone())
269-
.collect();
265+
let considered = unconfirmed.mined_txs.keys().cloned().collect();
270266
MicroblockMinerRuntime {
271267
bytes_so_far: unconfirmed.bytes_so_far,
272268
prev_microblock_header: unconfirmed.last_mblock.clone(),

0 commit comments

Comments
 (0)