From 624cda07b3f1d36928f92b904368c3ad4de16ec4 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 4 Nov 2022 11:44:23 +1100 Subject: [PATCH 1/4] Remove unnecessary casts Clippy emits a bunch of warnings of form: warning: casting to the same type is unnecessary ... As suggested, remove the unnecessary casts. --- bitcoin/src/bip152.rs | 2 +- bitcoin/src/bip32.rs | 4 ++-- bitcoin/src/blockdata/witness.rs | 2 +- bitcoin/src/consensus/encode.rs | 2 +- bitcoin/src/pow.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bitcoin/src/bip152.rs b/bitcoin/src/bip152.rs index 2b81a1cd..aa8b90dd 100644 --- a/bitcoin/src/bip152.rs +++ b/bitcoin/src/bip152.rs @@ -284,7 +284,7 @@ impl Decodable for BlockTransactionsRequest { // Since the number of indices ultimately represent transactions, // we can limit the number of indices to the maximum number of // transactions that would be allowed in a vector. - let byte_size = (nb_indexes as usize) + let byte_size = (nb_indexes) .checked_mul(mem::size_of::()) .ok_or(encode::Error::ParseFailed("Invalid length"))?; if byte_size > encode::MAX_VEC_SIZE { diff --git a/bitcoin/src/bip32.rs b/bitcoin/src/bip32.rs index dcb9dbc7..f631f4b7 100644 --- a/bitcoin/src/bip32.rs +++ b/bitcoin/src/bip32.rs @@ -627,7 +627,7 @@ impl ExtendedPrivKey { Network::Testnet | Network::Signet | Network::Regtest => [0x04, 0x35, 0x83, 0x94], }[..], ); - ret[4] = self.depth as u8; + ret[4] = self.depth; ret[5..9].copy_from_slice(&self.parent_fingerprint[..]); ret[9..13].copy_from_slice(&u32::from(self.child_number).to_be_bytes()); ret[13..45].copy_from_slice(&self.chain_code[..]); @@ -759,7 +759,7 @@ impl ExtendedPubKey { Network::Testnet | Network::Signet | Network::Regtest => [0x04u8, 0x35, 0x87, 0xCF], }[..], ); - ret[4] = self.depth as u8; + ret[4] = self.depth; ret[5..9].copy_from_slice(&self.parent_fingerprint[..]); ret[9..13].copy_from_slice(&u32::from(self.child_number).to_be_bytes()); ret[13..45].copy_from_slice(&self.chain_code[..]); diff --git a/bitcoin/src/blockdata/witness.rs b/bitcoin/src/blockdata/witness.rs index 40311121..c559e580 100644 --- a/bitcoin/src/blockdata/witness.rs +++ b/bitcoin/src/blockdata/witness.rs @@ -179,7 +179,7 @@ impl Witness { /// Returns the number of elements this witness holds pub fn len(&self) -> usize { - self.witness_elements as usize + self.witness_elements } /// Returns the bytes required when this Witness is consensus encoded diff --git a/bitcoin/src/consensus/encode.rs b/bitcoin/src/consensus/encode.rs index 73b07f7e..20f9d306 100644 --- a/bitcoin/src/consensus/encode.rs +++ b/bitcoin/src/consensus/encode.rs @@ -423,7 +423,7 @@ impl Encodable for VarInt { }, _ => { w.emit_u8(0xFF)?; - (self.0 as u64).consensus_encode(w)?; + self.0.consensus_encode(w)?; Ok(9) }, } diff --git a/bitcoin/src/pow.rs b/bitcoin/src/pow.rs index f267d349..be0730e4 100644 --- a/bitcoin/src/pow.rs +++ b/bitcoin/src/pow.rs @@ -198,7 +198,7 @@ impl Target { size += 1; } - CompactTarget(compact | (size << 24) as u32) + CompactTarget(compact | (size << 24)) } /// Returns true if block hash is less than or equal to this [`Target`]. From d1920525192c8e6011073ca2ab0e37ac974b6edf Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 4 Nov 2022 11:45:57 +1100 Subject: [PATCH 2/4] Remove unnecessary dereference Clippy emits: warning: deref which would be done by auto-deref As suggested, remove the unnecessary deref (`*`). --- bitcoin/src/blockdata/script.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitcoin/src/blockdata/script.rs b/bitcoin/src/blockdata/script.rs index 7628da14..8cb8c76f 100644 --- a/bitcoin/src/blockdata/script.rs +++ b/bitcoin/src/blockdata/script.rs @@ -443,7 +443,7 @@ impl Script { pub fn is_empty(&self) -> bool { self.0.is_empty() } /// Returns the script data as a byte slice. - pub fn as_bytes(&self) -> &[u8] { &*self.0 } + pub fn as_bytes(&self) -> &[u8] { &self.0 } /// Returns a copy of the script data. pub fn to_bytes(&self) -> Vec { self.0.clone().into_vec() } From 39667093366dc70692f3d7c147ca9619b395fc4a Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 4 Nov 2022 11:47:34 +1100 Subject: [PATCH 3/4] Use is_none() Clippy emits: warning: binary comparison to literal `Option::None` As suggested, use `find.is_none()` instead of comparison with `None`. --- bitcoin/src/blockdata/transaction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index 2a64cb30..c364b226 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -165,7 +165,7 @@ impl core::str::FromStr for OutPoint { return Err(ParseOutPointError::TooLong); } let find = s.find(':'); - if find == None || find != s.rfind(':') { + if find.is_none() || find != s.rfind(':') { return Err(ParseOutPointError::Format); } let colon = find.unwrap(); From 1050fe9cae88643ebe18436bc99a02f2c1c9961a Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 4 Nov 2022 11:49:14 +1100 Subject: [PATCH 4/4] Remove unnecessary borrow Clippy emits: warning: the borrowed expression implements the required traits As suggested, remove the unnecessary explicit borrow. --- bitcoin/src/sign_message.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bitcoin/src/sign_message.rs b/bitcoin/src/sign_message.rs index f85795a1..6094e9a1 100644 --- a/bitcoin/src/sign_message.rs +++ b/bitcoin/src/sign_message.rs @@ -281,9 +281,8 @@ mod tests { let signature = super::MessageSignature::from_base64(signature_base64).expect("message signature"); - let pubkey = - PublicKey::from_slice(&::base64::decode(&pubkey_base64).expect("base64 string")) - .expect("pubkey slice"); + let pubkey = PublicKey::from_slice(&base64::decode(pubkey_base64).expect("base64 string")) + .expect("pubkey slice"); let p2pkh = Address::p2pkh(&pubkey, Network::Bitcoin); assert_eq!(signature.is_signed_by_address(&secp, &p2pkh, msg_hash), Ok(false));