Skip to content

Commit 6638619

Browse files
committed
Merge rust-bitcoin/rust-bitcoin#1043: Clear clippy warnings from --all-targets
271d0ba Allow many arguments in test function (Tobin C. Harding) c0c88fe Use vec instead of pushing to a mutable vector (Tobin C. Harding) 73066e7 Use values() to iterate map values (Tobin C. Harding) 38ff025 Remove useless use of vec! (Tobin C. Harding) d8e82d5 Remove length comparison to zero (Tobin C. Harding) c1f34f5 Return Address directly (Tobin C. Harding) ff8d585 Use flat_map instead of map().flatten() (Tobin C. Harding) b24a112 Remove calls to clone from types that implement Copy (Tobin C. Harding) 2b8d93e Remove unnecessary explicit reference (Tobin C. Harding) ef90e3d Use plus-equals operator (Tobin C. Harding) 922b820 Replace assert!(false) with panic! (Tobin C. Harding) a8039e1 Remove redundant clone (Tobin C. Harding) cf8de73 Remove unnecessary cast of integer literal (Tobin C. Harding) 999ac45 Do not use assert_eq with literal bool (Tobin C. Harding) 827fcd8 Allow unusual digit grouping (Tobin C. Harding) 242c640 Remove redundant field names (Tobin C. Harding) 0f8f4c5 Collapse if statements (Tobin C. Harding) 229fcb9 Use if let instead of destructuring pattern (Tobin C. Harding) Pull request description: Clear all the clippy warnings (excl. #1042) that are returned by running `cargo clippy --all-targets`. I apologize in advance for the review burden :) ACKs for top commit: elichai: ACK 271d0ba apoelstra: ACK 271d0ba Tree-SHA512: 71ad2ec3db808e795791b7513f8b2a1c13dc90317f5328602c9ecbc31c09f82471f79c9c31a71a0ded5280554d1019d2bb4899fb9e8fa6421d46a2397cd31242
2 parents e9e9177 + 92ff6d4 commit 6638619

File tree

17 files changed

+68
-74
lines changed

17 files changed

+68
-74
lines changed

src/blockdata/block.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,15 @@ mod tests {
517517
// test with zero target
518518
match some_header.validate_pow(&Uint256::default()) {
519519
Err(BlockBadTarget) => (),
520-
_ => assert!(false)
520+
_ => panic!("unexpected result from validate_pow"),
521521
}
522522

523523
// test with modified header
524-
let mut invalid_header: BlockHeader = some_header.clone();
525-
invalid_header.version = invalid_header.version + 1;
524+
let mut invalid_header: BlockHeader = some_header;
525+
invalid_header.version += 1;
526526
match invalid_header.validate_pow(&invalid_header.target()) {
527527
Err(BlockBadProofOfWork) => (),
528-
_ => assert!(false)
528+
_ => panic!("unexpected result from validate_pow"),
529529
}
530530
}
531531

src/blockdata/script.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,18 +1329,18 @@ mod test {
13291329
#[test]
13301330
fn provably_unspendable_test() {
13311331
// p2pk
1332-
assert_eq!(hex_script!("410446ef0102d1ec5240f0d061a4246c1bdef63fc3dbab7733052fbbf0ecd8f41fc26bf049ebb4f9527f374280259e7cfa99c48b0e3f39c51347a19a5819651503a5ac").is_provably_unspendable(), false);
1333-
assert_eq!(hex_script!("4104ea1feff861b51fe3f5f8a3b12d0f4712db80e919548a80839fc47c6a21e66d957e9c5d8cd108c7a2d2324bad71f9904ac0ae7336507d785b17a2c115e427a32fac").is_provably_unspendable(), false);
1332+
assert!(!hex_script!("410446ef0102d1ec5240f0d061a4246c1bdef63fc3dbab7733052fbbf0ecd8f41fc26bf049ebb4f9527f374280259e7cfa99c48b0e3f39c51347a19a5819651503a5ac").is_provably_unspendable());
1333+
assert!(!hex_script!("4104ea1feff861b51fe3f5f8a3b12d0f4712db80e919548a80839fc47c6a21e66d957e9c5d8cd108c7a2d2324bad71f9904ac0ae7336507d785b17a2c115e427a32fac").is_provably_unspendable());
13341334
// p2pkhash
1335-
assert_eq!(hex_script!("76a914ee61d57ab51b9d212335b1dba62794ac20d2bcf988ac").is_provably_unspendable(), false);
1336-
assert_eq!(hex_script!("6aa9149eb21980dc9d413d8eac27314938b9da920ee53e87").is_provably_unspendable(), true);
1335+
assert!(!hex_script!("76a914ee61d57ab51b9d212335b1dba62794ac20d2bcf988ac").is_provably_unspendable());
1336+
assert!(hex_script!("6aa9149eb21980dc9d413d8eac27314938b9da920ee53e87").is_provably_unspendable());
13371337
}
13381338

13391339
#[test]
13401340
fn op_return_test() {
1341-
assert_eq!(hex_script!("6aa9149eb21980dc9d413d8eac27314938b9da920ee53e87").is_op_return(), true);
1342-
assert_eq!(hex_script!("76a914ee61d57ab51b9d212335b1dba62794ac20d2bcf988ac").is_op_return(), false);
1343-
assert_eq!(hex_script!("").is_op_return(), false);
1341+
assert!(hex_script!("6aa9149eb21980dc9d413d8eac27314938b9da920ee53e87").is_op_return());
1342+
assert!(!hex_script!("76a914ee61d57ab51b9d212335b1dba62794ac20d2bcf988ac").is_op_return());
1343+
assert!(!hex_script!("").is_op_return());
13441344
}
13451345

13461346
#[test]

src/blockdata/transaction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ mod tests {
10091009
assert_eq!(txin.script_sig, Script::new());
10101010
assert_eq!(txin.sequence, 0xFFFFFFFF);
10111011
assert_eq!(txin.previous_output, OutPoint::default());
1012-
assert_eq!(txin.witness.len(), 0 as usize);
1012+
assert_eq!(txin.witness.len(), 0);
10131013
}
10141014

10151015
#[test]
@@ -1092,7 +1092,7 @@ mod tests {
10921092
let expected_strippedsize = (EXPECTED_WEIGHT - tx_bytes.len()) / (WITNESS_SCALE_FACTOR - 1);
10931093
assert_eq!(realtx.strippedsize(), expected_strippedsize);
10941094
// Construct a transaction without the witness data.
1095-
let mut tx_without_witness = realtx.clone();
1095+
let mut tx_without_witness = realtx;
10961096
tx_without_witness.input.iter_mut().for_each(|input| input.witness.clear());
10971097
assert_eq!(tx_without_witness.weight(), expected_strippedsize*WITNESS_SCALE_FACTOR);
10981098
assert_eq!(tx_without_witness.size(), expected_strippedsize);

src/network/message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ mod test {
597597
assert_eq!(version_msg.nonce, 13952548347456104954);
598598
assert_eq!(version_msg.user_agent, "/Satoshi:0.17.1/");
599599
assert_eq!(version_msg.start_height, 560275);
600-
assert_eq!(version_msg.relay, true);
600+
assert!(version_msg.relay);
601601
} else {
602602
panic!("Wrong message type");
603603
}
@@ -634,7 +634,7 @@ mod test {
634634
assert_eq!(version_msg.nonce, 13952548347456104954);
635635
assert_eq!(version_msg.user_agent, "/Satoshi:0.17.1/");
636636
assert_eq!(version_msg.start_height, 560275);
637-
assert_eq!(version_msg.relay, true);
637+
assert!(version_msg.relay);
638638
} else {
639639
panic!("Wrong message type");
640640
}

src/network/message_network.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ mod tests {
170170
assert_eq!(real_decode.nonce, 16735069437859780935);
171171
assert_eq!(real_decode.user_agent, "/Satoshi:0.9.99/".to_string());
172172
assert_eq!(real_decode.start_height, 302892);
173-
assert_eq!(real_decode.relay, true);
173+
assert!(real_decode.relay);
174174

175175
assert_eq!(serialize(&real_decode), from_sat);
176176
}

src/network/stream_reader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ mod test {
139139
assert_eq!(version_msg.nonce, 13952548347456104954);
140140
assert_eq!(version_msg.user_agent, "/Satoshi:0.17.1/");
141141
assert_eq!(version_msg.start_height, 560275);
142-
assert_eq!(version_msg.relay, true);
142+
assert!(version_msg.relay);
143143
} else {
144144
panic!("Wrong message type: expected VersionMessage");
145145
}

src/util/address.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,10 @@ impl Address {
693693

694694
/// Constructs an [`Address`] from an output script (`scriptPubkey`).
695695
pub fn from_script(script: &script::Script, network: Network) -> Option<Address> {
696-
if script.is_witness_program() {
697-
if script.witness_version() == Some(WitnessVersion::V0) && !(script.is_v0_p2wpkh() || script.is_v0_p2wsh()) {
696+
if script.is_witness_program()
697+
&& script.witness_version() == Some(WitnessVersion::V0)
698+
&& !(script.is_v0_p2wpkh() || script.is_v0_p2wsh()) {
698699
return None
699-
}
700700
}
701701

702702
Some(Address {
@@ -988,7 +988,7 @@ mod tests {
988988
let addr = Address::p2pkh(&key, Bitcoin);
989989
assert_eq!(&addr.to_string(), "1QJVDzdqb1VpbDK7uDeyVXy9mR27CJiyhY");
990990

991-
let key = hex_key!(&"03df154ebfcf29d29cc10d5c2565018bce2d9edbab267c31d2caf44a63056cf99f");
991+
let key = hex_key!("03df154ebfcf29d29cc10d5c2565018bce2d9edbab267c31d2caf44a63056cf99f");
992992
let addr = Address::p2pkh(&key, Testnet);
993993
assert_eq!(&addr.to_string(), "mqkhEMH6NCeYjFybv7pvFC22MFeaNT9AQC");
994994
assert_eq!(addr.address_type(), Some(AddressType::P2pkh));
@@ -1086,7 +1086,7 @@ mod tests {
10861086
let addr = Address {
10871087
payload: Payload::WitnessProgram {
10881088
version: WitnessVersion::V13,
1089-
program: program,
1089+
program,
10901090
},
10911091
network: Network::Bitcoin,
10921092
};
@@ -1108,7 +1108,7 @@ mod tests {
11081108
("bc1zw508d6qejxtdg4y5r3zarvaryvaxxpcs", None),
11091109
];
11101110
for (address, expected_type) in &addresses {
1111-
let addr = Address::from_str(&address).unwrap();
1111+
let addr = Address::from_str(address).unwrap();
11121112
assert_eq!(&addr.address_type(), expected_type);
11131113
}
11141114
}
@@ -1292,11 +1292,10 @@ mod tests {
12921292

12931293
fn test_addr_type(payloads: &[Payload], equivalence_classes: &[&[Network]]) {
12941294
for pl in payloads {
1295-
for addr_net in equivalence_classes.iter().map(|ec| ec.iter()).flatten() {
1295+
for addr_net in equivalence_classes.iter().flat_map(|ec| ec.iter()) {
12961296
for valid_net in equivalence_classes.iter()
12971297
.filter(|ec| ec.contains(addr_net))
1298-
.map(|ec| ec.iter())
1299-
.flatten()
1298+
.flat_map(|ec| ec.iter())
13001299
{
13011300
let addr = Address {
13021301
payload: pl.clone(),
@@ -1307,8 +1306,7 @@ mod tests {
13071306

13081307
for invalid_net in equivalence_classes.iter()
13091308
.filter(|ec| !ec.contains(addr_net))
1310-
.map(|ec| ec.iter())
1311-
.flatten()
1309+
.flat_map(|ec| ec.iter())
13121310
{
13131311
let addr = Address {
13141312
payload: pl.clone(),

src/util/amount.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,7 @@ mod tests {
15991599
}
16001600

16011601
#[test]
1602+
#[allow(clippy::inconsistent_digit_grouping)] // Group to show 100,000,000 sats per bitcoin.
16021603
fn parsing() {
16031604
use super::ParseAmountError as E;
16041605
let btc = Denomination::Bitcoin;
@@ -1868,6 +1869,7 @@ mod tests {
18681869
}
18691870

18701871
#[test]
1872+
#[allow(clippy::inconsistent_digit_grouping)] // Group to show 100,000,000 sats per bitcoin.
18711873
fn from_str() {
18721874
use super::ParseAmountError as E;
18731875
let p = Amount::from_str;
@@ -1906,6 +1908,7 @@ mod tests {
19061908
}
19071909

19081910
#[test]
1911+
#[allow(clippy::inconsistent_digit_grouping)] // Group to show 100,000,000 sats per bitcoin.
19091912
fn to_from_string_in() {
19101913
use super::Denomination as D;
19111914
let ua_str = Amount::from_str_in;

src/util/base58.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ mod tests {
299299
assert_eq!(&encode_slice(&[0, 0, 0, 0, 13, 36][..]), "1111211");
300300

301301
// Long input (>100 bytes => has to use heap)
302-
let res = encode_slice(&"BitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBit\
302+
let res = encode_slice("BitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBit\
303303
coinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoin".as_bytes());
304304
let exp = "ZqC5ZdfpZRi7fjA8hbhX5pEE96MdH9hEaC1YouxscPtbJF16qVWksHWR4wwvx7MotFcs2ChbJqK8KJ9X\
305305
wZznwWn1JFDhhTmGo9v6GjAVikzCsBWZehu7bm22xL8b5zBR5AsBygYRwbFJsNwNkjpyFuDKwmsUTKvkULCvucPJrN5\

src/util/bip143.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ mod tests {
201201

202202
fn p2pkh_hex(pk: &str) -> Script {
203203
let pk: PublicKey = PublicKey::from_str(pk).unwrap();
204-
let witness_script = Address::p2pkh(&pk, Network::Bitcoin).script_pubkey();
205-
witness_script
204+
Address::p2pkh(&pk, Network::Bitcoin).script_pubkey()
206205
}
207206

208207
fn run_test_sighash_bip143(tx: &str, script: &str, input_index: usize, value: u64, hash_type: u32, expected_result: &str) {

0 commit comments

Comments
 (0)