Skip to content

Commit ea79fdc

Browse files
authored
Merge pull request #5773 from jbencin/chore/clippy-derivable-impls-eq-op-expect-fun-call
chore: Apply Clippy lints `derivable_impls`, `eq_op`, and `expect_fun_call`
2 parents a7c1178 + 887a05d commit ea79fdc

File tree

13 files changed

+58
-114
lines changed

13 files changed

+58
-114
lines changed

stackslib/src/burnchains/bitcoin/indexer.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,7 @@ impl BitcoinIndexer {
234234
true,
235235
false,
236236
)
237-
.expect(&format!(
238-
"Failed to open {:?}",
239-
working_dir_path.to_str().unwrap()
240-
));
237+
.unwrap_or_else(|_| panic!("Failed to open {working_dir_path:?}"));
241238

242239
BitcoinIndexer {
243240
config: BitcoinIndexerConfig::default_regtest(

stackslib/src/burnchains/tests/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,7 @@ impl TestBurnchainBlock {
439439
// prove on the last-ever sortition's hash to produce the new seed
440440
let proof = miner
441441
.make_proof(&leader_key.public_key, &last_snapshot.sortition_hash)
442-
.expect(&format!(
443-
"FATAL: no private key for {}",
444-
leader_key.public_key.to_hex()
445-
));
442+
.unwrap_or_else(|| panic!("FATAL: no private key for {:?}", leader_key.public_key));
446443

447444
VRFSeed::from_proof(&proof)
448445
});
@@ -655,10 +652,12 @@ impl TestBurnchainBlock {
655652
let parent_hdr = indexer
656653
.read_burnchain_header(self.block_height.saturating_sub(1))
657654
.unwrap()
658-
.expect(&format!(
659-
"BUG: could not read block at height {}",
660-
self.block_height.saturating_sub(1)
661-
));
655+
.unwrap_or_else(|| {
656+
panic!(
657+
"BUG: could not read block at height {}",
658+
self.block_height.saturating_sub(1)
659+
)
660+
});
662661

663662
let now = BURNCHAIN_TEST_BLOCK_TIME;
664663
let block_hash = BurnchainHeaderHash::from_bitcoin_hash(

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ impl TestPeer<'_> {
13441344
);
13451345
}
13461346
Err(e) => {
1347-
panic!("Failure fetching recipient set: {:?}", e);
1347+
panic!("Failure fetching recipient set: {e:?}");
13481348
}
13491349
};
13501350

