Skip to content

Commit

Permalink
Merge pull request #5744 from jbencin/chore/clippy-match-like-matches…
Browse files Browse the repository at this point in the history
…-macro

chore: Apply Clippy lint `match_like_matches_macro`
  • Loading branch information
obycode authored Jan 27, 2025
2 parents dd635f0 + 0c5c2c5 commit 5e11f2d
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 198 deletions.
18 changes: 3 additions & 15 deletions stackslib/src/burnchains/bitcoin/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,27 +396,15 @@ impl SegwitBitcoinAddress {
}

pub fn is_p2wpkh(&self) -> bool {
if let SegwitBitcoinAddress::P2WPKH(..) = self {
true
} else {
false
}
matches!(self, SegwitBitcoinAddress::P2WPKH(..))
}

pub fn is_p2wsh(&self) -> bool {
if let SegwitBitcoinAddress::P2WSH(..) = self {
true
} else {
false
}
matches!(self, SegwitBitcoinAddress::P2WSH(..))
}

pub fn is_p2tr(&self) -> bool {
if let SegwitBitcoinAddress::P2TR(..) = self {
true
} else {
false
}
matches!(self, SegwitBitcoinAddress::P2TR(..))
}
}

Expand Down
8 changes: 4 additions & 4 deletions stackslib/src/burnchains/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ impl BurnchainParameters {
}

pub fn is_testnet(network_id: u32) -> bool {
match network_id {
BITCOIN_NETWORK_ID_TESTNET | BITCOIN_NETWORK_ID_REGTEST => true,
_ => false,
}
matches!(
network_id,
BITCOIN_NETWORK_ID_TESTNET | BITCOIN_NETWORK_ID_REGTEST
)
}
}

Expand Down
20 changes: 4 additions & 16 deletions stackslib/src/chainstate/burn/operations/delegate_stx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,7 @@ mod tests {
&sender,
)
.unwrap_err();
assert!(match err {
op_error::ParseError => true,
_ => false,
});
assert!(matches!(err, op_error::ParseError));

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

// This test sets the op code to the op code of the StackStx
Expand Down Expand Up @@ -540,10 +534,7 @@ mod tests {
)
.unwrap_err();

assert!(match err {
op_error::InvalidInput => true,
_ => false,
});
assert!(matches!(err, op_error::InvalidInput));
}

// This test constructs a tx with zero outputs, which causes
Expand Down Expand Up @@ -576,10 +567,7 @@ mod tests {
)
.unwrap_err();

assert!(match err {
op_error::InvalidInput => true,
_ => false,
});
assert!(matches!(err, op_error::InvalidInput));
}

// Parse a normal DelegateStx op in which the reward_addr is set to output index 2.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1280,11 +1280,7 @@ mod tests {
)
.unwrap_err();

assert!(if let op_error::BlockCommitBadOutputs = err {
true
} else {
false
});
assert!(matches!(err, op_error::BlockCommitBadOutputs));

