Skip to content

Commit 38e73f3

Browse files
committed
Fix clippy::useless_conversions throughout stacks core
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 11823df commit 38e73f3

File tree

28 files changed

+100
-134
lines changed

28 files changed

+100
-134
lines changed

stackslib/src/burnchains/bitcoin/bits.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,7 @@ impl BitcoinTxInputStructured {
223223
Instruction::Op(btc_opcodes::OP_CHECKMULTISIG),
224224
) => {
225225
// op1 and op2 must be integers
226-
match (
227-
btc_opcodes::from(*op1).classify(),
228-
btc_opcodes::from(*op2).classify(),
229-
) {
226+
match (op1.classify(), op2.classify()) {
230227
(Class::PushNum(num_sigs), Class::PushNum(num_pubkeys)) => {
231228
// the "#instructions - 3" comes from the OP_m, OP_n, and OP_CHECKMULTISIG
232229
if num_sigs < 1

stackslib/src/burnchains/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ impl PoxConstants {
629629
// TODO: I *think* the logic of `== 0` here requires some further digging.
630630
// `mod 0` may not have any rewards, but it does not behave like "prepare phase" blocks:
631631
// is it already a member of reward cycle "N" where N = block_height / reward_cycle_len
632-
reward_index == 0 || reward_index > u64::from(reward_cycle_length - prepare_length)
632+
reward_index == 0 || reward_index > reward_cycle_length - prepare_length
633633
}
634634
}
635635

@@ -658,7 +658,7 @@ impl PoxConstants {
658658
} else {
659659
let effective_height = block_height - first_block_height;
660660
let reward_index = effective_height % reward_cycle_length;
661-
reward_index > u64::from(reward_cycle_length - prepare_length)
661+
reward_index > reward_cycle_length - prepare_length
662662
}
663663
}
664664

stackslib/src/burnchains/tests/db.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,38 +1316,30 @@ fn test_classify_delegate_stx() {
13161316
"Only one delegate_stx op should have been accepted"
13171317
);
13181318

1319-
let expected_pre_delegate_addr = StacksAddress::from_legacy_bitcoin_address(
1320-
&LegacyBitcoinAddress {
1319+
let expected_pre_delegate_addr =
1320+
StacksAddress::from_legacy_bitcoin_address(&LegacyBitcoinAddress {
13211321
addrtype: LegacyBitcoinAddressType::PublicKeyHash,
13221322
network_id: BitcoinNetworkType::Mainnet,
13231323
bytes: Hash160([1; 20]),
1324-
}
1325-
.into(),
1326-
);
1324+
});
13271325

13281326
let expected_delegate_addr = PoxAddress::Standard(
1329-
StacksAddress::from_legacy_bitcoin_address(
1330-
&LegacyBitcoinAddress {
1331-
addrtype: LegacyBitcoinAddressType::PublicKeyHash,
1332-
network_id: BitcoinNetworkType::Mainnet,
1333-
bytes: Hash160([2; 20]),
1334-
}
1335-
.into(),
1336-
),
1327+
StacksAddress::from_legacy_bitcoin_address(&LegacyBitcoinAddress {
1328+
addrtype: LegacyBitcoinAddressType::PublicKeyHash,
1329+
network_id: BitcoinNetworkType::Mainnet,
1330+
bytes: Hash160([2; 20]),
1331+
}),
13371332
Some(AddressHashMode::SerializeP2PKH),
13381333
);
13391334

13401335
let expected_reward_addr = Some((
13411336
1,
13421337
PoxAddress::Standard(
1343-
StacksAddress::from_legacy_bitcoin_address(
1344-
&LegacyBitcoinAddress {
1345-
addrtype: LegacyBitcoinAddressType::PublicKeyHash,
1346-
network_id: BitcoinNetworkType::Mainnet,
1347-
bytes: Hash160([1; 20]),
1348-
}
1349-
.into(),
1350-
),
1338+
StacksAddress::from_legacy_bitcoin_address(&LegacyBitcoinAddress {
1339+
addrtype: LegacyBitcoinAddressType::PublicKeyHash,
1340+
network_id: BitcoinNetworkType::Mainnet,
1341+
bytes: Hash160([1; 20]),
1342+
}),
13511343
Some(AddressHashMode::SerializeP2PKH),
13521344
),
13531345
));

stackslib/src/chainstate/coordinator/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,8 +1237,8 @@ impl<
12371237
continue;
12381238
}
12391239
Err(e) => {
1240-
error!("Failed to query affirmation map: {:?}", &e);
1241-
return Err(e.into());
1240+
error!("Failed to query affirmation map: {e:?}");
1241+
return Err(e);
12421242
}
12431243
};
12441244