@@ -1368,16 +1368,11 @@ impl TestPeer<'_> {
13681368
let proof = self
13691369
.miner
13701370
.make_proof(&miner_key.public_key, &tip.sortition_hash)
1371-
.expect(&format!(
1372-
"FATAL: no private key for {}",
1373-
miner_key.public_key.to_hex()
1374-
));
1371+
.unwrap_or_else(|| panic!("FATAL: no private key for {:?}", miner_key.public_key));
13751372
self.sortdb = Some(sortdb);
13761373
debug!(
1377-
"VRF proof made from {} over {}: {}",
1378-
&miner_key.public_key.to_hex(),
1379-
&tip.sortition_hash,
1380-
&proof.to_hex()
1374+
"VRF proof made from {:?} over {}: {proof:?}",
1375+
miner_key.public_key, &tip.sortition_hash
13811376
);
13821377
proof
13831378
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,7 @@ pub fn check_stacking_state_invariants(
334334
.burn_header_height;
335335

336336
let stacking_state_entry = get_stacking_state_pox(peer, tip, stacker, active_pox_contract)
337-
.expect(&format!(
338-
"Invariant violated: reward-cycle entry has stacker field set, but not present in stacker-state (pox_contract = {})",
339-
active_pox_contract,
340-
))
337+
.unwrap_or_else(|| panic!("Invariant violated: reward-cycle entry has stacker field set, but not present in stacker-state (pox_contract = {active_pox_contract})"))
341338
.expect_tuple().unwrap();
342339
let first_cycle = stacking_state_entry
343340
.get("first-reward-cycle")

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8353,9 +8353,9 @@ fn test_scenario_three(use_nakamoto: bool) {
83538353
assert_eq!(amount_locked_actual, amount_locked_expected);
83548354

83558355
// Check Bob signer key
8356-
let signer_key_expected = Value::buff_from(bob.public_key.to_bytes_compressed());
8356+
let signer_key_expected = Value::buff_from(bob.public_key.to_bytes_compressed()).unwrap();
83578357
let signer_key_actual = bob_stack_tx_ok.data_map.get("signer-key").unwrap().clone();
8358-
assert_eq!(signer_key_actual, signer_key_actual);
8358+
assert_eq!(signer_key_actual, signer_key_expected);
83598359

83608360
// 5. Check that David can't delegate-stack-stx Eve if delegation expires during lock period
83618361
let eve_delegate_stx_to_david_err = receipts
@@ -10262,7 +10262,7 @@ fn test_scenario_five(use_nakamoto: bool) {
1026210262
for (idx, (stacker, stacker_lock_period)) in davids_stackers.iter().enumerate() {
1026310263
let (pox_address, first_reward_cycle, lock_period, _indices) =
1026410264
get_stacker_info_pox_4(&mut peer, &stacker.principal)
10265-
.expect(format!("Failed to find stacker {}", idx).as_str());
10265+
.unwrap_or_else(|| panic!("Failed to find stacker {idx}"));
1026610266
assert_eq!(first_reward_cycle, reward_cycle);
1026710267
assert_eq!(pox_address, david.pox_address);
1026810268
assert_eq!(lock_period, *stacker_lock_period);
@@ -10271,7 +10271,7 @@ fn test_scenario_five(use_nakamoto: bool) {
1027110271
for (idx, (stacker, stacker_lock_period)) in eves_stackers.iter().enumerate() {
1027210272
let (pox_address, first_reward_cycle, lock_period, _indices) =
1027310273
get_stacker_info_pox_4(&mut peer, &stacker.principal)
10274-
.expect(format!("Failed to find stacker {}", idx).as_str());
10274+
.unwrap_or_else(|| panic!("Failed to find stacker {idx}"));
1027510275
assert_eq!(first_reward_cycle, reward_cycle);
1027610276
assert_eq!(pox_address, eve.pox_address);
1027710277
assert_eq!(lock_period, *stacker_lock_period);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,7 @@ impl TestStacksNode {
609609
&miner_key.public_key,
610610
&burn_block.parent_snapshot.sortition_hash,
611611
)
612-
.expect(&format!(
613-
"FATAL: no private key for {}",
614-
miner_key.public_key.to_hex()
615-
));
612+
.unwrap_or_else(|| panic!("FATAL: no private key for {:?}", miner_key.public_key));
616613

617614
let (builder, parent_block_snapshot_opt) = match parent_stacks_block {
618615
None => {

stackslib/src/config/mod.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,40 +1691,25 @@ pub struct NodeConfig {
16911691
pub stacker_dbs: Vec<QualifiedContractIdentifier>,
16921692
}
16931693

1694-
#[derive(Clone, Debug)]
1694+
#[derive(Clone, Debug, Default)]
16951695
pub enum CostEstimatorName {
1696+
#[default]
16961697
NaivePessimistic,
16971698
}
16981699

1699-
#[derive(Clone, Debug)]
1700+
#[derive(Clone, Debug, Default)]
17001701
pub enum FeeEstimatorName {
1702+
#[default]
17011703
ScalarFeeRate,
17021704
FuzzedWeightedMedianFeeRate,
17031705
}
17041706

1705-
#[derive(Clone, Debug)]
1707+
#[derive(Clone, Debug, Default)]
17061708
pub enum CostMetricName {
1709+
#[default]
17071710
ProportionDotProduct,
17081711
}
17091712

1710-
impl Default for CostEstimatorName {
1711-
fn default() -> Self {
1712-
CostEstimatorName::NaivePessimistic
1713-
}
1714-
}
1715-
1716-
impl Default for FeeEstimatorName {
1717-
fn default() -> Self {
1718-
FeeEstimatorName::ScalarFeeRate
1719-
}
1720-
}
1721-
1722-
impl Default for CostMetricName {
1723-
fn default() -> Self {
1724-
CostMetricName::ProportionDotProduct
1725-
}
1726-
}
1727-
17281713
impl CostEstimatorName {
17291714
fn panic_parse(s: String) -> CostEstimatorName {
17301715
if &s.to_lowercase() == "naive_pessimistic" {

stackslib/src/net/chat.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,12 @@ use crate::net::{
5252
use crate::util_lib::db::{DBConn, Error as db_error};
5353

5454
// did we or did we not successfully send a message?
55-
#[derive(Debug, Clone)]
55+
#[derive(Debug, Clone, Default)]
5656
pub struct NeighborHealthPoint {
5757
pub success: bool,
5858
pub time: u64,
5959
}
6060

61-
impl Default for NeighborHealthPoint {
62-
fn default() -> NeighborHealthPoint {
63-
NeighborHealthPoint {
64-
success: false,
65-
time: 0,
66-
}
67-
}
68-
}
69-
7061
pub const NUM_HEALTH_POINTS: usize = 32;
7162
pub const HEALTH_POINT_LIFETIME: u64 = 12 * 3600; // 12 hours
7263

stackslib/src/net/download/nakamoto/tenure.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,12 @@ impl TenureStartEnd {
345345
rc,
346346
pox_constants
347347
.block_height_to_reward_cycle(first_burn_height, wt_start.burn_height)
348-
.expect(&format!(
349-
"FATAL: tenure from before system start ({} <= {})",
350-
wt_start.burn_height, first_burn_height
351-
)),
348+
.unwrap_or_else(|| {
349+
panic!(
350+
"FATAL: tenure from before system start ({} <= {first_burn_height})",
351+
wt_start.burn_height
352+
)
353+
}),
352354
wt.processed,
353355
);
354356
tenure_start_end.fetch_end_block = true;

stackslib/src/net/httpcore.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,10 +1014,9 @@ impl StacksHttp {
10141014
pub fn set_response_handler(&mut self, request_verb: &str, request_path: &str) {
10151015
let handler_index = self
10161016
.find_response_handler(request_verb, request_path)
1017-
.expect(&format!(
1018-
"FATAL: could not find handler for '{}' '{}'",
1019-
request_verb, request_path
1020-
));
1017+
.unwrap_or_else(|| {
1018+
panic!("FATAL: could not find handler for '{request_verb}' '{request_path}'")
1019+
});
10211020
self.request_handler_index = Some(handler_index);
10221021
}
10231022

stackslib/src/net/mod.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4384,18 +4384,15 @@ pub mod test {
43844384
let mut stacks_node = self.stacks_node.take().unwrap();
43854385

43864386
let parent_block_opt = stacks_node.get_last_anchored_block(&self.miner);
4387-
let parent_sortition_opt = match parent_block_opt.as_ref() {
4388-
Some(parent_block) => {
4389-
let ic = sortdb.index_conn();
4390-
SortitionDB::get_block_snapshot_for_winning_stacks_block(
4391-
&ic,
4392-
&tip.sortition_id,
4393-
&parent_block.block_hash(),
4394-
)
4395-
.unwrap()
4396-
}
4397-
None => None,
4398-
};
4387+
let parent_sortition_opt = parent_block_opt.as_ref().and_then(|parent_block| {
4388+
let ic = sortdb.index_conn();
4389+
SortitionDB::get_block_snapshot_for_winning_stacks_block(
4390+
&ic,
4391+
&tip.sortition_id,
4392+
&parent_block.block_hash(),
4393+
)
4394+
.unwrap()
4395+
});
43994396

44004397
let parent_microblock_header_opt =
44014398
get_last_microblock_header(&stacks_node, &self.miner, parent_block_opt.as_ref());
@@ -4411,10 +4408,7 @@ pub mod test {
44114408
&last_key.public_key,
44124409
&burn_block.parent_snapshot.sortition_hash,
44134410
)
4414-
.expect(&format!(
4415-
"FATAL: no private key for {}",
4416-
last_key.public_key.to_hex()
4417-
));
4411+
.unwrap_or_else(|| panic!("FATAL: no private key for {:?}", last_key.public_key));
44184412

44194413
let (stacks_block, microblocks) = tenure_builder(
44204414
&mut self.miner,
@@ -4674,10 +4668,9 @@ pub mod test {
46744668
self.config
46754669
.burnchain
46764670
.block_height_to_reward_cycle(block_height)
4677-
.expect(&format!(
4678-
"Failed to get reward cycle for block height {}",
4679-
block_height
4680-
))
4671+
.unwrap_or_else(|| {
4672+
panic!("Failed to get reward cycle for block height {block_height}")
4673+
})
46814674
}
46824675

46834676
/// Verify that the sortition DB migration into Nakamoto worked correctly.

stackslib/src/net/stackerdb/tests/config.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,25 +525,24 @@ fn test_valid_and_invalid_stackerdb_configs() {
525525
)
526526
.unwrap()
527527
.into(),
528-
ContractName::try_from(format!("test-{}", i)).unwrap(),
528+
ContractName::try_from(format!("test-{i}")).unwrap(),
529529
);
530530
peer.with_db_state(|sortdb, chainstate, _, _| {
531531
match StackerDBConfig::from_smart_contract(chainstate, sortdb, &contract_id, 32, None) {
532532
Ok(config) => {
533533
let expected = result
534534
.clone()
535-
.expect(&format!("FATAL: parsed a bad contract\n{}", code));
535+
.unwrap_or_else(|| panic!("FATAL: parsed a bad contract\n{code}"));
536536
assert_eq!(config, expected);
537537
}
538538
Err(net_error::InvalidStackerDBContract(..)) => {
539539
assert!(
540540
result.is_none(),
541-
"FATAL: valid contract treated as invalid\n{}",
542-
code
541+
"FATAL: valid contract treated as invalid\n{code}"
543542
);
544543
}
545544
Err(e) => {
546-
panic!("Unexpected error: {:?}", &e);
545+
panic!("Unexpected error: {e:?}");
547546
}
548547
}
549548
Ok(())

stackslib/src/net/tests/download/nakamoto.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,11 +1221,7 @@ fn test_tenure_start_end_from_inventory() {
12211221
// no tenure here
12221222
assert!(
12231223
tenure_start_end_opt.is_none(),
1224-
"{}",
1225-
format!(
1226-
"tenure_start_end = {:?}, rc = {}, i = {}, wt = {:?}",
1227-
&tenure_start_end_opt, rc, i, &wt
1228-
)
1224+
"tenure_start_end = {tenure_start_end_opt:?}, rc = {rc}, i = {i}, wt = {wt:?}"
12291225
);
12301226
}
12311227
}
@@ -1262,7 +1258,7 @@ fn test_tenure_start_end_from_inventory() {
12621258
let tenure_start_end_opt = available.get(&wt.tenure_id_consensus_hash);
12631259
if bits
12641260
.get(i as u16)
1265-
.expect(&format!("failed to get bit {}: {:?}", i, &wt))
1261+
.unwrap_or_else(|| panic!("failed to get bit {i}: {wt:?}"))
12661262
{
12671263
// this sortition had a tenure
12681264
let mut j = (i + 1) as u16;
@@ -1288,13 +1284,11 @@ fn test_tenure_start_end_from_inventory() {
12881284

12891285
if tenure_start_index.is_some() && tenure_end_index.is_some() {
12901286
debug!(
1291-
"rc = {}, i = {}, tenure_start_index = {:?}, tenure_end_index = {:?}",
1292-
rc, i, &tenure_start_index, &tenure_end_index
1287+
"rc = {rc}, i = {i}, tenure_start_index = {tenure_start_index:?}, tenure_end_index = {tenure_end_index:?}"
12931288
);
1294-
let tenure_start_end = tenure_start_end_opt.expect(&format!(
1295-
"failed to get tenure_start_end_opt: i = {}, wt = {:?}",
1296-
i, &wt
1297-
));
1289+
let tenure_start_end = tenure_start_end_opt.unwrap_or_else(|| {
1290+
panic!("failed to get tenure_start_end_opt: i = {i}, wt = {wt:?}")
1291+
});
12981292
assert_eq!(
12991293
all_tenures[tenure_start_index.unwrap() as usize].winning_block_id,
13001294
tenure_start_end.start_block_id
@@ -1310,11 +1304,7 @@ fn test_tenure_start_end_from_inventory() {
13101304
// no tenure here
13111305
assert!(
13121306
tenure_start_end_opt.is_none(),
1313-
"{}",
1314-
format!(
1315-
"tenure_start_end = {:?}, rc = {}, i = {}, wt = {:?}",
1316-
&tenure_start_end_opt, rc, i, &wt
1317-
)
1307+
"tenure_start_end = {tenure_start_end_opt:?}, rc = {rc}, i = {i}, wt = {wt:?}"
13181308
);
13191309
}
13201310
}

0 commit comments

Comments
 (0)