Skip to content

Commit

Permalink
Merge pull request #434 from Chia-Network/clippy-fix
Browse files Browse the repository at this point in the history
Clippy fixes
  • Loading branch information
jack60612 authored Jul 11, 2024
2 parents c95a1f4 + 203f88d commit 1d84646
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/run_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl<'a, D: Dialect> RunProgramContext<'a, D> {
Operation::PostEval => {
let f = self.posteval_stack.pop().unwrap();
let peek: Option<NodePtr> = self.val_stack.last().copied();
f(&mut self.allocator, peek);
f(self.allocator, peek);
0
}
};
Expand Down
54 changes: 27 additions & 27 deletions src/test_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ use std::collections::HashSet;
#[cfg(feature = "pre-eval")]
use std::rc::Rc;

#[cfg(feature = "pre-eval")]
type Callback = Box<dyn Fn(&mut Allocator, Option<NodePtr>)>;

#[cfg(feature = "pre-eval")]
type PreEvalF = Box<dyn Fn(&mut Allocator, NodePtr, NodePtr) -> Result<Option<Callback>, EvalErr>>;

// Ensure pre_eval_f and post_eval_f are working as expected.
#[cfg(feature = "pre-eval")]
#[test]
Expand Down Expand Up @@ -410,13 +416,7 @@ fn test_pre_eval_and_post_eval() {

let tracking = Rc::new(RefCell::new(HashMap::new()));
let pre_eval_tracking = tracking.clone();
let pre_eval_f: Box<
dyn Fn(
&mut Allocator,
NodePtr,
NodePtr,
) -> Result<Option<Box<(dyn Fn(&mut Allocator, Option<NodePtr>))>>, EvalErr>,
> = Box::new(move |_allocator, prog, args| {
let pre_eval_f: PreEvalF = Box::new(move |_allocator, prog, args| {
let tracking_key = pre_eval_tracking.borrow().len();
// Ensure lifetime of mutable borrow is contained.
// It must end before the lifetime of the following closure.
Expand All @@ -432,18 +432,17 @@ fn test_pre_eval_and_post_eval() {
);
}
let post_eval_tracking = pre_eval_tracking.clone();
let post_eval_f: Box<dyn Fn(&mut Allocator, Option<NodePtr>)> =
Box::new(move |_a, outcome| {
let mut tracking_mutable = post_eval_tracking.borrow_mut();
tracking_mutable.insert(
tracking_key,
EvalFTracker {
prog,
args,
outcome,
},
);
});
let post_eval_f: Callback = Box::new(move |_a, outcome| {
let mut tracking_mutable = post_eval_tracking.borrow_mut();
tracking_mutable.insert(
tracking_key,
EvalFTracker {
prog,
args,
outcome,
},
);
});
Ok(Some(post_eval_f))
});

Expand Down Expand Up @@ -471,14 +470,15 @@ fn test_pre_eval_and_post_eval() {
// args consed
let args_consed = allocator.new_pair(a99, a101).unwrap();

let mut desired_outcomes = Vec::new(); // Not in order.
desired_outcomes.push((args, NodePtr::NIL, arg_mid));
desired_outcomes.push((f_quoted, NodePtr::NIL, f_expr));
desired_outcomes.push((a2, arg_mid, a99));
desired_outcomes.push((a5, arg_mid, a101));
desired_outcomes.push((cons_expr, arg_mid, args_consed));
desired_outcomes.push((f_expr, arg_mid, a99));
desired_outcomes.push((program, NodePtr::NIL, a99));
let desired_outcomes = [
(args, NodePtr::NIL, arg_mid),
(f_quoted, NodePtr::NIL, f_expr),
(a2, arg_mid, a99),
(a5, arg_mid, a101),
(cons_expr, arg_mid, args_consed),
(f_expr, arg_mid, a99),
(program, NodePtr::NIL, a99),
];

let mut found_outcomes = HashSet::new();
let tracking_examine = tracking.borrow();
Expand Down
6 changes: 0 additions & 6 deletions wasm/src/run_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ use clvmr::cost::Cost;
use clvmr::run_program::run_program;
use clvmr::serde::{node_from_bytes, node_from_bytes_backrefs, node_to_bytes};

// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

#[wasm_bindgen]
pub struct Flag;

Expand Down

0 comments on commit 1d84646

Please sign in to comment.