Skip to content

Commit 8c23c0e

Browse files
authored
Merge pull request #5628 from stacks-network/fix/clippy-ci-stacks-lib-len-zero
Fix string to empty string comparison and len zero warnings
2 parents 9802763 + 06f4f93 commit 8c23c0e

Some content is hidden

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

82 files changed

+390
-388
lines changed

stackslib/src/blockstack_cli.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ fn handle_contract_publish(
375375
) -> Result<String, CliError> {
376376
let mut args = args_slice.to_vec();
377377

378-
if args.len() >= 1 && args[0] == "-h" {
378+
if !args.is_empty() && args[0] == "-h" {
379379
return Err(CliError::Message(format!("USAGE:\n {}", PUBLISH_USAGE)));
380380
}
381381
if args.len() != 5 {
@@ -433,7 +433,7 @@ fn handle_contract_call(
433433
clarity_version: ClarityVersion,
434434
) -> Result<String, CliError> {
435435
let mut args = args_slice.to_vec();
436-
if args.len() >= 1 && args[0] == "-h" {
436+
if !args.is_empty() && args[0] == "-h" {
437437
return Err(CliError::Message(format!("USAGE:\n {}", CALL_USAGE)));
438438
}
439439
if args.len() < 6 {
@@ -518,7 +518,7 @@ fn handle_token_transfer(
518518
chain_id: u32,
519519
) -> Result<String, CliError> {
520520
let mut args = args_slice.to_vec();
521-
if args.len() >= 1 && args[0] == "-h" {
521+
if !args.is_empty() && args[0] == "-h" {
522522
return Err(CliError::Message(format!(
523523
"USAGE:\n {}",
524524
TOKEN_TRANSFER_USAGE
@@ -575,7 +575,7 @@ fn handle_token_transfer(
575575
}
576576

577577
fn generate_secret_key(args: &[String], version: TransactionVersion) -> Result<String, CliError> {
578-
if args.len() >= 1 && args[0] == "-h" {
578+
if !args.is_empty() && args[0] == "-h" {
579579
return Err(CliError::Message(format!("USAGE:\n {}", GENERATE_USAGE)));
580580
}
581581

@@ -606,7 +606,7 @@ fn generate_secret_key(args: &[String], version: TransactionVersion) -> Result<S
606606
}
607607

608608
fn get_addresses(args: &[String], version: TransactionVersion) -> Result<String, CliError> {
609-
if (args.len() >= 1 && args[0] == "-h") || args.len() != 1 {
609+
if (!args.is_empty() && args[0] == "-h") || args.len() != 1 {
610610
return Err(CliError::Message(format!("USAGE:\n {}", ADDRESSES_USAGE)));
611611
}
612612

@@ -645,7 +645,7 @@ fn get_addresses(args: &[String], version: TransactionVersion) -> Result<String,
645645
}
646646

647647
fn decode_transaction(args: &[String], _version: TransactionVersion) -> Result<String, CliError> {
648-
if (args.len() >= 1 && args[0] == "-h") || args.len() != 1 {
648+
if (!args.is_empty() && args[0] == "-h") || args.len() != 1 {
649649
return Err(CliError::Message(format!(
650650
"Usage: {}\n",
651651
DECODE_TRANSACTION_USAGE
@@ -683,7 +683,7 @@ fn decode_transaction(args: &[String], _version: TransactionVersion) -> Result<S
683683
}
684684

685685
fn decode_header(args: &[String], _version: TransactionVersion) -> Result<String, CliError> {
686-
if (args.len() >= 1 && args[0] == "-h") || args.len() != 1 {
686+
if (!args.is_empty() && args[0] == "-h") || args.len() != 1 {
687687
return Err(CliError::Message(format!(
688688
"Usage: {}\n",
689689
DECODE_HEADER_USAGE
@@ -722,7 +722,7 @@ fn decode_header(args: &[String], _version: TransactionVersion) -> Result<String
722722
}
723723

724724
fn decode_block(args: &[String], _version: TransactionVersion) -> Result<String, CliError> {
725-
if (args.len() >= 1 && args[0] == "-h") || args.len() != 1 {
725+
if (!args.is_empty() && args[0] == "-h") || args.len() != 1 {
726726
return Err(CliError::Message(format!(
727727
"Usage: {}\n",
728728
DECODE_BLOCK_USAGE
@@ -759,7 +759,7 @@ fn decode_block(args: &[String], _version: TransactionVersion) -> Result<String,
759759
}
760760

761761
fn decode_microblock(args: &[String], _version: TransactionVersion) -> Result<String, CliError> {
762-
if (args.len() >= 1 && args[0] == "-h") || args.len() != 1 {
762+
if (!args.is_empty() && args[0] == "-h") || args.len() != 1 {
763763
return Err(CliError::Message(format!(
764764
"Usage: {}\n",
765765
DECODE_MICROBLOCK_USAGE
@@ -798,7 +798,7 @@ fn decode_microblock(args: &[String], _version: TransactionVersion) -> Result<St
798798
}
799799

800800
fn decode_microblocks(args: &[String], _version: TransactionVersion) -> Result<String, CliError> {
801-
if (args.len() >= 1 && args[0] == "-h") || args.len() != 1 {
801+
if (!args.is_empty() && args[0] == "-h") || args.len() != 1 {
802802
return Err(CliError::Message(format!(
803803
"Usage: {}\n",
804804
DECODE_MICROBLOCKS_USAGE

stackslib/src/burnchains/affirmation.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ impl AffirmationMap {
378378
self.affirmations.len()
379379
}
380380

381+
pub fn is_empty(&self) -> bool {
382+
self.affirmations.is_empty()
383+
}
384+
381385
pub fn as_slice(&self) -> &[AffirmationMapEntry] {
382386
&self.affirmations
383387
}
@@ -876,7 +880,7 @@ fn inner_find_heaviest_block_commit_ptr(
876880
test_debug!("ancestors = {:?}", &ancestors);
877881
test_debug!("ancestor_confirmations = {:?}", &ancestor_confirmations);
878882

879-
if ancestor_confirmations.len() == 0 {
883+
if ancestor_confirmations.is_empty() {
880884
// empty prepare phase
881885
test_debug!("Prepare-phase has no block-commits");
882886
return None;

stackslib/src/burnchains/bitcoin/address.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl SegwitBitcoinAddress {
317317
None
318318
}?;
319319

320-
if quintets.len() == 0 || quintets.len() > 65 {
320+
if quintets.is_empty() || quintets.len() > 65 {
321321
test_debug!("Invalid prog length: {}", quintets.len());
322322
return None;
323323
}

stackslib/src/burnchains/bitcoin/bits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl BitcoinTxInputStructured {
9393
segwit: bool,
9494
input_txid: (Txid, u32),
9595
) -> Option<BitcoinTxInputStructured> {
96-
if num_sigs < 1 || pubkey_pushbytes.len() < 1 || pubkey_pushbytes.len() < num_sigs {
96+
if num_sigs < 1 || pubkey_pushbytes.is_empty() || pubkey_pushbytes.len() < num_sigs {
9797
test_debug!(
9898
"Not a multisig script: num_sigs = {}, num_pubkeys <= {}",
9999
num_sigs,
@@ -153,7 +153,7 @@ impl BitcoinTxInputStructured {
153153
pubkey_vecs: &[Vec<u8>],
154154
input_txid: (Txid, u32),
155155
) -> Option<BitcoinTxInputStructured> {
156-
if num_sigs < 1 || pubkey_vecs.len() < 1 || pubkey_vecs.len() < num_sigs {
156+
if num_sigs < 1 || pubkey_vecs.is_empty() || pubkey_vecs.len() < num_sigs {
157157
test_debug!(
158158
"Not a multisig script: num_sigs = {}, num_pubkeys <= {}",
159159
num_sigs,

stackslib/src/burnchains/bitcoin/blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl BitcoinBlockParser {
381381
tx: &Transaction,
382382
epoch_id: StacksEpochId,
383383
) -> Option<Vec<BitcoinTxOutput>> {
384-
if tx.output.len() == 0 {
384+
if tx.output.is_empty() {
385385
return None;
386386
}
387387

stackslib/src/burnchains/bitcoin/indexer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ impl BitcoinIndexer {
705705
e
706706
})?;
707707

708-
if reorg_headers.len() == 0 {
708+
if reorg_headers.is_empty() {
709709
// chain shrank considerably
710710
info!(
711711
"Missing Bitcoin headers in block range {}-{} -- did the Bitcoin chain shrink?",
@@ -736,7 +736,7 @@ impl BitcoinIndexer {
736736
})?;
737737

738738
assert!(
739-
canonical_headers.len() > 0,
739+
!canonical_headers.is_empty(),
740740
"BUG: uninitialized canonical SPV headers DB"
741741
);
742742

@@ -1379,7 +1379,7 @@ mod test {
13791379
spv_client
13801380
.insert_block_headers_before(start_block - 1, hdrs)
13811381
.unwrap();
1382-
} else if hdrs.len() > 0 {
1382+
} else if !hdrs.is_empty() {
13831383
test_debug!("insert at {}: {:?}", 0, &hdrs);
13841384
spv_client.test_write_block_headers(0, hdrs).unwrap();
13851385
}
@@ -1552,7 +1552,7 @@ mod test {
15521552
spv_client
15531553
.insert_block_headers_before(start_block - 1, hdrs)
15541554
.unwrap();
1555-
} else if hdrs.len() > 0 {
1555+
} else if !hdrs.is_empty() {
15561556
test_debug!("insert at {}: {:?}", 0, &hdrs);
15571557
spv_client.test_write_block_headers(0, hdrs).unwrap();
15581558
}

stackslib/src/burnchains/bitcoin/network.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl BitcoinIndexer {
355355

356356
/// Send a GetData message
357357
pub fn send_getdata(&mut self, block_hashes: &Vec<Sha256dHash>) -> Result<(), btc_error> {
358-
assert!(block_hashes.len() > 0);
358+
assert!(!block_hashes.is_empty());
359359
let getdata_invs = block_hashes
360360
.iter()
361361
.map(|h| btc_message_blockdata::Inventory {

stackslib/src/burnchains/bitcoin/spv.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl SpvClient {
529529
headers: &Vec<LoneBlockHeader>,
530530
check_txcount: bool,
531531
) -> Result<(), btc_error> {
532-
if headers.len() == 0 {
532+
if headers.is_empty() {
533533
return Ok(());
534534
}
535535

@@ -945,7 +945,7 @@ impl SpvClient {
945945
) -> Result<(), btc_error> {
946946
assert!(self.readwrite, "SPV header DB is open read-only");
947947

948-
if block_headers.len() == 0 {
948+
if block_headers.is_empty() {
949949
// no-op
950950
return Ok(());
951951
}
@@ -996,7 +996,7 @@ impl SpvClient {
996996
block_headers: Vec<LoneBlockHeader>,
997997
) -> Result<(), btc_error> {
998998
assert!(self.readwrite, "SPV header DB is open read-only");
999-
if block_headers.len() == 0 {
999+
if block_headers.is_empty() {
10001000
// no-op
10011001
return Ok(());
10021002
}
@@ -1137,7 +1137,7 @@ impl SpvClient {
11371137
]);
11381138
let max_target_bits = BlockHeader::compact_target_from_u256(&max_target);
11391139

1140-
let parent_header = if headers_in_range.len() > 0 {
1140+
let parent_header = if !headers_in_range.is_empty() {
11411141
headers_in_range[0]
11421142
} else {
11431143
match self.read_block_header(current_header_height - 1)? {

stackslib/src/burnchains/burnchain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl BurnchainStateTransition {
130130

131131
block_total_burns.sort();
132132

133-
if block_total_burns.len() == 0 {
133+
if block_total_burns.is_empty() {
134134
return Some(0);
135135
} else if block_total_burns.len() == 1 {
136136
return Some(block_total_burns[0]);

stackslib/src/burnchains/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl BurnchainDBTransaction<'_> {
451451
})
452452
.collect()
453453
};
454-
if commits.len() == 0 {
454+
if commits.is_empty() {
455455
test_debug!("No block-commits for block {}", hdr.block_height);
456456
return Ok(());
457457
}

0 commit comments

Comments
 (0)