Skip to content

Commit

Permalink
Merge rust-bitcoin#3895: Automated nightly rustfmt (2025-01-12)
Browse files Browse the repository at this point in the history
8bdd67a 2025-01-12 automated rustfmt nightly (Fmt Bot)

Pull request description:

  Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  apoelstra:
    ACK 8bdd67a; successfully ran local tests

Tree-SHA512: c408f90b2df821f4b940e1c99a85f1c7bc4f4983b2f39ebe15bb2ff8a4620ef4196f28f3ee2ce791dbd2a71f050ff841df455be6cba148c5278541a10bbca826
  • Loading branch information
apoelstra committed Jan 12, 2025
2 parents cee2308 + 8bdd67a commit 9a03d6b
Show file tree
Hide file tree
Showing 26 changed files with 72 additions and 41 deletions.
2 changes: 1 addition & 1 deletion base58/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

//! Error code for the `base58` crate.
use core::fmt;
use core::convert::Infallible;
use core::fmt;

use internals::write_err;

Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/address/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Error code for the address module.
use core::fmt;
use core::convert::Infallible;
use core::fmt;

use internals::write_err;

Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/bip152.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/bip158.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _};
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/blockdata/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
5 changes: 4 additions & 1 deletion bitcoin/src/blockdata/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/blockdata/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/blockdata/script/witness_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/blockdata/script/witness_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/consensus/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _;
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/consensus_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/crypto/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/crypto/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/crypto/sighash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/crypto/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/merkle_tree/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/psbt/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: CC0-1.0

use core::fmt;
use core::convert::Infallible;
use core::fmt;

use internals::write_err;

Expand Down
4 changes: 2 additions & 2 deletions bitcoin/src/psbt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/sign_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/taproot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
12 changes: 6 additions & 6 deletions chacha20_poly1305/src/poly1305.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down
35 changes: 28 additions & 7 deletions units/src/amount/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
}
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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"),
Expand Down
15 changes: 12 additions & 3 deletions units/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion units/src/fee_rate/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions units/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 9a03d6b

Please sign in to comment.