2025-01-12 automated rustfmt nightly

This commit is contained in:
Fmt Bot 2025-01-12 01:23:13 +00:00 committed by github-actions[bot]
parent cee2308586
commit 8bdd67a368
26 changed files with 72 additions and 41 deletions

View File

@ -2,8 +2,8 @@
//! Error code for the `base58` crate.
use core::fmt;
use core::convert::Infallible;
use core::fmt;
use internals::write_err;

View File

@ -1,7 +1,7 @@
//! Error code for the address module.
use core::fmt;
use core::convert::Infallible;
use core::fmt;
use internals::write_err;

View File

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

View File

@ -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 _};

View File

@ -5,10 +5,10 @@
//! Implementation of BIP32 hierarchical deterministic wallets, as defined
//! at <https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki>.
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;

View File

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

View File

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

View File

@ -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::*;

View File

@ -7,8 +7,8 @@
//!
//! [BIP141]: <https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki>
use core::fmt;
use core::convert::Infallible;
use core::fmt;
use internals::array_vec::ArrayVec;
use secp256k1::{Secp256k1, Verification};

View File

@ -7,9 +7,9 @@
//!
//! [BIP141]: <https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki>
use core::convert::Infallible;
use core::fmt;
use core::str::FromStr;
use core::convert::Infallible;
use internals::write_err;
use units::parse::{self, ParseIntError};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: CC0-1.0
use core::fmt;
use core::convert::Infallible;
use core::fmt;
use internals::write_err;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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>() == BlockInterval(6));
assert!([BlockInterval(4), BlockInterval(5), BlockInterval(6)].into_iter().sum::<BlockInterval>() == BlockInterval(15));
assert!(
[BlockInterval(1), BlockInterval(2), BlockInterval(3)].iter().sum::<BlockInterval>()
== BlockInterval(6)
);
assert!(
[BlockInterval(4), BlockInterval(5), BlockInterval(6)]
.into_iter()
.sum::<BlockInterval>()
== BlockInterval(15)
);
// interval += interval
let mut int = BlockInterval(1);

View File

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

View File

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