From 40306cdaa730a7ea651f31b0e1029dae5ded0eba Mon Sep 17 00:00:00 2001 From: Davidson Souza Date: Sat, 8 Jun 2024 12:15:21 -0300 Subject: [PATCH] fix some linting suggestions --- src/accumulator/pollard.rs | 16 ++++++++-------- src/accumulator/util.rs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/accumulator/pollard.rs b/src/accumulator/pollard.rs index 194ae81..6bc2af0 100644 --- a/src/accumulator/pollard.rs +++ b/src/accumulator/pollard.rs @@ -77,10 +77,9 @@ impl Node { .replace(NodeHash::parent_hash(&left.data.get(), &right.data.get())); } if let Some(ref parent) = *self.parent.borrow() { - parent.upgrade().and_then(|p| { + if let Some(p) = parent.upgrade() { p.recompute_hashes(); - Some(()) - }); + } } } /// Writes one node to the writer, this method will recursively write all children. @@ -344,17 +343,19 @@ impl Pollard { for row in (0..(branch_len)).rev() { // Parent is the sibling of the current node as each of the // nodes point to their nieces. - parent = sibling; + parent.clone_from(&sibling); // Figure out which node we need to follow. let niece_pos = ((bits >> row) & 1) as u8; + + #[allow(clippy::assigning_clones)] if let Some(node) = n { if is_left_niece(niece_pos as u64) { n = node.right.borrow().clone(); - sibling = node.left.borrow().clone(); + sibling.clone_from(&*node.left.borrow()); } else { n = node.left.borrow().clone(); - sibling = node.right.borrow().clone(); + sibling.clone_from(&*node.right.borrow()); } } else { sibling = None; @@ -410,8 +411,7 @@ impl Pollard { while let Some(parent) = node.parent.clone().into_inner() { let parent_left = parent .upgrade() - .map(|parent| parent.left.clone().into_inner()) - .flatten() + .and_then(|parent| parent.left.clone().into_inner()) .unwrap() .clone(); diff --git a/src/accumulator/util.rs b/src/accumulator/util.rs index ec19c8f..a3d025b 100644 --- a/src/accumulator/util.rs +++ b/src/accumulator/util.rs @@ -18,11 +18,11 @@ pub fn is_root_position(position: u64, num_leaves: u64, forest_rows: u8) -> bool // bit is to be removed from 1011 (11 in dec), the returned value is 111 (7 in dec). pub fn remove_bit(val: u64, bit: u64) -> u64 { let mask = ((2 << bit) - 1) as u64; - let upper_mask = std::u64::MAX ^ mask; + let upper_mask = u64::MAX ^ mask; let upper = val & upper_mask; let mask = ((1 << bit) - 1) as u64; - let lower_mask = !(std::u64::MAX ^ mask); + let lower_mask = !(u64::MAX ^ mask); let lower = val & lower_mask; (upper >> 1) | lower