Skip to content

Commit 5e11f2d

Browse files
authored
Merge pull request #5744 from jbencin/chore/clippy-match-like-matches-macro
chore: Apply Clippy lint `match_like_matches_macro`
2 parents dd635f0 + 0c5c2c5 commit 5e11f2d

File tree

15 files changed

+59
-198
lines changed

15 files changed

+59
-198
lines changed

stackslib/src/burnchains/bitcoin/address.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -396,27 +396,15 @@ impl SegwitBitcoinAddress {
396396
}
397397

398398
pub fn is_p2wpkh(&self) -> bool {
399-
if let SegwitBitcoinAddress::P2WPKH(..) = self {
400-
true
401-
} else {
402-
false
403-
}
399+
matches!(self, SegwitBitcoinAddress::P2WPKH(..))
404400
}
405401

406402
pub fn is_p2wsh(&self) -> bool {
407-
if let SegwitBitcoinAddress::P2WSH(..) = self {
408-
true
409-
} else {
410-
false
411-
}
403+
matches!(self, SegwitBitcoinAddress::P2WSH(..))
412404
}
413405

414406
pub fn is_p2tr(&self) -> bool {
415-
if let SegwitBitcoinAddress::P2TR(..) = self {
416-
true
417-
} else {
418-
false
419-
}
407+
matches!(self, SegwitBitcoinAddress::P2TR(..))
420408
}
421409
}
422410

stackslib/src/burnchains/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ impl BurnchainParameters {
150150
}
151151

152152
pub fn is_testnet(network_id: u32) -> bool {
153-
match network_id {
154-
BITCOIN_NETWORK_ID_TESTNET | BITCOIN_NETWORK_ID_REGTEST => true,
155-
_ => false,
156-
}
153+
matches!(
154+
network_id,
155+
BITCOIN_NETWORK_ID_TESTNET | BITCOIN_NETWORK_ID_REGTEST
156+
)
157157
}
158158
}
159159

stackslib/src/chainstate/burn/operations/delegate_stx.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,7 @@ mod tests {
457457
&sender,
458458
)
459459
.unwrap_err();
460-
assert!(match err {
461-
op_error::ParseError => true,
462-
_ => false,
463-
});
460+
assert!(matches!(err, op_error::ParseError));
464461

465462
// Data is length 17. The 16th byte is set to 1, which signals that until_burn_height
466463
// is Some(u64), so the deserialize function expects another 8 bytes
@@ -496,10 +493,7 @@ mod tests {
496493
&sender,
497494
)
498495
.unwrap_err();
499-
assert!(match err {
500-
op_error::ParseError => true,
501-
_ => false,
502-
});
496+
assert!(matches!(err, op_error::ParseError));
503497
}
504498

505499
// This test sets the op code to the op code of the StackStx
@@ -540,10 +534,7 @@ mod tests {
540534
)
541535
.unwrap_err();
542536

543-
assert!(match err {
544-
op_error::InvalidInput => true,
545-
_ => false,
546-
});
537+
assert!(matches!(err, op_error::InvalidInput));
547538
}
548539

549540
// This test constructs a tx with zero outputs, which causes
@@ -576,10 +567,7 @@ mod tests {
576567
)
577568
.unwrap_err();
578569

579-
assert!(match err {
580-
op_error::InvalidInput => true,
581-
_ => false,
582-
});
570+
assert!(matches!(err, op_error::InvalidInput));
583571
}
584572

585573
// Parse a normal DelegateStx op in which the reward_addr is set to output index 2.

stackslib/src/chainstate/burn/operations/leader_block_commit.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,11 +1280,7 @@ mod tests {
12801280
)
12811281
.unwrap_err();
12821282

1283-
assert!(if let op_error::BlockCommitBadOutputs = err {
1284-
true
1285-
} else {
1286-
false
1287-
});
1283+
assert!(matches!(err, op_error::BlockCommitBadOutputs));
12881284

