Skip to content

Commit

Permalink
Merge pull request #1265 from mintlayer/fix/clippy_173
Browse files Browse the repository at this point in the history
Appease clippy 1.73
  • Loading branch information
TheQuantumPhysicist authored Oct 9, 2023
2 parents e135879 + 0b87b3f commit f6d3f44
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 12 deletions.
3 changes: 1 addition & 2 deletions common/src/chain/block/block_body/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ mod tests {
}

fn generate_random_bytes(rng: &mut impl Rng, length: usize) -> Vec<u8> {
let mut bytes = Vec::new();
bytes.resize(length, 0);
let mut bytes = vec![0; length];
rng.fill_bytes(&mut bytes);
bytes
}
Expand Down
3 changes: 1 addition & 2 deletions common/src/chain/transaction/transaction_index/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ fn generate_random_h256(rng: &mut impl Rng) -> H256 {
}

fn generate_random_bytes(rng: &mut impl Rng, length: usize) -> Vec<u8> {
let mut bytes = Vec::new();
bytes.resize(length, 0);
let mut bytes = vec![0; length];
rng.fill_bytes(&mut bytes);
bytes
}
Expand Down
12 changes: 10 additions & 2 deletions common/src/primitives/id/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ impl H256 {
/// are viewed as a byte-array (as is the case with H256), then serializing the type will result in whatever that
/// byte-array is with no regard to endianness, which is done as big-endian in H256 if seen as a number.
pub fn as_bitcoin_uint256_hex(&self) -> String {
self.as_bytes().iter().rev().map(|b| format!("{:02x}", b)).collect()
let hex_length = self.0.len() * 2;
self.as_bytes()
.iter()
.rev()
.fold(String::with_capacity(hex_length), |mut current, b| {
use std::fmt::Write;
let _ = write!(current, "{b:02x}");
current
})
}

pub fn into_arith_uint256(self) -> Uint256 {
Expand Down Expand Up @@ -132,7 +140,7 @@ impl<T: Eq> Ord for Id<T> {
// We implement PartialOrd manually to avoid it getting inherited to T through PhantomData, because Id having PartialOrd doesn't mean T requiring Ord
impl<T: Eq> PartialOrd for Id<T> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.hash.partial_cmp(&other.hash)
Some(self.cmp(other))
}
}

Expand Down
2 changes: 1 addition & 1 deletion mempool/src/pool/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub struct ValuedOutPoint {

impl PartialOrd for ValuedOutPoint {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
other.value.partial_cmp(&self.value)
Some(self.cmp(other))
}
}

Expand Down
2 changes: 1 addition & 1 deletion merkletree/src/merkle/proof/multi/ordered_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<T, H> Eq for NodeWithAbsOrder<'_, T, H> {}

impl<T, H> PartialOrd for NodeWithAbsOrder<'_, T, H> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.node.abs_index().partial_cmp(&other.node.abs_index())
Some(self.cmp(other))
}
}

Expand Down
2 changes: 1 addition & 1 deletion storage/src/database/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<Sch> Ord for DbMapId<Sch> {

impl<Sch> PartialOrd for DbMapId<Sch> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.idx.partial_cmp(&other.idx)
Some(self.cmp(other))
}
}

Expand Down
4 changes: 1 addition & 3 deletions wallet/src/account/utxo_selector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ impl PartialEq for OutputGroupOrd {

impl PartialOrd for OutputGroupOrd {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.0
.get_effective_value(PayFee::PayFeeWithThisCurrency)
.partial_cmp(&other.0.get_effective_value(PayFee::PayFeeWithThisCurrency))
Some(self.cmp(other))
}
}

Expand Down

0 comments on commit f6d3f44

Please sign in to comment.