Merge rust-bitcoin/rust-bitcoin#1367: Do clippy improvements

1050fe9cae Remove unnecessary borrow (Tobin C. Harding)
3966709336 Use is_none() (Tobin C. Harding)
d192052519 Remove unnecessary dereference (Tobin C. Harding)
624cda07b3 Remove unnecessary casts (Tobin C. Harding)

Pull request description:

  Clippy has been updated and new warnings are being triggered in our codebase. This PR does all warnings using nightly since they all looked like reasonable things to fix.

  Needed for CI to pass in other open PRs.

ACKs for top commit:
  Kixunil:
    ACK 1050fe9cae
  sanket1729:
    ACK 1050fe9cae.

Tree-SHA512: 7dcfb6a72a0aae51b49b417bb94cbe1becb1095d1bf0011921b1834a10f792cfcdeee37993ab9b103bd2dfcc9cd3c26cd7f1bb80b06b0d1aa4aaa454bfb0b3f0
This commit is contained in:
sanket1729 2022-11-04 03:17:12 -07:00
commit 932aaaa88a
No known key found for this signature in database
GPG Key ID: 648FFB183E0870A2
8 changed files with 10 additions and 11 deletions

View File

@ -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::<Transaction>())
.ok_or(encode::Error::ParseFailed("Invalid length"))?;
if byte_size > encode::MAX_VEC_SIZE {

View File

@ -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[..]);

View File

@ -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<u8> { self.0.clone().into_vec() }

View File

@ -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();

View File

@ -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

View File

@ -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)
},
}

View File

@ -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`].

View File

@ -281,8 +281,7 @@ 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"))
let pubkey = PublicKey::from_slice(&base64::decode(pubkey_base64).expect("base64 string"))
.expect("pubkey slice");
let p2pkh = Address::p2pkh(&pubkey, Network::Bitcoin);