12891285
// should succeed in epoch 2.1 -- can be PoX in 2.1
12901286
let _op = LeaderBlockCommitOp::parse_from_tx(

stackslib/src/chainstate/stacks/auth.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,17 +1256,11 @@ impl TransactionAuth {
12561256
}
12571257

12581258
pub fn is_standard(&self) -> bool {
1259-
match *self {
1260-
TransactionAuth::Standard(_) => true,
1261-
_ => false,
1262-
}
1259+
matches!(self, TransactionAuth::Standard(_))
12631260
}
12641261

12651262
pub fn is_sponsored(&self) -> bool {
1266-
match *self {
1267-
TransactionAuth::Sponsored(_, _) => true,
1268-
_ => false,
1269-
}
1263+
matches!(self, TransactionAuth::Sponsored(..))
12701264
}
12711265

12721266
/// When beginning to sign a sponsored transaction, the origin account will not commit to any

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,38 +1240,23 @@ macro_rules! with_node {
12401240

12411241
impl TrieNodeType {
12421242
pub fn is_leaf(&self) -> bool {
1243-
match self {
1244-
TrieNodeType::Leaf(_) => true,
1245-
_ => false,
1246-
}
1243+
matches!(self, TrieNodeType::Leaf(_))
12471244
}
12481245

12491246
pub fn is_node4(&self) -> bool {
1250-
match self {
1251-
TrieNodeType::Node4(_) => true,
1252-
_ => false,
1253-
}
1247+
matches!(self, TrieNodeType::Node4(_))
12541248
}
12551249

12561250
pub fn is_node16(&self) -> bool {
1257-
match self {
1258-
TrieNodeType::Node16(_) => true,
1259-
_ => false,
1260-
}
1251+
matches!(self, TrieNodeType::Node16(_))
12611252
}
12621253

12631254
pub fn is_node48(&self) -> bool {
1264-
match self {
1265-
TrieNodeType::Node48(_) => true,
1266-
_ => false,
1267-
}
1255+
matches!(self, TrieNodeType::Node48(_))
12681256
}
12691257

12701258
pub fn is_node256(&self) -> bool {
1271-
match self {
1272-
TrieNodeType::Node256(_) => true,
1273-
_ => false,
1274-
}
1259+
matches!(self, TrieNodeType::Node256(_))
12751260
}
12761261

12771262
pub fn id(&self) -> u8 {

stackslib/src/chainstate/stacks/miner.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,7 @@ impl TransactionResult {
551551

552552
/// Returns true iff this enum is backed by `TransactionSuccess`.
553553
pub fn is_ok(&self) -> bool {
554-
match &self {
555-
TransactionResult::Success(_) => true,
556-
_ => false,
557-
}
554+
matches!(self, TransactionResult::Success(_))
558555
}
559556

560557
/// Returns a TransactionSuccess result as a pair of 1) fee and 2) receipt.
@@ -568,10 +565,7 @@ impl TransactionResult {
568565

569566
/// Returns true iff this enum is backed by `Error`.
570567
pub fn is_err(&self) -> bool {
571-
match &self {
572-
TransactionResult::ProcessingError(_) => true,
573-
_ => false,
574-
}
568+
matches!(self, TransactionResult::ProcessingError(_))
575569
}
576570

577571
/// Returns an Error result as an Error.

stackslib/src/chainstate/stacks/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -461,17 +461,11 @@ pub enum TransactionAuthField {
461461

462462
impl TransactionAuthField {
463463
pub fn is_public_key(&self) -> bool {
464-
match *self {
465-
TransactionAuthField::PublicKey(_) => true,
466-
_ => false,
467-
}
464+
matches!(self, TransactionAuthField::PublicKey(_))
468465
}
469466

470467
pub fn is_signature(&self) -> bool {
471-
match *self {
472-
TransactionAuthField::Signature(_, _) => true,
473-
_ => false,
474-
}
468+
matches!(self, TransactionAuthField::Signature(..))
475469
}
476470

477471
pub fn as_public_key(&self) -> Option<StacksPublicKey> {

stackslib/src/chainstate/stacks/tests/block_construction.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,20 +1277,14 @@ fn test_build_anchored_blocks_incrementing_nonces() {
12771277
// because the tx fee for each transaction increases with the nonce
12781278
for (i, tx) in stacks_block.txs.iter().enumerate() {
12791279
if i == 0 {
1280-
let okay = if let TransactionPayload::Coinbase(..) = tx.payload {
1281-
true
1282-
} else {
1283-
false
1284-
};
1280+
let okay = matches!(tx.payload, TransactionPayload::Coinbase(..));
12851281
assert!(okay, "Coinbase should be first tx");
12861282
} else {
12871283
let expected_nonce = (i - 1) % 25;
12881284
assert_eq!(
12891285
tx.get_origin_nonce(),
12901286
expected_nonce as u64,
1291-
"{}th transaction should have nonce = {}",
1292-
i,
1293-
expected_nonce
1287+
"{i}th transaction should have nonce = {expected_nonce}",
12941288
);
12951289
}
12961290
}

stackslib/src/chainstate/stacks/transaction.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,10 +1030,7 @@ impl StacksTransaction {
10301030

10311031
/// Is this a mainnet transaction? false means 'testnet'
10321032
pub fn is_mainnet(&self) -> bool {
1033-
match self.version {
1034-
TransactionVersion::Mainnet => true,
1035-
_ => false,
1036-
}
1033+
self.version == TransactionVersion::Mainnet
10371034
}
10381035

10391036
/// Is this a phantom transaction?
@@ -3993,10 +3990,10 @@ mod test {
39933990
TransactionAuth::Standard(origin) => origin,
39943991
TransactionAuth::Sponsored(_, sponsor) => sponsor,
39953992
};
3996-
match spending_condition {
3997-
TransactionSpendingCondition::OrderIndependentMultisig(..) => true,
3998-
_ => false,
3999-
}
3993+
matches!(
3994+
spending_condition,
3995+
TransactionSpendingCondition::OrderIndependentMultisig(..)
3996+
)
40003997
}
40013998

40023999
fn check_oversign_origin_multisig(signed_tx: &StacksTransaction) {

0 commit comments

Comments
 (0)