From 624cda07b3f1d36928f92b904368c3ad4de16ec4 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 4 Nov 2022 11:44:23 +1100 Subject: [PATCH] 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`].