Skip to content

Commit

Permalink
fmt + clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed May 8, 2024
1 parent b413e5c commit c7b95ec
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 31 deletions.
40 changes: 20 additions & 20 deletions src/classic/clvm_tools/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub fn call_tool(
return Ok(());
}

let args_path_or_code_val = match args.get(&"path_or_code".to_string()) {
let args_path_or_code_val = match args.get("path_or_code") {
None => ArgumentValue::ArgArray(vec![]),
Some(v) => v.clone(),
};
Expand All @@ -214,7 +214,7 @@ pub fn call_tool(
let conv_result = task.conv.invoke(allocator, &s)?;
let sexp = *conv_result.first();
let text = conv_result.rest();
if args.contains_key(&"script_hash".to_string()) {
if args.contains_key("script_hash") {
let data: Vec<u8> = sha256tree(allocator, sexp).hex().bytes().collect();
stream.write(Bytes::new(Some(BytesFromType::Raw(data))));
} else if !text.is_empty() {
Expand Down Expand Up @@ -595,8 +595,8 @@ pub fn cldb(args: &[String]) {
}

if let Some(ArgumentValue::ArgString(file, path_or_code)) = parsed_args.get("path_or_code") {
input_file = file.clone();
input_program = path_or_code.to_string();
input_file.clone_from(file);
input_program.clone_from(path_or_code);
}

if let Some(ArgumentValue::ArgString(_, s)) = parsed_args.get("env") {
Expand Down Expand Up @@ -730,7 +730,7 @@ pub fn cldb(args: &[String]) {
Box::new(CldbNoOverride::new_symbols(use_symbol_table.clone())),
);

if parsed_args.get("tree").is_some() {
if parsed_args.contains_key("tree") {
let result = cldb_hierarchy(
runner,
Rc::new(prim_map),
Expand Down Expand Up @@ -771,9 +771,9 @@ pub fn cldb(args: &[String]) {
only_print.insert("Print".to_string(), YamlElement::String(p.clone()));
output.push(only_print);
} else {
let is_final = result.get("Final").is_some();
let is_throw = result.get("Throw").is_some();
let is_failure = result.get("Failure").is_some();
let is_final = result.contains_key("Final");
let is_throw = result.contains_key("Throw");
let is_failure = result.contains_key("Failure");
if is_final || is_throw || is_failure {
print_tree(&mut output, &result);
}
Expand Down Expand Up @@ -1189,8 +1189,8 @@ pub fn launch_tool(stdout: &mut Stream, args: &[String], tool_name: &str, defaul
let mut input_program = "()".to_string();

if let Some(ArgumentValue::ArgString(file, path_or_code)) = parsed_args.get("path_or_code") {
input_file = file.clone();
input_program = path_or_code.to_string();
input_file.clone_from(file);
input_program.clone_from(path_or_code);
}

let reported_input_file = input_file
Expand Down Expand Up @@ -1252,8 +1252,8 @@ pub fn launch_tool(stdout: &mut Stream, args: &[String], tool_name: &str, defaul
}

if let Some(ArgumentValue::ArgString(file, path_or_code)) = parsed_args.get("env") {
input_file = file.clone();
input_args = path_or_code.to_string();
input_file.clone_from(file);
input_args.clone_from(path_or_code);
}

let special_runner =
Expand Down Expand Up @@ -1317,8 +1317,8 @@ pub fn launch_tool(stdout: &mut Stream, args: &[String], tool_name: &str, defaul
if let Some(ArgumentValue::ArgString(f, content)) = parsed_args.get("path_or_code") {
match read_ir(content) {
Ok(s) => {
input_program = content.clone();
input_file = f.clone();
input_program.clone_from(content);
input_file.clone_from(f);
src_sexp = s;
}
Err(e) => {
Expand Down Expand Up @@ -1382,7 +1382,7 @@ pub fn launch_tool(stdout: &mut Stream, args: &[String], tool_name: &str, defaul
emit_symbol_output = true;
}

if parsed_args.get("table").is_some() {
if parsed_args.contains_key("table") {
emit_symbol_output = true;
}

Expand Down Expand Up @@ -1466,15 +1466,15 @@ pub fn launch_tool(stdout: &mut Stream, args: &[String], tool_name: &str, defaul
let mut includes = Vec::new();

// Short circuit preprocessing display.
if parsed_args.get("preprocess").is_some() {
if parsed_args.contains_key("preprocess") {
if let Err(e) = perform_preprocessing(stdout, opts, &use_filename, &input_program) {
stdout.write_str(&format!("{}: {}", e.0, e.1));
}
return;
}

// Short circuit desguaring display.
if parsed_args.get("desugar").is_some() {
if parsed_args.contains_key("desugar") {
if let Err(e) = perform_desugaring(runner, stdout, opts, &use_filename, &input_program)
{
stdout.write_str(&format!("{}: {}", e.0, e.1));
Expand Down Expand Up @@ -1670,15 +1670,15 @@ pub fn launch_tool(stdout: &mut Stream, args: &[String], tool_name: &str, defaul
let result = run_program_result.1;
let time_done = SystemTime::now();

if parsed_args.get("cost").is_some() {
if parsed_args.contains_key("cost") {
if cost > 0 {
cost += cost_offset;
}
stdout.write_str(&format!("cost = {cost}\n"));
};

if let Some(ArgumentValue::ArgBool(true)) = parsed_args.get("time") {
if parsed_args.get("hex").is_some() {
if parsed_args.contains_key("hex") {
stdout.write_str(&format!(
"read_hex: {}\n",
time_read_hex
Expand Down Expand Up @@ -1760,7 +1760,7 @@ pub fn launch_tool(stdout: &mut Stream, args: &[String], tool_name: &str, defaul
.unwrap_or_else(|| false);

if emit_symbol_output {
if parsed_args.get("table").is_some() {
if parsed_args.contains_key("table") {
trace_to_table(
&mut allocator,
stdout,
Expand Down
2 changes: 1 addition & 1 deletion src/classic/clvm_tools/stages/stage_2/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ pub fn optimize_sexp_(
}
SExp::Pair(_, _) => {
for opt in optimizers.iter() {
name = opt.name.clone();
name.clone_from(&opt.name);
match opt.invoke(allocator, memo, r, eval_f.clone()) {
Err(e) => {
return Err(e);
Expand Down
7 changes: 2 additions & 5 deletions src/classic/platform/argparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl ArgumentParser {
}
}

if params.get(&"help".to_string()).is_some() {
if params.contains_key("help") {
let usage = self.compile_help_messages();
return Err(usage);
}
Expand Down Expand Up @@ -491,10 +491,7 @@ impl ArgumentParser {
}

let name = &self.optional_args[k].names[index as usize];
let index2 = match arg.find(name) {
Some(i) => i,
_ => 0,
} + name.len();
let index2 = arg.find(name).unwrap_or_default() + name.len();
let value = &arg[index2..].to_string();

norm.push(name.to_string());
Expand Down
8 changes: 5 additions & 3 deletions src/compiler/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ fn start_codegen(
)),
};

code_generator.to_process = program.helpers.clone();
code_generator.to_process.clone_from(&program.helpers);
// Ensure that we have the synthesis of the previous codegen's helpers and
// The ones provided with the new form if any.
let mut combined_helpers_for_codegen = program.helpers.clone();
Expand Down Expand Up @@ -1592,7 +1592,7 @@ fn finalize_env_(
}

/* Parentfns are functions in progress in the parent */
if c.parentfns.get(v).is_some() {
if c.parentfns.contains(v) {
Ok(Rc::new(SExp::Nil(l.clone())))
} else {
Err(CompileErr(
Expand Down Expand Up @@ -1727,7 +1727,9 @@ pub fn codegen(
// If stepping 23 or greater, we support no-env mode.
enable_nil_env_mode_for_stepping_23_or_greater(opts.clone(), &mut code_generator);

*context.symbols() = code_generator.function_symbols.clone();
context
.symbols()
.clone_from(&code_generator.function_symbols);
context
.symbols()
.insert("source_file".to_string(), opts.filename());
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ impl CompilerOpts for DefaultCompilerOpts {
}
fn set_search_paths(&self, dirs: &[String]) -> Rc<dyn CompilerOpts> {
let mut copy = self.clone();
copy.include_dirs = dirs.to_owned();
dirs.clone_into(&mut copy.include_dirs);
Rc::new(copy)
}
fn set_disassembly_ver(&self, ver: Option<usize>) -> Rc<dyn CompilerOpts> {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/comptypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1877,7 +1877,7 @@ pub fn join_vecs_to_string(sep: Vec<u8>, vecs: &[Vec<u8>]) -> String {
s.append(&mut comma.clone());
s.append(&mut elt.to_vec());
if comma.is_empty() {
comma = sep.clone();
comma.clone_from(&sep);
}
}

Expand Down

0 comments on commit c7b95ec

Please sign in to comment.