diff --git a/base58/src/error.rs b/base58/src/error.rs index c86e6dacc..67409d286 100644 --- a/base58/src/error.rs +++ b/base58/src/error.rs @@ -2,8 +2,8 @@ //! Error code for the `base58` crate. -use core::fmt; use core::convert::Infallible; +use core::fmt; use internals::write_err; diff --git a/bitcoin/src/address/error.rs b/bitcoin/src/address/error.rs index 65eb34f4d..eaa820552 100644 --- a/bitcoin/src/address/error.rs +++ b/bitcoin/src/address/error.rs @@ -1,7 +1,7 @@ //! Error code for the address module. -use core::fmt; use core::convert::Infallible; +use core::fmt; use internals::write_err; diff --git a/bitcoin/src/bip152.rs b/bitcoin/src/bip152.rs index d2cdcaf8e..f57fe3e1c 100644 --- a/bitcoin/src/bip152.rs +++ b/bitcoin/src/bip152.rs @@ -4,8 +4,8 @@ //! //! Implementation of compact blocks data structure and algorithms. -use core::{convert, fmt, mem}; use core::convert::Infallible; +use core::{convert, fmt, mem}; #[cfg(feature = "std")] use std::error; diff --git a/bitcoin/src/bip158.rs b/bitcoin/src/bip158.rs index 419514abf..a0d57c1a8 100644 --- a/bitcoin/src/bip158.rs +++ b/bitcoin/src/bip158.rs @@ -38,8 +38,8 @@ //! ``` use core::cmp::{self, Ordering}; -use core::fmt; use core::convert::Infallible; +use core::fmt; use hashes::{sha256d, siphash24, HashEngine as _}; use internals::{write_err, ToU64 as _}; diff --git a/bitcoin/src/bip32.rs b/bitcoin/src/bip32.rs index b02900435..832b497ad 100644 --- a/bitcoin/src/bip32.rs +++ b/bitcoin/src/bip32.rs @@ -5,10 +5,10 @@ //! Implementation of BIP32 hierarchical deterministic wallets, as defined //! at . +use core::convert::Infallible; use core::ops::Index; use core::str::FromStr; use core::{fmt, slice}; -use core::convert::Infallible; use hashes::{hash160, hash_newtype, sha512, GeneralHash, HashEngine, Hmac, HmacEngine}; use internals::write_err; diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs index 72149a44d..43ac31ad7 100644 --- a/bitcoin/src/blockdata/block.rs +++ b/bitcoin/src/blockdata/block.rs @@ -7,8 +7,8 @@ //! module describes structures and functions needed to describe //! these blocks and the blockchain. -use core::fmt; use core::convert::Infallible; +use core::fmt; use hashes::{sha256d, HashEngine}; use internals::{compact_size, ToU64}; diff --git a/bitcoin/src/blockdata/constants.rs b/bitcoin/src/blockdata/constants.rs index 91821fe70..dd45b1c88 100644 --- a/bitcoin/src/blockdata/constants.rs +++ b/bitcoin/src/blockdata/constants.rs @@ -112,7 +112,10 @@ fn bitcoin_genesis_tx(params: &Params) -> Transaction { witness: Witness::default(), }); - ret.output.push(TxOut { value: Amount::from_sat_unchecked(50 * 100_000_000), script_pubkey: out_script }); + ret.output.push(TxOut { + value: Amount::from_sat_unchecked(50 * 100_000_000), + script_pubkey: out_script, + }); // end ret diff --git a/bitcoin/src/blockdata/script/mod.rs b/bitcoin/src/blockdata/script/mod.rs index ac2a01842..b77acb2c7 100644 --- a/bitcoin/src/blockdata/script/mod.rs +++ b/bitcoin/src/blockdata/script/mod.rs @@ -57,8 +57,8 @@ mod tests; pub mod witness_program; pub mod witness_version; -use core::fmt; use core::convert::Infallible; +use core::fmt; use io::{BufRead, Write}; use primitives::opcodes::all::*; diff --git a/bitcoin/src/blockdata/script/witness_program.rs b/bitcoin/src/blockdata/script/witness_program.rs index 9f1448da3..4c60228dc 100644 --- a/bitcoin/src/blockdata/script/witness_program.rs +++ b/bitcoin/src/blockdata/script/witness_program.rs @@ -7,8 +7,8 @@ //! //! [BIP141]: -use core::fmt; use core::convert::Infallible; +use core::fmt; use internals::array_vec::ArrayVec; use secp256k1::{Secp256k1, Verification}; diff --git a/bitcoin/src/blockdata/script/witness_version.rs b/bitcoin/src/blockdata/script/witness_version.rs index 98b6edc16..fa4f06d48 100644 --- a/bitcoin/src/blockdata/script/witness_version.rs +++ b/bitcoin/src/blockdata/script/witness_version.rs @@ -7,9 +7,9 @@ //! //! [BIP141]: +use core::convert::Infallible; use core::fmt; use core::str::FromStr; -use core::convert::Infallible; use internals::write_err; use units::parse::{self, ParseIntError}; diff --git a/bitcoin/src/consensus/error.rs b/bitcoin/src/consensus/error.rs index d3cbaa846..be0bccc9d 100644 --- a/bitcoin/src/consensus/error.rs +++ b/bitcoin/src/consensus/error.rs @@ -2,8 +2,8 @@ //! Consensus encoding errors. -use core::fmt; use core::convert::Infallible; +use core::fmt; use hex::error::{InvalidCharError, OddLengthStringError}; use hex::DisplayHex as _; diff --git a/bitcoin/src/consensus_validation.rs b/bitcoin/src/consensus_validation.rs index d3d67f0ea..b461374d1 100644 --- a/bitcoin/src/consensus_validation.rs +++ b/bitcoin/src/consensus_validation.rs @@ -4,8 +4,8 @@ //! //! Relies on the `bitcoinconsensus` crate that uses Bitcoin Core libconsensus to perform validation. -use core::fmt; use core::convert::Infallible; +use core::fmt; use internals::write_err; diff --git a/bitcoin/src/crypto/ecdsa.rs b/bitcoin/src/crypto/ecdsa.rs index 90e6d105e..58c0b028b 100644 --- a/bitcoin/src/crypto/ecdsa.rs +++ b/bitcoin/src/crypto/ecdsa.rs @@ -4,9 +4,9 @@ //! //! This module provides ECDSA signatures used by Bitcoin that can be roundtrip (de)serialized. +use core::convert::Infallible; use core::str::FromStr; use core::{fmt, iter}; -use core::convert::Infallible; #[cfg(feature = "arbitrary")] use arbitrary::{Arbitrary, Unstructured}; diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs index e51350afa..c3f3affe8 100644 --- a/bitcoin/src/crypto/key.rs +++ b/bitcoin/src/crypto/key.rs @@ -5,10 +5,10 @@ //! This module provides keys used in Bitcoin that can be roundtrip //! (de)serialized. +use core::convert::Infallible; use core::fmt::{self, Write as _}; use core::ops; use core::str::FromStr; -use core::convert::Infallible; use hashes::hash160; use hex::{FromHex, HexToArrayError}; diff --git a/bitcoin/src/crypto/sighash.rs b/bitcoin/src/crypto/sighash.rs index 6c7a0664d..83a82433b 100644 --- a/bitcoin/src/crypto/sighash.rs +++ b/bitcoin/src/crypto/sighash.rs @@ -11,8 +11,8 @@ //! handle its complexity efficiently. Computing these hashes is as simple as creating //! [`SighashCache`] and calling its methods. -use core::{fmt, str}; use core::convert::Infallible; +use core::{fmt, str}; #[cfg(feature = "arbitrary")] use arbitrary::{Arbitrary, Unstructured}; diff --git a/bitcoin/src/crypto/taproot.rs b/bitcoin/src/crypto/taproot.rs index fed166e30..a0c73309e 100644 --- a/bitcoin/src/crypto/taproot.rs +++ b/bitcoin/src/crypto/taproot.rs @@ -4,8 +4,8 @@ //! //! This module provides Taproot keys used in Bitcoin (including reexporting secp256k1 keys). -use core::fmt; use core::convert::Infallible; +use core::fmt; #[cfg(feature = "arbitrary")] use arbitrary::{Arbitrary, Unstructured}; diff --git a/bitcoin/src/merkle_tree/block.rs b/bitcoin/src/merkle_tree/block.rs index 73a0adb67..e39fab19a 100644 --- a/bitcoin/src/merkle_tree/block.rs +++ b/bitcoin/src/merkle_tree/block.rs @@ -9,8 +9,8 @@ //! //! Support proofs that transaction(s) belong to a block. -use core::fmt; use core::convert::Infallible; +use core::fmt; use internals::ToU64 as _; use io::{BufRead, Write}; diff --git a/bitcoin/src/psbt/error.rs b/bitcoin/src/psbt/error.rs index 35f38146f..dcf244ad3 100644 --- a/bitcoin/src/psbt/error.rs +++ b/bitcoin/src/psbt/error.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: CC0-1.0 -use core::fmt; use core::convert::Infallible; +use core::fmt; use internals::write_err; diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs index 2e7b45efc..184e785ae 100644 --- a/bitcoin/src/psbt/mod.rs +++ b/bitcoin/src/psbt/mod.rs @@ -13,8 +13,8 @@ mod map; pub mod raw; pub mod serialize; -use core::{cmp, fmt}; use core::convert::Infallible; +use core::{cmp, fmt}; #[cfg(feature = "std")] use std::collections::{HashMap, HashSet}; @@ -1154,9 +1154,9 @@ impl std::error::Error for IndexOutOfBoundsError { #[cfg(feature = "base64")] mod display_from_str { + use core::convert::Infallible; use core::fmt; use core::str::FromStr; - use core::convert::Infallible; use base64::display::Base64Display; use base64::prelude::{Engine as _, BASE64_STANDARD}; diff --git a/bitcoin/src/sign_message.rs b/bitcoin/src/sign_message.rs index 979a174c9..045544d5e 100644 --- a/bitcoin/src/sign_message.rs +++ b/bitcoin/src/sign_message.rs @@ -21,8 +21,8 @@ pub const BITCOIN_SIGNED_MSG_PREFIX: &[u8] = b"\x18Bitcoin Signed Message:\n"; #[cfg(feature = "secp-recovery")] mod message_signing { - use core::fmt; use core::convert::Infallible; + use core::fmt; use hashes::sha256d; use internals::write_err; diff --git a/bitcoin/src/taproot/mod.rs b/bitcoin/src/taproot/mod.rs index 53a3f95ea..50ea6c257 100644 --- a/bitcoin/src/taproot/mod.rs +++ b/bitcoin/src/taproot/mod.rs @@ -8,9 +8,9 @@ pub mod merkle_branch; pub mod serialized_signature; use core::cmp::{Ordering, Reverse}; +use core::convert::Infallible; use core::fmt; use core::iter::FusedIterator; -use core::convert::Infallible; use hashes::{sha256t, HashEngine}; use internals::{impl_to_hex_from_lower_hex, write_err}; diff --git a/chacha20_poly1305/src/poly1305.rs b/chacha20_poly1305/src/poly1305.rs index 0b277b01f..4aef1343c 100644 --- a/chacha20_poly1305/src/poly1305.rs +++ b/chacha20_poly1305/src/poly1305.rs @@ -197,12 +197,12 @@ fn prepare_padded_message_slice(msg: &[u8], is_last: bool) -> [u32; 5] { let m0 = u32::from_le_bytes(fmt_msg[0..4].try_into().expect("Valid subset of 32.")) & BITMASK; let m1 = (u32::from_le_bytes(fmt_msg[3..7].try_into().expect("Valid subset of 32.")) >> 2) & BITMASK; - let m2 = - (u32::from_le_bytes(fmt_msg[6..10].try_into().expect("Valid subset of 32.")) >> 4) & BITMASK; - let m3 = - (u32::from_le_bytes(fmt_msg[9..13].try_into().expect("Valid subset of 32.")) >> 6) & BITMASK; - let m4 = - (u32::from_le_bytes(fmt_msg[12..16].try_into().expect("Valid subset of 32.")) >> 8) | hi_bit; + let m2 = (u32::from_le_bytes(fmt_msg[6..10].try_into().expect("Valid subset of 32.")) >> 4) + & BITMASK; + let m3 = (u32::from_le_bytes(fmt_msg[9..13].try_into().expect("Valid subset of 32.")) >> 6) + & BITMASK; + let m4 = (u32::from_le_bytes(fmt_msg[12..16].try_into().expect("Valid subset of 32.")) >> 8) + | hi_bit; [m0, m1, m2, m3, m4] } diff --git a/units/src/amount/tests.rs b/units/src/amount/tests.rs index ecd813ffd..d6becf50f 100644 --- a/units/src/amount/tests.rs +++ b/units/src/amount/tests.rs @@ -19,7 +19,10 @@ use crate::{FeeRate, Weight}; #[test] fn sanity_check() { assert_eq!(SignedAmount::from_sat(-100).abs(), SignedAmount::from_sat(100)); - assert_eq!(SignedAmount::from_sat(i64::MIN + 1).checked_abs().unwrap(), SignedAmount::from_sat(i64::MAX)); + assert_eq!( + SignedAmount::from_sat(i64::MIN + 1).checked_abs().unwrap(), + SignedAmount::from_sat(i64::MAX) + ); assert_eq!(SignedAmount::from_sat(-100).signum(), -1); assert_eq!(SignedAmount::from_sat(0).signum(), 0); assert_eq!(SignedAmount::from_sat(100).signum(), 1); @@ -30,8 +33,14 @@ fn sanity_check() { #[cfg(feature = "alloc")] { - assert_eq!(Amount::from_float_in(0_f64, Denomination::Bitcoin).unwrap(), Amount::from_sat(0)); - assert_eq!(Amount::from_float_in(2_f64, Denomination::Bitcoin).unwrap(), Amount::from_sat(200_000_000)); + assert_eq!( + Amount::from_float_in(0_f64, Denomination::Bitcoin).unwrap(), + Amount::from_sat(0) + ); + assert_eq!( + Amount::from_float_in(2_f64, Denomination::Bitcoin).unwrap(), + Amount::from_sat(200_000_000) + ); assert!(Amount::from_float_in(-100_f64, Denomination::Bitcoin).is_err()); } } @@ -170,15 +179,24 @@ fn checked_arithmetic() { #[test] #[allow(deprecated_in_future)] fn unchecked_arithmetic() { - assert_eq!(SignedAmount::from_sat(10).unchecked_add(SignedAmount::from_sat(20)), SignedAmount::from_sat(30)); - assert_eq!(SignedAmount::from_sat(50).unchecked_sub(SignedAmount::from_sat(10)), SignedAmount::from_sat(40)); + assert_eq!( + SignedAmount::from_sat(10).unchecked_add(SignedAmount::from_sat(20)), + SignedAmount::from_sat(30) + ); + assert_eq!( + SignedAmount::from_sat(50).unchecked_sub(SignedAmount::from_sat(10)), + SignedAmount::from_sat(40) + ); assert_eq!(Amount::from_sat(5).unchecked_add(Amount::from_sat(7)), Amount::from_sat(12)); assert_eq!(Amount::from_sat(10).unchecked_sub(Amount::from_sat(7)), Amount::from_sat(3)); } #[test] fn positive_sub() { - assert_eq!(SignedAmount::from_sat(10).positive_sub(SignedAmount::from_sat(7)).unwrap(), SignedAmount::from_sat(3)); + assert_eq!( + SignedAmount::from_sat(10).positive_sub(SignedAmount::from_sat(7)).unwrap(), + SignedAmount::from_sat(3) + ); assert!(SignedAmount::from_sat(-10).positive_sub(SignedAmount::from_sat(7)).is_none()); assert!(SignedAmount::from_sat(10).positive_sub(SignedAmount::from_sat(-7)).is_none()); assert!(SignedAmount::from_sat(10).positive_sub(SignedAmount::from_sat(11)).is_none()); @@ -795,7 +813,10 @@ fn serde_as_str() { } serde_test::assert_tokens( - &T { amt: Amount::from_sat_unchecked(123_456_789), samt: SignedAmount::from_sat_unchecked(-123_456_789) }, + &T { + amt: Amount::from_sat_unchecked(123_456_789), + samt: SignedAmount::from_sat_unchecked(-123_456_789), + }, &[ serde_test::Token::Struct { name: "T", len: 2 }, serde_test::Token::String("amt"), diff --git a/units/src/block.rs b/units/src/block.rs index 8eaca0da4..49bd88ac9 100644 --- a/units/src/block.rs +++ b/units/src/block.rs @@ -289,7 +289,8 @@ mod tests { let interval_from_height: BlockInterval = relative::Height::from(10u16).into(); assert_eq!(interval_from_height.to_u32(), 10u32); - let invalid_height_greater = relative::Height::try_from(BlockInterval(u32::from(u16::MAX) + 1)); + let invalid_height_greater = + relative::Height::try_from(BlockInterval(u32::from(u16::MAX) + 1)); assert!(invalid_height_greater.is_err()); let valid_height = relative::Height::try_from(BlockInterval(u32::from(u16::MAX))); @@ -314,8 +315,16 @@ mod tests { // interval - interval = interval assert!(BlockInterval(10) - BlockInterval(7) == BlockInterval(3)); - assert!([BlockInterval(1), BlockInterval(2), BlockInterval(3)].iter().sum::() == BlockInterval(6)); - assert!([BlockInterval(4), BlockInterval(5), BlockInterval(6)].into_iter().sum::() == BlockInterval(15)); + assert!( + [BlockInterval(1), BlockInterval(2), BlockInterval(3)].iter().sum::() + == BlockInterval(6) + ); + assert!( + [BlockInterval(4), BlockInterval(5), BlockInterval(6)] + .into_iter() + .sum::() + == BlockInterval(15) + ); // interval += interval let mut int = BlockInterval(1); diff --git a/units/src/fee_rate/serde.rs b/units/src/fee_rate/serde.rs index 486b01fe9..cd914c322 100644 --- a/units/src/fee_rate/serde.rs +++ b/units/src/fee_rate/serde.rs @@ -22,8 +22,8 @@ //! } //! ``` -use core::fmt; use core::convert::Infallible; +use core::fmt; pub mod as_sat_per_kwu { //! Serialize and deserialize [`FeeRate`] denominated in satoshis per 1000 weight units. diff --git a/units/src/parse.rs b/units/src/parse.rs index 49f4064b7..08f0cf464 100644 --- a/units/src/parse.rs +++ b/units/src/parse.rs @@ -567,7 +567,6 @@ mod tests { let want = 171; // 0xab assert_eq!(hex_u32_prefixed("0xab").unwrap(), want); assert!(hex_u32_unprefixed("0xab").is_err()); - } #[test] @@ -596,7 +595,6 @@ mod tests { let want = 3_735_928_559; assert_eq!(hex_u128_prefixed("0xdeadbeef").unwrap(), want); assert!(hex_u128_unprefixed("0xdeadbeef").is_err()); - } #[test]