From 442123602c9911dd474a48931e5f3fe05be862cf Mon Sep 17 00:00:00 2001 From: Himess <95512809+Himess@users.noreply.github.com> Date: Fri, 9 May 2025 10:32:54 +0300 Subject: [PATCH] fix: replace deprecated #[clap(...)] with #[command(...)] and #[arg(...)] (#413) --- CHANGELOG.md | 1 + miden-crypto/benches/merkle.rs | 4 ++-- miden-crypto/benches/smt-subtree.rs | 6 +++--- miden-crypto/benches/smt-with-entries.rs | 6 +++--- miden-crypto/benches/smt.rs | 4 +--- miden-crypto/src/hash/rescue/rpo/digest.rs | 2 +- miden-crypto/src/hash/rescue/rpx/digest.rs | 2 +- miden-crypto/src/main.rs | 8 ++++---- miden-crypto/src/merkle/mmr/partial.rs | 8 ++------ miden-crypto/src/merkle/smt/full/concurrent/tests.rs | 9 +++------ miden-crypto/src/merkle/sparse_path.rs | 6 ++---- 11 files changed, 23 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30b2376..9ef7130 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 0.15.0 (TBD) +- Replace deprecated #[clap(...)] with #[command(...)] and #[arg(...)] (#413). - Added default constructors to `MmrPeaks` and `PartialMmr` (#409). - Add module and function documentation. (#408). diff --git a/miden-crypto/benches/merkle.rs b/miden-crypto/benches/merkle.rs index b815394..270ca8c 100644 --- a/miden-crypto/benches/merkle.rs +++ b/miden-crypto/benches/merkle.rs @@ -5,7 +5,7 @@ //! tree will perform better than the sparse version. At the time of this writing (2024/11/24), this //! benchmark is about four times more efficient than the equivalent benchmark in //! `benches/smt-subtree.rs`. -use std::{hint, mem, time::Duration}; +use std::{hint, time::Duration}; use criterion::{BatchSize, Criterion, criterion_group, criterion_main}; use miden_crypto::{Felt, ONE, Word, merkle::MerkleTree}; @@ -60,7 +60,7 @@ criterion_main!(smt_subtree_group); // -------------------------------------------------------------------------------------------- fn generate_word(seed: &mut [u8; 32]) -> Word { - mem::swap(seed, &mut prng_array(*seed)); + *seed = prng_array(*seed); let nums: [u64; 4] = prng_array(*seed); [Felt::new(nums[0]), Felt::new(nums[1]), Felt::new(nums[2]), Felt::new(nums[3])] } diff --git a/miden-crypto/benches/smt-subtree.rs b/miden-crypto/benches/smt-subtree.rs index 315ba3b..b2bc677 100644 --- a/miden-crypto/benches/smt-subtree.rs +++ b/miden-crypto/benches/smt-subtree.rs @@ -1,4 +1,4 @@ -use std::{fmt::Debug, hint, mem, time::Duration}; +use std::{fmt::Debug, hint, time::Duration}; use criterion::{BatchSize, BenchmarkId, Criterion, criterion_group, criterion_main}; use miden_crypto::{ @@ -131,13 +131,13 @@ criterion_main!(smt_subtree_group); // -------------------------------------------------------------------------------------------- fn generate_value(seed: &mut [u8; 32]) -> T { - mem::swap(seed, &mut prng_array(*seed)); + *seed = prng_array(*seed); let value: [T; 1] = rand_utils::prng_array(*seed); value[0] } fn generate_word(seed: &mut [u8; 32]) -> Word { - mem::swap(seed, &mut prng_array(*seed)); + *seed = prng_array(*seed); let nums: [u64; 4] = prng_array(*seed); [Felt::new(nums[0]), Felt::new(nums[1]), Felt::new(nums[2]), Felt::new(nums[3])] } diff --git a/miden-crypto/benches/smt-with-entries.rs b/miden-crypto/benches/smt-with-entries.rs index a9ca097..cb7cd85 100644 --- a/miden-crypto/benches/smt-with-entries.rs +++ b/miden-crypto/benches/smt-with-entries.rs @@ -1,4 +1,4 @@ -use std::{fmt::Debug, hint, mem, time::Duration}; +use std::{fmt::Debug, hint, time::Duration}; use criterion::{BatchSize, BenchmarkId, Criterion, criterion_group, criterion_main}; use miden_crypto::{Felt, ONE, Word, hash::rpo::RpoDigest, merkle::Smt}; @@ -59,13 +59,13 @@ fn prepare_entries(pair_count: u64, seed: &mut [u8; 32]) -> Vec<(RpoDigest, [Fel } fn generate_value(seed: &mut [u8; 32]) -> T { - mem::swap(seed, &mut prng_array(*seed)); + *seed = prng_array(*seed); let value: [T; 1] = rand_utils::prng_array(*seed); value[0] } fn generate_word(seed: &mut [u8; 32]) -> Word { - mem::swap(seed, &mut prng_array(*seed)); + *seed = prng_array(*seed); let nums: [u64; 4] = prng_array(*seed); [Felt::new(nums[0]), Felt::new(nums[1]), Felt::new(nums[2]), Felt::new(nums[3])] } diff --git a/miden-crypto/benches/smt.rs b/miden-crypto/benches/smt.rs index f8a81c9..6a5b700 100644 --- a/miden-crypto/benches/smt.rs +++ b/miden-crypto/benches/smt.rs @@ -1,5 +1,3 @@ -use core::mem::swap; - use criterion::{Criterion, black_box, criterion_group, criterion_main}; use miden_crypto::{ Felt, Word, @@ -71,7 +69,7 @@ criterion_main!(smt_group); // -------------------------------------------------------------------------------------------- fn generate_word(seed: &mut [u8; 32]) -> Word { - swap(seed, &mut prng_array(*seed)); + *seed = prng_array(*seed); let nums: [u64; 4] = prng_array(*seed); [Felt::new(nums[0]), Felt::new(nums[1]), Felt::new(nums[2]), Felt::new(nums[3])] } diff --git a/miden-crypto/src/hash/rescue/rpo/digest.rs b/miden-crypto/src/hash/rescue/rpo/digest.rs index 961a104..00bef42 100644 --- a/miden-crypto/src/hash/rescue/rpo/digest.rs +++ b/miden-crypto/src/hash/rescue/rpo/digest.rs @@ -126,7 +126,7 @@ impl PartialOrd for RpoDigest { impl Display for RpoDigest { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let encoded: String = self.into(); - write!(f, "{}", encoded)?; + write!(f, "{encoded}")?; Ok(()) } } diff --git a/miden-crypto/src/hash/rescue/rpx/digest.rs b/miden-crypto/src/hash/rescue/rpx/digest.rs index 9b83c72..f847f40 100644 --- a/miden-crypto/src/hash/rescue/rpx/digest.rs +++ b/miden-crypto/src/hash/rescue/rpx/digest.rs @@ -108,7 +108,7 @@ impl PartialOrd for RpxDigest { impl Display for RpxDigest { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let encoded: String = self.into(); - write!(f, "{}", encoded)?; + write!(f, "{encoded}")?; Ok(()) } } diff --git a/miden-crypto/src/main.rs b/miden-crypto/src/main.rs index 8559e9f..f999b78 100644 --- a/miden-crypto/src/main.rs +++ b/miden-crypto/src/main.rs @@ -10,16 +10,16 @@ use rand::{Rng, prelude::IteratorRandom, rng}; use rand_utils::rand_value; #[derive(Parser, Debug)] -#[clap(name = "Benchmark", about = "SMT benchmark", version, rename_all = "kebab-case")] +#[command(name = "Benchmark", about = "SMT benchmark", version, rename_all = "kebab-case")] pub struct BenchmarkCmd { /// Size of the tree - #[clap(short = 's', long = "size", default_value = "1000000")] + #[arg(short = 's', long = "size", default_value = "1000000")] size: usize, /// Number of insertions - #[clap(short = 'i', long = "insertions", default_value = "1000")] + #[arg(short = 'i', long = "insertions", default_value = "1000")] insertions: usize, /// Number of updates - #[clap(short = 'u', long = "updates", default_value = "1000")] + #[arg(short = 'u', long = "updates", default_value = "1000")] updates: usize, } diff --git a/miden-crypto/src/merkle/mmr/partial.rs b/miden-crypto/src/merkle/mmr/partial.rs index 310f55e..5edd2e5 100644 --- a/miden-crypto/src/merkle/mmr/partial.rs +++ b/miden-crypto/src/merkle/mmr/partial.rs @@ -246,9 +246,7 @@ impl PartialMmr { debug_assert!( old.is_none(), - "Idx {:?} already contained an element {:?}", - left_idx, - old + "Idx {left_idx:?} already contained an element {old:?}", ); }; if track_left { @@ -257,9 +255,7 @@ impl PartialMmr { debug_assert!( old.is_none(), - "Idx {:?} already contained an element {:?}", - right_idx, - old + "Idx {right_idx:?} already contained an element {old:?}", ); }; diff --git a/miden-crypto/src/merkle/smt/full/concurrent/tests.rs b/miden-crypto/src/merkle/smt/full/concurrent/tests.rs index f6e5c9b..fe266e3 100644 --- a/miden-crypto/src/merkle/smt/full/concurrent/tests.rs +++ b/miden-crypto/src/merkle/smt/full/concurrent/tests.rs @@ -247,8 +247,7 @@ fn test_singlethreaded_subtrees() { let control_node = control.get_inner_node(index); assert_eq!( test_node, &control_node, - "depth {} subtree {}: test node does not match control at index {:?}", - current_depth, i, index, + "depth {current_depth} subtree {i}: test node does not match control at index {index:?}", ); } (nodes, subtree_root) @@ -329,8 +328,7 @@ fn test_multithreaded_subtrees() { let control_node = control.get_inner_node(index); assert_eq!( test_node, &control_node, - "depth {} subtree {}: test node does not match control at index {:?}", - current_depth, i, index, + "depth {current_depth} subtree {i}: test node does not match control at index {index:?}", ); } (nodes, subtree_root) @@ -428,8 +426,7 @@ fn test_singlethreaded_subtree_mutations() { let control_mutation = control.node_mutations().get(&index).unwrap(); assert_eq!( control_mutation, mutation, - "depth {} subtree {}: mutation does not match control at index {:?}", - current_depth, i, index, + "depth {current_depth} subtree {i}: mutation does not match control at index {index:?}", ); } (mutations_per_subtree, subtree_root) diff --git a/miden-crypto/src/merkle/sparse_path.rs b/miden-crypto/src/merkle/sparse_path.rs index 5bdaa80..3862c0d 100644 --- a/miden-crypto/src/merkle/sparse_path.rs +++ b/miden-crypto/src/merkle/sparse_path.rs @@ -154,16 +154,14 @@ impl Deserializable for SparseMerklePath { let depth = source.read_u8()?; if depth > SMT_MAX_DEPTH { return Err(DeserializationError::InvalidValue(format!( - "SparseMerklePath max depth exceeded ({} > {})", - depth, SMT_MAX_DEPTH + "SparseMerklePath max depth exceeded ({depth} > {SMT_MAX_DEPTH})", ))); } let empty_nodes_mask = source.read_u64()?; let empty_nodes_count = empty_nodes_mask.count_ones(); if empty_nodes_count > depth as u32 { return Err(DeserializationError::InvalidValue(format!( - "SparseMerklePath has more empty nodes ({}) than its full length ({})", - empty_nodes_count, depth + "SparseMerklePath has more empty nodes ({empty_nodes_count}) than its full length ({depth})", ))); } let count = depth as u32 - empty_nodes_count;