From 9a5ba9b6df1c37e6f6e29029f3169a9ba8d1ceaa Mon Sep 17 00:00:00 2001 From: Fmt Bot Date: Sun, 8 Sep 2024 01:17:12 +0000 Subject: [PATCH] 2024-09-08 automated rustfmt nightly --- bitcoin/src/blockdata/constants.rs | 5 ++++- bitcoin/src/crypto/ecdsa.rs | 3 ++- bitcoin/src/p2p/mod.rs | 4 +++- bitcoin/src/pow.rs | 1 + bitcoin/src/sign_message.rs | 4 +--- hashes/src/hkdf.rs | 7 +++++-- hashes/src/lib.rs | 6 +++--- internals/src/macros.rs | 4 +--- primitives/src/pow.rs | 7 ++++++- primitives/src/sequence.rs | 6 +++++- 10 files changed, 31 insertions(+), 16 deletions(-) diff --git a/bitcoin/src/blockdata/constants.rs b/bitcoin/src/blockdata/constants.rs index e0ed771c6..7ac1d4905 100644 --- a/bitcoin/src/blockdata/constants.rs +++ b/bitcoin/src/blockdata/constants.rs @@ -47,7 +47,10 @@ pub const MAX_STACK_ELEMENT_SIZE: usize = 520; /// How may blocks between halvings. pub const SUBSIDY_HALVING_INTERVAL: u32 = 210_000; /// Maximum allowed value for an integer in Script. -#[deprecated(since = "TBD", note = "This constant has ambiguous semantics. Please carefully check your intended use-case and define a new constant reflecting that.")] +#[deprecated( + since = "TBD", + note = "This constant has ambiguous semantics. Please carefully check your intended use-case and define a new constant reflecting that." +)] pub const MAX_SCRIPTNUM_VALUE: u32 = 0x80000000; // 2^31 /// Number of blocks needed for an output from a coinbase transaction to be spendable. pub const COINBASE_MATURITY: u32 = 100; diff --git a/bitcoin/src/crypto/ecdsa.rs b/bitcoin/src/crypto/ecdsa.rs index 646ccaf47..162a831f3 100644 --- a/bitcoin/src/crypto/ecdsa.rs +++ b/bitcoin/src/crypto/ecdsa.rs @@ -174,7 +174,8 @@ impl fmt::LowerHex for SerializedSignature { fmt::LowerHex::fmt(&(**self).as_hex(), f) } } -impl_to_hex_from_lower_hex!(SerializedSignature, |signature: &SerializedSignature| signature.len * 2); +impl_to_hex_from_lower_hex!(SerializedSignature, |signature: &SerializedSignature| signature.len + * 2); impl fmt::UpperHex for SerializedSignature { #[inline] diff --git a/bitcoin/src/p2p/mod.rs b/bitcoin/src/p2p/mod.rs index b64fc36e0..a682ca398 100644 --- a/bitcoin/src/p2p/mod.rs +++ b/bitcoin/src/p2p/mod.rs @@ -22,6 +22,7 @@ pub mod message_network; use core::str::FromStr; use core::{fmt, ops}; + use hex::FromHex; use internals::{debug_from_display, impl_to_hex_from_lower_hex, write_err}; use io::{BufRead, Write}; @@ -122,7 +123,8 @@ impl ServiceFlags { impl fmt::LowerHex for ServiceFlags { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::LowerHex::fmt(&self.0, f) } } -impl_to_hex_from_lower_hex!(ServiceFlags, |service_flags: &ServiceFlags| 16 - service_flags.0.leading_zeros() as usize / 4); +impl_to_hex_from_lower_hex!(ServiceFlags, |service_flags: &ServiceFlags| 16 + - service_flags.0.leading_zeros() as usize / 4); impl fmt::UpperHex for ServiceFlags { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::UpperHex::fmt(&self.0, f) } diff --git a/bitcoin/src/pow.rs b/bitcoin/src/pow.rs index 637ba939b..6d1afe18c 100644 --- a/bitcoin/src/pow.rs +++ b/bitcoin/src/pow.rs @@ -7,6 +7,7 @@ use core::ops::{Add, Div, Mul, Not, Rem, Shl, Shr, Sub}; use core::{cmp, fmt}; + use internals::impl_to_hex_from_lower_hex; use io::{BufRead, Write}; #[cfg(all(test, mutate))] diff --git a/bitcoin/src/sign_message.rs b/bitcoin/src/sign_message.rs index d722d549a..8295daae1 100644 --- a/bitcoin/src/sign_message.rs +++ b/bitcoin/src/sign_message.rs @@ -109,9 +109,7 @@ mod message_signing { } /// Creates a `MessageSignature` from a fixed-length array. - pub fn from_byte_array( - bytes: &[u8; 65], - ) -> Result { + pub fn from_byte_array(bytes: &[u8; 65]) -> Result { // We just check this here so we can safely subtract further. if bytes[0] < 27 { return Err(secp256k1::Error::InvalidRecoveryId); diff --git a/hashes/src/hkdf.rs b/hashes/src/hkdf.rs index 77af8f085..cfe641f69 100644 --- a/hashes/src/hkdf.rs +++ b/hashes/src/hkdf.rs @@ -79,8 +79,11 @@ where let t = Hmac::from_engine(hmac_engine); let start_index = (counter as usize - 1) * T::Bytes::LEN; // Last block might not take full hash length. - let end_index = - if counter == (total_blocks as u8) { okm.len() } else { counter as usize * T::Bytes::LEN }; + let end_index = if counter == (total_blocks as u8) { + okm.len() + } else { + counter as usize * T::Bytes::LEN + }; okm[start_index..end_index].copy_from_slice(&t.as_ref()[0..(end_index - start_index)]); diff --git a/hashes/src/lib.rs b/hashes/src/lib.rs index eb979a4d4..2c2371bab 100644 --- a/hashes/src/lib.rs +++ b/hashes/src/lib.rs @@ -274,7 +274,7 @@ pub trait Hash: + convert::AsRef<[u8]> { /// The byte array that represents the hash internally. - type Bytes: hex::FromHex + Copy + IsByteArray /* is still unsupported by Rust */; + type Bytes: hex::FromHex + Copy + IsByteArray; /// Length of the hash, in bytes. const LEN: usize = Self::Bytes::LEN; @@ -309,9 +309,9 @@ impl IsByteArray for [u8; N] { mod sealed { #[doc(hidden)] - pub trait IsByteArray { } + pub trait IsByteArray {} - impl IsByteArray for [u8; N] { } + impl IsByteArray for [u8; N] {} } /// Attempted to create a hash from an invalid length slice. diff --git a/internals/src/macros.rs b/internals/src/macros.rs index e1ff3a96c..cdee1ab69 100644 --- a/internals/src/macros.rs +++ b/internals/src/macros.rs @@ -227,7 +227,5 @@ macro_rules! impl_to_hex_from_lower_hex { #[macro_export] #[cfg(not(feature = "alloc"))] macro_rules! impl_to_hex_from_lower_hex { - ($t:ident, $hex_len_fn:expr) => { - - }; + ($t:ident, $hex_len_fn:expr) => {}; } diff --git a/primitives/src/pow.rs b/primitives/src/pow.rs index 18bd549a4..663557ca1 100644 --- a/primitives/src/pow.rs +++ b/primitives/src/pow.rs @@ -3,6 +3,7 @@ //! Proof-of-work related integer types. use core::fmt; + use internals::impl_to_hex_from_lower_hex; /// Encoding of 256-bit target as 32-bit float. @@ -35,7 +36,11 @@ impl fmt::LowerHex for CompactTarget { #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::LowerHex::fmt(&self.0, f) } } -impl_to_hex_from_lower_hex!(CompactTarget, |compact_target: &CompactTarget| 8 - compact_target.0.leading_zeros() as usize / 4); +impl_to_hex_from_lower_hex!(CompactTarget, |compact_target: &CompactTarget| 8 - compact_target + .0 + .leading_zeros() + as usize + / 4); impl fmt::UpperHex for CompactTarget { #[inline] diff --git a/primitives/src/sequence.rs b/primitives/src/sequence.rs index 5e7de3f09..d3ee0013d 100644 --- a/primitives/src/sequence.rs +++ b/primitives/src/sequence.rs @@ -16,6 +16,7 @@ //! [BIP-125]: use core::fmt; + use internals::impl_to_hex_from_lower_hex; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -23,6 +24,7 @@ use serde::{Deserialize, Serialize}; use units::locktime::relative::TimeOverflowError; #[cfg(feature = "alloc")] use units::parse::{self, PrefixedHexError, UnprefixedHexError}; + #[cfg(feature = "alloc")] use crate::locktime::relative; @@ -219,7 +221,9 @@ impl fmt::Display for Sequence { impl fmt::LowerHex for Sequence { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::LowerHex::fmt(&self.0, f) } } -impl_to_hex_from_lower_hex!(Sequence, |sequence: &Sequence| 8 - sequence.0.leading_zeros() as usize / 4); +impl_to_hex_from_lower_hex!(Sequence, |sequence: &Sequence| 8 - sequence.0.leading_zeros() + as usize + / 4); impl fmt::UpperHex for Sequence { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::UpperHex::fmt(&self.0, f) }