Skip to content

Commit da64cec

Browse files
committed
chore: Apply Clippy lint single_match
1 parent 2f2cb53 commit da64cec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+663
-1033
lines changed

stackslib/src/burnchains/bitcoin/indexer.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -282,23 +282,17 @@ impl BitcoinIndexer {
282282
btc_error::ConnectionError
283283
})?;
284284

285-
match self.runtime.sock.take() {
286-
Some(s) => {
287-
let _ = s.shutdown(Shutdown::Both);
288-
}
289-
None => {}
285+
if let Some(s) = self.runtime.sock.take() {
286+
let _ = s.shutdown(Shutdown::Both);
290287
}
291288

292289
self.runtime.sock = Some(s);
293290
Ok(())
294291
}
295292
Err(_e) => {
296293
let s = self.runtime.sock.take();
297-
match s {
298-
Some(s) => {
299-
let _ = s.shutdown(Shutdown::Both);
300-
}
301-
None => {}
294+
if let Some(s) = s {
295+
let _ = s.shutdown(Shutdown::Both);
302296
}
303297
Err(btc_error::ConnectionError)
304298
}
@@ -932,11 +926,8 @@ impl BitcoinIndexer {
932926

933927
impl Drop for BitcoinIndexer {
934928
fn drop(&mut self) {
935-
match self.runtime.sock {
936-
Some(ref mut s) => {
937-
let _ = s.shutdown(Shutdown::Both);
938-
}
939-
None => {}
929+
if let Some(ref mut s) = self.runtime.sock {
930+
let _ = s.shutdown(Shutdown::Both);
940931
}
941932
}
942933
}

stackslib/src/burnchains/tests/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,9 @@ impl TestBurnchainBlock {
580580
assert_eq!(parent_snapshot.block_height + 1, self.block_height);
581581

582582
for i in 0..self.txs.len() {
583-
match self.txs[i] {
584-
BlockstackOperationType::LeaderKeyRegister(ref mut data) => {
585-
assert_eq!(data.block_height, self.block_height);
586-
data.consensus_hash = parent_snapshot.consensus_hash.clone();
587-
}
588-
_ => {}
583+
if let BlockstackOperationType::LeaderKeyRegister(ref mut data) = self.txs[i] {
584+
assert_eq!(data.block_height, self.block_height);
585+
data.consensus_hash = parent_snapshot.consensus_hash.clone();
589586
}
590587
}
591588
}

stackslib/src/chainstate/stacks/block.rs

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -353,16 +353,13 @@ impl StacksMessageCodec for StacksBlock {
353353
// must be only one coinbase
354354
let mut coinbase_count = 0;
355355
for tx in txs.iter() {
356-
match tx.payload {
357-
TransactionPayload::Coinbase(..) => {
358-
coinbase_count += 1;
359-
if coinbase_count > 1 {
360-
return Err(codec_error::DeserializeError(
361-
"Invalid block: multiple coinbases found".to_string(),
362-
));
363-
}
356+
if let TransactionPayload::Coinbase(..) = tx.payload {
357+
coinbase_count += 1;
358+
if coinbase_count > 1 {
359+
return Err(codec_error::DeserializeError(
360+
"Invalid block: multiple coinbases found".to_string(),
361+
));
364362
}
365-
_ => {}
366363
}
367364
}
368365

@@ -518,26 +515,23 @@ impl StacksBlock {
518515
let mut found_coinbase = false;
519516
let mut coinbase_index = 0;
520517
for (i, tx) in txs.iter().enumerate() {
521-
match tx.payload {
522-
TransactionPayload::Coinbase(..) => {
523-
if !check_present {
524-
warn!("Found unexpected coinbase tx {}", tx.txid());
525-
return false;
526-
}
527-
528-
if found_coinbase {
529-
warn!("Found duplicate coinbase tx {}", tx.txid());
530-
return false;
531-
}
532-
533-
if tx.anchor_mode != TransactionAnchorMode::OnChainOnly {
534-
warn!("Invalid coinbase tx {}: not on-chain only", tx.txid());
535-
return false;
536-
}
537-
found_coinbase = true;
538-
coinbase_index = i;
518+
if let TransactionPayload::Coinbase(..) = tx.payload {
519+
if !check_present {
520+
warn!("Found unexpected coinbase tx {}", tx.txid());
521+
return false;
522+
}
523+
524+
if found_coinbase {
525+
warn!("Found duplicate coinbase tx {}", tx.txid());
526+
return false;
539527
}
540-
_ => {}
528+
529+
if tx.anchor_mode != TransactionAnchorMode::OnChainOnly {
530+
warn!("Invalid coinbase tx {}: not on-chain only", tx.txid());
531+
return false;
532+
}
533+
found_coinbase = true;
534+
coinbase_index = i;
541535
}
542536
}
543537

@@ -1150,11 +1144,8 @@ mod test {
11501144
let mut txs_anchored = vec![];
11511145

11521146
for tx in all_txs.iter() {
1153-
match tx.payload {
1154-
TransactionPayload::Coinbase(..) => {
1155-
continue;
1156-
}
1157-
_ => {}
1147+
if let TransactionPayload::Coinbase(..) = tx.payload {
1148+
continue;
11581149
}
11591150
txs_anchored.push(tx);
11601151
}

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,23 +1371,20 @@ fn test_simple_pox_2_auto_unlock(alice_first: bool) {
13711371
coinbase_txs.push(r);
13721372
continue;
13731373
}
1374-
match r.transaction {
1375-
TransactionOrigin::Stacks(ref t) => {
1376-
let addr = t.auth.origin().address_testnet();
1377-
eprintln!("TX addr: {}", addr);
1378-
if addr == alice_address {
1379-
alice_txs.insert(t.auth.get_origin_nonce(), r);
1380-
} else if addr == bob_address {
1381-
bob_txs.insert(t.auth.get_origin_nonce(), r);
1382-
} else if addr == charlie_address {
1383-
assert!(
1384-
r.execution_cost != ExecutionCost::ZERO,
1385-
"Execution cost is not zero!"
1386-
);
1387-
charlie_txs.insert(t.auth.get_origin_nonce(), r);
1388-
}
1374+
if let TransactionOrigin::Stacks(ref t) = r.transaction {
1375+
let addr = t.auth.origin().address_testnet();
1376+
eprintln!("TX addr: {}", addr);
1377+
if addr == alice_address {
1378+
alice_txs.insert(t.auth.get_origin_nonce(), r);
1379+
} else if addr == bob_address {
1380+
bob_txs.insert(t.auth.get_origin_nonce(), r);
1381+
} else if addr == charlie_address {
1382+
assert!(
1383+
r.execution_cost != ExecutionCost::ZERO,
1384+
"Execution cost is not zero!"
1385+
);
1386+
charlie_txs.insert(t.auth.get_origin_nonce(), r);
13891387
}
1390-
_ => {}
13911388
}
13921389
}
13931390
}

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -930,16 +930,13 @@ fn pox_auto_unlock(alice_first: bool) {
930930
coinbase_txs.push(r);
931931
continue;
932932
}
933-
match r.transaction {
934-
TransactionOrigin::Stacks(ref t) => {
935-
let addr = t.auth.origin().address_testnet();
936-
if addr == alice_address {
937-
alice_txs.insert(t.auth.get_origin_nonce(), r);
938-
} else if addr == bob_address {
939-
bob_txs.insert(t.auth.get_origin_nonce(), r);
940-
}
933+
if let TransactionOrigin::Stacks(ref t) = r.transaction {
934+
let addr = t.auth.origin().address_testnet();
935+
if addr == alice_address {
936+
alice_txs.insert(t.auth.get_origin_nonce(), r);
937+
} else if addr == bob_address {
938+
bob_txs.insert(t.auth.get_origin_nonce(), r);
941939
}
942-
_ => {}
943940
}
944941
}
945942
}

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9184,16 +9184,13 @@ fn missed_slots_no_unlock() {
91849184
coinbase_txs.push(r);
91859185
continue;
91869186
}
9187-
match r.transaction {
9188-
TransactionOrigin::Stacks(ref t) => {
9189-
let addr = t.auth.origin().address_testnet();
9190-
if addr == alice_address {
9191-
alice_txs.insert(t.auth.get_origin_nonce(), r);
9192-
} else if addr == bob_address {
9193-
bob_txs.insert(t.auth.get_origin_nonce(), r);
9194-
}
9187+
if let TransactionOrigin::Stacks(ref t) = r.transaction {
9188+
let addr = t.auth.origin().address_testnet();
9189+
if addr == alice_address {
9190+
alice_txs.insert(t.auth.get_origin_nonce(), r);
9191+
} else if addr == bob_address {
9192+
bob_txs.insert(t.auth.get_origin_nonce(), r);
91959193
}
9196-
_ => {}
91979194
}
91989195
}
91999196
}

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11206,15 +11206,12 @@ pub mod test {
1120611206

1120711207
let (_, burn_header_hash, consensus_hash) = peer.next_burnchain_block(burn_ops.clone());
1120811208

11209-
match (stacks_block_opt, microblocks_opt) {
11210-
(Some(stacks_block), Some(microblocks)) => {
11211-
peer.process_stacks_epoch_at_tip(&stacks_block, &microblocks);
11212-
last_block_id = StacksBlockHeader::make_index_block_hash(
11213-
&consensus_hash,
11214-
&stacks_block.block_hash(),
11215-
);
11216-
}
11217-
_ => {}
11209+
if let (Some(stacks_block), Some(microblocks)) = (stacks_block_opt, microblocks_opt) {
11210+
peer.process_stacks_epoch_at_tip(&stacks_block, &microblocks);
11211+
last_block_id = StacksBlockHeader::make_index_block_hash(
11212+
&consensus_hash,
11213+
&stacks_block.block_hash(),
11214+
);
1121811215
}
1121911216

1122011217
let tip =
@@ -11889,15 +11886,12 @@ pub mod test {
1188911886

1189011887
let (_, burn_header_hash, consensus_hash) = peer.next_burnchain_block(burn_ops.clone());
1189111888

11892-
match (stacks_block_opt, microblocks_opt) {
11893-
(Some(stacks_block), Some(microblocks)) => {
11894-
peer.process_stacks_epoch_at_tip(&stacks_block, &microblocks);
11895-
last_block_id = StacksBlockHeader::make_index_block_hash(
11896-
&consensus_hash,
11897-
&stacks_block.block_hash(),
11898-
);
11899-
}
11900-
_ => {}
11889+
if let (Some(stacks_block), Some(microblocks)) = (stacks_block_opt, microblocks_opt) {
11890+
peer.process_stacks_epoch_at_tip(&stacks_block, &microblocks);
11891+
last_block_id = StacksBlockHeader::make_index_block_hash(
11892+
&consensus_hash,
11893+
&stacks_block.block_hash(),
11894+
);
1190111895
}
1190211896

1190311897
let tip =

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,11 +2746,8 @@ pub mod test {
27462746
balances: Vec<(StacksAddress, u64)>,
27472747
) -> StacksChainState {
27482748
let path = chainstate_path(test_name);
2749-
match fs::metadata(&path) {
2750-
Ok(_) => {
2751-
fs::remove_dir_all(&path).unwrap();
2752-
}
2753-
Err(_) => {}
2749+
if let Ok(_) = fs::metadata(&path) {
2750+
fs::remove_dir_all(&path).unwrap();
27542751
};
27552752

27562753
let initial_balances = balances
@@ -2866,11 +2863,8 @@ pub mod test {
28662863
};
28672864

28682865
let path = chainstate_path(function_name!());
2869-
match fs::metadata(&path) {
2870-
Ok(_) => {
2871-
fs::remove_dir_all(&path).unwrap();
2872-
}
2873-
Err(_) => {}
2866+
if let Ok(_) = fs::metadata(&path) {
2867+
fs::remove_dir_all(&path).unwrap();
28742868
};
28752869

28762870
let mut chainstate =
@@ -2956,11 +2950,8 @@ pub mod test {
29562950
};
29572951

29582952
let path = chainstate_path(function_name!());
2959-
match fs::metadata(&path) {
2960-
Ok(_) => {
2961-
fs::remove_dir_all(&path).unwrap();
2962-
}
2963-
Err(_) => {}
2953+
if let Ok(_) = fs::metadata(&path) {
2954+
fs::remove_dir_all(&path).unwrap();
29642955
};
29652956

29662957
let mut chainstate =

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,11 @@ impl<T: MarfTrieId> TrieCache<T> {
258258
TrieCache::Everything(ref mut state) => {
259259
state.store_node_and_hash(block_id, trieptr, node, hash);
260260
}
261-
TrieCache::Node256(ref mut state) => match node {
262-
TrieNodeType::Node256(data) => {
261+
TrieCache::Node256(ref mut state) => {
262+
if let TrieNodeType::Node256(data) = node {
263263
state.store_node_and_hash(block_id, trieptr, TrieNodeType::Node256(data), hash);
264264
}
265-
_ => {}
266-
},
265+
}
267266
}
268267
}
269268

@@ -273,12 +272,11 @@ impl<T: MarfTrieId> TrieCache<T> {
273272
match self {
274273
TrieCache::Noop(_) => {}
275274
TrieCache::Everything(ref mut state) => state.store_node(block_id, trieptr, node),
276-
TrieCache::Node256(ref mut state) => match node {
277-
TrieNodeType::Node256(data) => {
275+
TrieCache::Node256(ref mut state) => {
276+
if let TrieNodeType::Node256(data) = node {
278277
state.store_node(block_id, trieptr, TrieNodeType::Node256(data))
279278
}
280-
_ => {}
281-
},
279+
}
282280
}
283281
}
284282

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,8 @@ impl TrieFile {
194194
.map(|stat| Some(stat.len()))
195195
.unwrap_or(None);
196196

197-
match (size_before_opt, size_after_opt) {
198-
(Some(sz_before), Some(sz_after)) => {
199-
debug!("Shrank DB from {} to {} bytes", sz_before, sz_after);
200-
}
201-
_ => {}
197+
if let (Some(sz_before), Some(sz_after)) = (size_before_opt, size_after_opt) {
198+
debug!("Shrank DB from {} to {} bytes", sz_before, sz_after);
202199
}
203200

204201
Ok(())
@@ -461,11 +458,8 @@ impl TrieFile {
461458
self.write_all(buf)?;
462459
self.flush()?;
463460

464-
match self {
465-
TrieFile::Disk(ref mut data) => {
466-
data.fd.sync_data()?;
467-
}
468-
_ => {}
461+
if let TrieFile::Disk(ref mut data) = self {
462+
data.fd.sync_data()?;
469463
}
470464
Ok(offset)
471465
}

0 commit comments

Comments
 (0)