Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions bitcoin/src/merkle_tree/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,12 @@ impl<'a> Arbitrary<'a> for MerkleBlock {

#[cfg(test)]
mod tests {
use hex::{DisplayHex, FromHex};
use hex_lit::hex;
#[cfg(feature = "std")]
use core::cmp;

use hex::{DisplayHex, FromHex};
use hex_lit::hex;

use super::*;
use crate::block::Unchecked;
use crate::consensus::encode;
Expand All @@ -555,11 +556,7 @@ mod tests {
const P: usize = 1039;
const Q: usize = 677;

const fn new(seed: usize) -> Self {
Self {
state: seed
}
}
const fn new(seed: usize) -> Self { Self { state: seed } }

#[inline]
fn next_usize(&mut self) -> usize {
Expand All @@ -568,14 +565,10 @@ mod tests {
}

#[inline]
fn next_in_range(&mut self, max: usize) -> usize {
self.next_usize() % max
}
fn next_in_range(&mut self, max: usize) -> usize { self.next_usize() % max }

#[inline]
fn next_u8(&mut self) -> u8 {
self.next_usize().to_le_bytes()[0]
}
fn next_u8(&mut self) -> u8 { self.next_usize().to_le_bytes()[0] }
}

#[cfg(feature = "std")]
Expand Down
9 changes: 6 additions & 3 deletions consensus_encoding/src/decode/decoders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ impl Decoder for ByteVecDecoder {
type Error = ByteVecDecoderError;

fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
use {ByteVecDecoderError as E, ByteVecDecoderErrorInner as Inner};
use ByteVecDecoderError as E;
use ByteVecDecoderErrorInner as Inner;

if let Some(mut decoder) = self.prefix_decoder.take() {
if decoder.push_bytes(bytes).map_err(|e| E(Inner::LengthPrefixDecode(e)))? {
Expand Down Expand Up @@ -106,7 +107,8 @@ impl Decoder for ByteVecDecoder {
}

fn end(self) -> Result<Self::Output, Self::Error> {
use {ByteVecDecoderError as E, ByteVecDecoderErrorInner as Inner};
use ByteVecDecoderError as E;
use ByteVecDecoderErrorInner as Inner;

if let Some(ref prefix_decoder) = self.prefix_decoder {
return Err(E(Inner::UnexpectedEof(UnexpectedEofError {
Expand Down Expand Up @@ -189,7 +191,8 @@ impl<T: Decodable> Decoder for VecDecoder<T> {
type Error = VecDecoderError<<<T as Decodable>::Decoder as Decoder>::Error>;

fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
use {VecDecoderError as E, VecDecoderErrorInner as Inner};
use VecDecoderError as E;
use VecDecoderErrorInner as Inner;

if let Some(mut decoder) = self.prefix_decoder.take() {
if decoder.push_bytes(bytes).map_err(|e| E(Inner::LengthPrefixDecode(e)))? {
Expand Down
2 changes: 1 addition & 1 deletion network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub mod as_core_arg {
#![allow(clippy::missing_errors_doc)]

use crate::Network;

#[allow(clippy::trivially_copy_pass_by_ref)] // `serde` controls the API.
pub fn serialize<S>(network: &Network, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down
14 changes: 6 additions & 8 deletions primitives/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,9 @@ impl Decoder for TransactionDecoder {

#[inline]
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
use {
TransactionDecoderError as E, TransactionDecoderErrorInner as Inner,
TransactionDecoderState as State,
};
use TransactionDecoderError as E;
use TransactionDecoderErrorInner as Inner;
use TransactionDecoderState as State;

loop {
// Attempt to push to the currently-active decoder and return early on success.
Expand Down Expand Up @@ -575,10 +574,9 @@ impl Decoder for TransactionDecoder {

#[inline]
fn end(self) -> Result<Self::Output, Self::Error> {
use {
TransactionDecoderError as E, TransactionDecoderErrorInner as Inner,
TransactionDecoderState as State,
};
use TransactionDecoderError as E;
use TransactionDecoderErrorInner as Inner;
use TransactionDecoderState as State;

match self.state {
State::Version(_) => Err(E(Inner::EarlyEnd("version"))),
Expand Down
6 changes: 4 additions & 2 deletions primitives/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ impl Decoder for WitnessDecoder {
type Error = WitnessDecoderError;

fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
use {WitnessDecoderError as E, WitnessDecoderErrorInner as Inner};
use WitnessDecoderError as E;
use WitnessDecoderErrorInner as Inner;

// Read initial witness element count.
if self.witness_elements.is_none() {
Expand Down Expand Up @@ -445,7 +446,8 @@ impl Decoder for WitnessDecoder {
}

fn end(mut self) -> Result<Self::Output, Self::Error> {
use {WitnessDecoderError as E, WitnessDecoderErrorInner as Inner};
use WitnessDecoderError as E;
use WitnessDecoderErrorInner as Inner;

let Some(witness_elements) = self.witness_elements else {
// Never read the witness element count.
Expand Down