Skip to content

Commit

Permalink
Fix clippy beta lints
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttycom committed Jan 31, 2025
1 parent e7ed4e0 commit 9edc305
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
12 changes: 5 additions & 7 deletions incrementalmerkletree-testing/src/complete_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<H: Hashable, C: Clone + Ord + core::fmt::Debug, const DEPTH: u8> CompleteTr
self.mark();
}
Retention::Checkpoint { id, marking } => {
let latest_checkpoint = self.checkpoints.keys().rev().next();
let latest_checkpoint = self.checkpoints.keys().next_back();
if Some(&id) > latest_checkpoint {
append(&mut self.leaves, value, DEPTH)?;
if marking == Marking::Marked {
Expand Down Expand Up @@ -145,7 +145,7 @@ impl<H: Hashable, C: Clone + Ord + core::fmt::Debug, const DEPTH: u8> CompleteTr
if !self.marks.contains(&pos) {
self.marks.insert(pos);

if let Some(checkpoint) = self.checkpoints.values_mut().rev().next() {
if let Some(checkpoint) = self.checkpoints.values_mut().next_back() {
checkpoint.marked.insert(pos);
}
}
Expand Down Expand Up @@ -277,7 +277,7 @@ impl<H: Hashable + PartialEq + Clone, C: Ord + Clone + core::fmt::Debug, const D

fn remove_mark(&mut self, position: Position) -> bool {
if self.marks.contains(&position) {
if let Some(c) = self.checkpoints.values_mut().rev().next() {
if let Some(c) = self.checkpoints.values_mut().next_back() {
c.forgotten.insert(position);
} else {
self.marks.remove(&position);
Expand All @@ -289,7 +289,7 @@ impl<H: Hashable + PartialEq + Clone, C: Ord + Clone + core::fmt::Debug, const D
}

fn checkpoint(&mut self, id: C) -> bool {
if Some(&id) > self.checkpoints.keys().rev().next() {
if Some(&id) > self.checkpoints.keys().next_back() {
Self::checkpoint(self, id, self.current_position());
true
} else {
Expand Down Expand Up @@ -335,8 +335,6 @@ impl<H: Hashable + PartialEq + Clone, C: Ord + Clone + core::fmt::Debug, const D

#[cfg(test)]
mod tests {
use std::convert::TryFrom;

use super::CompleteTree;
use crate::{
check_append, check_checkpoint_rewind, check_rewind_remove_mark, check_root_hashes,
Expand Down Expand Up @@ -432,7 +430,7 @@ mod tests {
assert_eq!(tree.root(Some(0)), Some(expected.clone()));

for i in 0u64..(1 << DEPTH) {
let position = Position::try_from(i).unwrap();
let position = Position::from(i);
let path = tree.witness(position, 0).unwrap();
assert_eq!(
compute_root_from_witness(SipHashable(i), position, &path),
Expand Down
4 changes: 2 additions & 2 deletions incrementalmerkletree-testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ pub fn check_checkpoint_rewind<C: TestCheckpoint, T: Tree<String, C>, F: Fn(usiz
}

pub fn check_remove_mark<C: TestCheckpoint, T: Tree<String, C>, F: Fn(usize) -> T>(new_tree: F) {
let samples = vec![
let samples = [
vec![
append_str("a", Retention::Ephemeral),
append_str(
Expand Down Expand Up @@ -1126,7 +1126,7 @@ pub fn check_rewind_remove_mark<C: TestCheckpoint, T: Tree<String, C>, F: Fn(usi
// test framework itself previously did not correctly handle
// chain state restoration.

let samples = vec![
let samples = [
vec![
append_str("x", Retention::Marked),
Checkpoint(C::from_u64(1)),
Expand Down
4 changes: 2 additions & 2 deletions incrementalmerkletree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,13 @@ impl Address {
/// Returns the minimum value among the range of leaf positions that are contained within the
/// tree with its root at this address.
pub fn position_range_start(&self) -> Position {
(self.index << self.level.0).try_into().unwrap()
(self.index << self.level.0).into()
}

/// Returns the (exclusive) end of the range of leaf positions that are contained within the
/// tree with its root at this address.
pub fn position_range_end(&self) -> Position {
((self.index + 1) << self.level.0).try_into().unwrap()
((self.index + 1) << self.level.0).into()
}

/// Returns the maximum value among the range of leaf positions that are contained within the
Expand Down
4 changes: 2 additions & 2 deletions shardtree/src/store/caching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ mod tests {

#[test]
fn check_remove_mark() {
let samples = vec![
let samples = [
vec![
append_str("a", Retention::Ephemeral),
append_str(
Expand Down Expand Up @@ -1128,7 +1128,7 @@ mod tests {
// test framework itself previously did not correctly handle
// chain state restoration.

let samples = vec![
let samples = [
vec![
append_str("x", Retention::Marked),
Checkpoint(1),
Expand Down
20 changes: 10 additions & 10 deletions shardtree/src/testing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::convert::TryFrom;

use assert_matches::assert_matches;
use proptest::bool::weighted;
use proptest::collection::vec;
Expand Down Expand Up @@ -96,17 +94,19 @@ where
})
}

/// A random shardtree of size up to 2^6 with shards of size 2^3, along with vectors of the
/// checkpointed and marked positions within the tree.
type ArbShardtreeParts<H> = (
ShardTree<MemoryShardStore<<H as Strategy>::Value, usize>, 6, 3>,
Vec<Position>,
Vec<Position>,
);

/// Constructs a random shardtree of size up to 2^6 with shards of size 2^3. Returns the tree,
/// along with vectors of the checkpoint and mark positions.
/// along with vectors of the checkpointed and marked positions.
pub fn arb_shardtree<H: Strategy + Clone>(
arb_leaf: H,
) -> impl Strategy<
Value = (
ShardTree<MemoryShardStore<H::Value, usize>, 6, 3>,
Vec<Position>,
Vec<Position>,
),
>
) -> impl Strategy<Value = ArbShardtreeParts<H>>
where
H::Value: Hashable + Clone + PartialEq,
{
Expand Down

0 comments on commit 9edc305

Please sign in to comment.