stackslib/src/chainstate/coordinator/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4741,7 +4741,7 @@ fn atlas_stop_start() {
47414741
TransactionVersion::Testnet,
47424742
TransactionAuth::from_p2pkh(&signer_sk).unwrap(),
47434743
TransactionPayload::ContractCall(TransactionContractCall {
4744-
address: signer_pk.clone().into(),
4744+
address: signer_pk.clone(),
47454745
contract_name: atlas_name.clone(),
47464746
function_name: "make-attach".into(),
47474747
function_args: vec![Value::buff_from(vec![ix; 20]).unwrap()],

stackslib/src/chainstate/nakamoto/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4515,7 +4515,7 @@ impl NakamotoChainState {
45154515
Ok((block_fees, _block_burns, txs_receipts)) => (block_fees, txs_receipts),
45164516
};
45174517

4518-
tx_receipts.extend(txs_receipts.into_iter());
4518+
tx_receipts.extend(txs_receipts);
45194519

45204520
let total_tenure_cost = clarity_tx.cost_so_far();
45214521
let mut block_execution_cost = total_tenure_cost.clone();
@@ -4659,10 +4659,8 @@ impl NakamotoChainState {
46594659
let new_block_id = new_tip.index_block_hash();
46604660
chainstate_tx.log_transactions_processed(&new_block_id, &tx_receipts);
46614661

4662-
let reward_cycle = pox_constants.block_height_to_reward_cycle(
4663-
first_block_height.into(),
4664-
chain_tip_burn_header_height.into(),
4665-
);
4662+
let reward_cycle = pox_constants
4663+
.block_height_to_reward_cycle(first_block_height, chain_tip_burn_header_height.into());
46664664

46674665
// store the reward set calculated during this block if it happened
46684666
// NOTE: miner and proposal evaluation should not invoke this because
@@ -4673,14 +4671,14 @@ impl NakamotoChainState {
46734671
Self::write_reward_set(chainstate_tx, &new_block_id, &signer_calculation.reward_set)?;
46744672

46754673
let cycle_number = if let Some(cycle) = pox_constants.reward_cycle_of_prepare_phase(
4676-
first_block_height.into(),
4674+
first_block_height,
46774675
chain_tip_burn_header_height.into(),
46784676
) {
46794677
Some(cycle)
46804678
} else {
46814679
pox_constants
46824680
.block_height_to_reward_cycle(
4683-
first_block_height.into(),
4681+
first_block_height,
46844682
chain_tip_burn_header_height.into(),
46854683
)
46864684
.map(|cycle| cycle + 1)

stackslib/src/chainstate/nakamoto/shadow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,17 +901,17 @@ pub fn process_shadow_block(
901901
) {
902902
Ok(receipt_opt) => receipt_opt,
903903
Err(ChainstateError::InvalidStacksBlock(msg)) => {
904-
warn!("Encountered invalid block: {}", &msg);
904+
warn!("Encountered invalid block: {msg}");
905905
continue;
906906
}
907907
Err(ChainstateError::NetError(NetError::DeserializeError(msg))) => {
908908
// happens if we load a zero-sized block (i.e. an invalid block)
909-
warn!("Encountered invalid block (codec error): {}", &msg);
909+
warn!("Encountered invalid block (codec error): {msg}");
910910
continue;
911911
}
912912
Err(e) => {
913913
// something else happened
914-
return Err(e.into());
914+
return Err(e);
915915
}
916916
};
917917

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ impl TestStacksNode {
10071007
}
10081008
Ok(blocks
10091009
.into_iter()
1010-
.zip(all_malleablized_blocks.into_iter())
1010+
.zip(all_malleablized_blocks)
10111011
.map(|((blk, sz, cost), mals)| (blk, sz, cost, mals))
10121012
.collect())
10131013
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,6 @@ fn test_deploy_smart_contract(
17891789
// test that the maximum stackerdb list size will fit in a value
17901790
fn max_stackerdb_list() {
17911791
let signers_list: Vec<_> = (0..SIGNERS_MAX_LIST_SIZE)
1792-
.into_iter()
17931792
.map(|signer_ix| {
17941793
let signer_address = StacksAddress {
17951794
version: 0,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ impl StacksChainState {
908908
) -> u128 {
909909
// set the lower limit on reward scaling at 25% of liquid_ustx
910910
// (i.e., liquid_ustx / POX_MAXIMAL_SCALING)
911-
let scale_by = cmp::max(participation, liquid_ustx / u128::from(POX_MAXIMAL_SCALING));
911+
let scale_by = cmp::max(participation, liquid_ustx / POX_MAXIMAL_SCALING);
912912
let threshold_precise = scale_by / reward_slots;
913913
// compute the threshold as nearest 10k > threshold_precise
914914
let ceil_amount = match threshold_precise % POX_THRESHOLD_STEPS_USTX {
@@ -935,7 +935,7 @@ impl StacksChainState {
935935

936936
// set the lower limit on reward scaling at 25% of liquid_ustx
937937
// (i.e., liquid_ustx / POX_MAXIMAL_SCALING)
938-
let scale_by = cmp::max(participation, liquid_ustx / u128::from(POX_MAXIMAL_SCALING));
938+
let scale_by = cmp::max(participation, liquid_ustx / POX_MAXIMAL_SCALING);
939939

940940
let reward_slots = u128::try_from(pox_settings.reward_slots())
941941
.expect("FATAL: unreachable: more than 2^128 reward slots");
@@ -2911,7 +2911,7 @@ pub mod test {
29112911
let alice = StacksAddress::from_string("STVK1K405H6SK9NKJAP32GHYHDJ98MMNP8Y6Z9N0").unwrap();
29122912
let bob = StacksAddress::from_string("ST76D2FMXZ7D2719PNE4N71KPSX84XCCNCMYC940").unwrap();
29132913
peer_config.initial_lockups = vec![
2914-
ChainstateAccountLockup::new(alice.into(), 1000, 1),
2914+
ChainstateAccountLockup::new(alice, 1000, 1),
29152915
ChainstateAccountLockup::new(bob, 1000, 1),
29162916
ChainstateAccountLockup::new(alice, 1000, 2),
29172917
ChainstateAccountLockup::new(bob, 1000, 3),
@@ -5498,7 +5498,7 @@ pub mod test {
54985498
// alice did _NOT_ spend
54995499
assert!(get_contract(
55005500
&mut peer,
5501-
&make_contract_id(&key_to_stacks_addr(&alice), "alice-try-spend").into(),
5501+
&make_contract_id(&key_to_stacks_addr(&alice), "alice-try-spend"),
55025502
)
55035503
.is_none());
55045504
}

0 commit comments

Comments
 (0)