From e3c16361b6f503a078de2aa757b9179dc352594e Mon Sep 17 00:00:00 2001 From: han0110 Date: Mon, 9 Oct 2023 14:03:06 +0800 Subject: [PATCH] fix: clippy errors --- src/codegen/evaluator.rs | 36 ++++++++++-------------------------- src/codegen/pcs.rs | 4 ++-- src/codegen/template.rs | 2 +- src/evm.rs | 12 +++++------- 4 files changed, 18 insertions(+), 36 deletions(-) diff --git a/src/codegen/evaluator.rs b/src/codegen/evaluator.rs index b7517ed..b22e8d6 100644 --- a/src/codegen/evaluator.rs +++ b/src/codegen/evaluator.rs @@ -10,7 +10,7 @@ use halo2_proofs::{ }; use itertools::{chain, izip, Itertools}; use ruint::aliases::U256; -use std::{borrow::Borrow, cell::RefCell, cmp::Ordering, collections::HashMap, iter}; +use std::{cell::RefCell, cmp::Ordering, collections::HashMap, iter}; #[derive(Debug)] pub(crate) struct Evaluator<'a, F: PrimeField> { @@ -340,34 +340,18 @@ fn u256_string(value: U256) -> String { } fn fixed_eval_var(fixed_query: FixedQuery) -> String { - let column_index = fixed_query.column_index(); - let rotation = fixed_query.rotation().0; - match rotation.cmp(&0) { - Ordering::Less => { - format!("f_{}_prev_{}", column_index, rotation.abs()) - } - Ordering::Equal => { - format!("f_{}", column_index) - } - Ordering::Greater => { - format!("f_{}_next_{}", column_index, rotation) - } - } + column_eval_var("f", fixed_query.column_index(), fixed_query.rotation().0) } fn advice_eval_var(advice_query: AdviceQuery) -> String { - let column_index = advice_query.column_index(); - let rotation = advice_query.rotation().0; + column_eval_var("a", advice_query.column_index(), advice_query.rotation().0) +} + +fn column_eval_var(prefix: &'static str, column_index: usize, rotation: i32) -> String { match rotation.cmp(&0) { - Ordering::Less => { - format!("a_{}_prev_{}", column_index, rotation.abs()) - } - Ordering::Equal => { - format!("a_{}", column_index) - } - Ordering::Greater => { - format!("a_{}_next_{}", column_index, rotation) - } + Ordering::Less => format!("{prefix}_{column_index}_prev_{}", rotation.abs()), + Ordering::Equal => format!("{prefix}_{column_index}"), + Ordering::Greater => format!("{prefix}_{column_index}_next_{rotation}"), } } @@ -392,7 +376,7 @@ where expr, constant, fixed, advice, instance, challenge, negated, sum, product, scaled, ) }; - match expression.borrow() { + match expression { Expression::Constant(scalar) => constant(fe_to_u256(*scalar)), Expression::Selector(_) => unreachable!(), Expression::Fixed(query) => fixed(*query), diff --git a/src/codegen/pcs.rs b/src/codegen/pcs.rs index 89354cf..8b814db 100644 --- a/src/codegen/pcs.rs +++ b/src/codegen/pcs.rs @@ -431,7 +431,7 @@ pub(crate) fn bdfg21_computations(meta: &ConstraintSystemMeta, data: &Data) -> V for_loop( [ format!("let mptr := 0x00"), - format!("let mptr_end := {}", second_batch_invert_end), + format!("let mptr_end := {second_batch_invert_end}"), format!("let sum_mptr := {}", sums[0].ptr()), ], "lt(mptr, mptr_end)", @@ -449,7 +449,7 @@ pub(crate) fn bdfg21_computations(meta: &ConstraintSystemMeta, data: &Data) -> V for_loop( [ format!("let sum_inv_mptr := {}", second_batch_invert_end - 2), - format!("let sum_inv_mptr_end := {}", second_batch_invert_end), + format!("let sum_inv_mptr_end := {second_batch_invert_end}"), format!("let r_eval_mptr := {}", r_evals[r_evals.len() - 2].ptr()), ], "lt(sum_inv_mptr, sum_inv_mptr_end)", diff --git a/src/codegen/template.rs b/src/codegen/template.rs index 218ac63..e25f723 100644 --- a/src/codegen/template.rs +++ b/src/codegen/template.rs @@ -73,7 +73,7 @@ mod filters { } pub fn hex_padded(value: impl LowerHex, pad: usize) -> ::askama::Result { - let string = format!("0x{value:0pad$x}", pad = pad); + let string = format!("0x{value:0pad$x}"); if string == "0x0" { Ok(format!("0x{}", "0".repeat(pad))) } else { diff --git a/src/evm.rs b/src/evm.rs index c442694..16ba59f 100644 --- a/src/evm.rs +++ b/src/evm.rs @@ -196,20 +196,18 @@ pub(crate) mod test { for (log_idx, log) in logs.iter().enumerate() { println!("log#{log_idx}"); for (topic_idx, topic) in log.topics.iter().enumerate() { - println!(" topic{topic_idx}: {:?}", topic); + println!(" topic{topic_idx}: {topic:?}"); } } println!("--- end ---"); } (gas_used, output) } - ExecutionResult::Revert { gas_used, output } => panic!( - "Transaction reverts with gas_used {gas_used} and output {:#x}", - output - ), + ExecutionResult::Revert { gas_used, output } => { + panic!("Transaction reverts with gas_used {gas_used} and output {output:#x}") + } ExecutionResult::Halt { reason, gas_used } => panic!( - "Transaction halts unexpectedly with gas_used {gas_used} and reason {:?}", - reason + "Transaction halts unexpectedly with gas_used {gas_used} and reason {reason:?}" ), } }