// should succeed in epoch 2.1 -- can be PoX in 2.1
let _op = LeaderBlockCommitOp::parse_from_tx(
Expand Down
10 changes: 2 additions & 8 deletions stackslib/src/chainstate/stacks/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,17 +1256,11 @@ impl TransactionAuth {
}

pub fn is_standard(&self) -> bool {
match *self {
TransactionAuth::Standard(_) => true,
_ => false,
}
matches!(self, TransactionAuth::Standard(_))
}

pub fn is_sponsored(&self) -> bool {
match *self {
TransactionAuth::Sponsored(_, _) => true,
_ => false,
}
matches!(self, TransactionAuth::Sponsored(..))
}

/// When beginning to sign a sponsored transaction, the origin account will not commit to any
Expand Down
25 changes: 5 additions & 20 deletions stackslib/src/chainstate/stacks/index/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,38 +1240,23 @@ macro_rules! with_node {

impl TrieNodeType {
pub fn is_leaf(&self) -> bool {
match self {
TrieNodeType::Leaf(_) => true,
_ => false,
}
matches!(self, TrieNodeType::Leaf(_))
}

pub fn is_node4(&self) -> bool {
match self {
TrieNodeType::Node4(_) => true,
_ => false,
}
matches!(self, TrieNodeType::Node4(_))
}

pub fn is_node16(&self) -> bool {
match self {
TrieNodeType::Node16(_) => true,
_ => false,
}
matches!(self, TrieNodeType::Node16(_))
}

pub fn is_node48(&self) -> bool {
match self {
TrieNodeType::Node48(_) => true,
_ => false,
}
matches!(self, TrieNodeType::Node48(_))
}

pub fn is_node256(&self) -> bool {
match self {
TrieNodeType::Node256(_) => true,
_ => false,
}
matches!(self, TrieNodeType::Node256(_))
}

pub fn id(&self) -> u8 {
Expand Down
10 changes: 2 additions & 8 deletions stackslib/src/chainstate/stacks/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,7 @@ impl TransactionResult {

/// Returns true iff this enum is backed by `TransactionSuccess`.
pub fn is_ok(&self) -> bool {
match &self {
TransactionResult::Success(_) => true,
_ => false,
}
matches!(self, TransactionResult::Success(_))
}

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

/// Returns true iff this enum is backed by `Error`.
pub fn is_err(&self) -> bool {
match &self {
TransactionResult::ProcessingError(_) => true,
_ => false,
}
matches!(self, TransactionResult::ProcessingError(_))
}

/// Returns an Error result as an Error.
Expand Down
10 changes: 2 additions & 8 deletions stackslib/src/chainstate/stacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,17 +461,11 @@ pub enum TransactionAuthField {

impl TransactionAuthField {
pub fn is_public_key(&self) -> bool {
match *self {
TransactionAuthField::PublicKey(_) => true,
_ => false,
}
matches!(self, TransactionAuthField::PublicKey(_))
}

pub fn is_signature(&self) -> bool {
match *self {
TransactionAuthField::Signature(_, _) => true,
_ => false,
}
matches!(self, TransactionAuthField::Signature(..))
}

pub fn as_public_key(&self) -> Option<StacksPublicKey> {
Expand Down
10 changes: 2 additions & 8 deletions stackslib/src/chainstate/stacks/tests/block_construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,20 +1277,14 @@ fn test_build_anchored_blocks_incrementing_nonces() {
// because the tx fee for each transaction increases with the nonce
for (i, tx) in stacks_block.txs.iter().enumerate() {
if i == 0 {
let okay = if let TransactionPayload::Coinbase(..) = tx.payload {
true
} else {
false
};
let okay = matches!(tx.payload, TransactionPayload::Coinbase(..));
assert!(okay, "Coinbase should be first tx");
} else {
let expected_nonce = (i - 1) % 25;
assert_eq!(
tx.get_origin_nonce(),
expected_nonce as u64,
"{}th transaction should have nonce = {}",
i,
expected_nonce
"{i}th transaction should have nonce = {expected_nonce}",
);
}
}
Expand Down
13 changes: 5 additions & 8 deletions stackslib/src/chainstate/stacks/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,10 +1030,7 @@ impl StacksTransaction {

/// Is this a mainnet transaction? false means 'testnet'
pub fn is_mainnet(&self) -> bool {
match self.version {
TransactionVersion::Mainnet => true,
_ => false,
}
self.version == TransactionVersion::Mainnet
}

/// Is this a phantom transaction?
Expand Down Expand Up @@ -3993,10 +3990,10 @@ mod test {
TransactionAuth::Standard(origin) => origin,
TransactionAuth::Sponsored(_, sponsor) => sponsor,
};
match spending_condition {
TransactionSpendingCondition::OrderIndependentMultisig(..) => true,
_ => false,
}
matches!(
spending_condition,
TransactionSpendingCondition::OrderIndependentMultisig(..)
)
}

fn check_oversign_origin_multisig(signed_tx: &StacksTransaction) {
Expand Down
Loading

0 comments on commit 5e11f2d

Please sign in to comment.