Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

chore: clippy --fix #224

Merged
merged 5 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions huff_cli/src/huffc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ enum TestCommands {
pub(crate) fn get_input(prompt: &str) -> String {
// let mut sp = Spinner::new(Spinners::Line, format!("{}{}",
// Paint::blue("[INTERACTIVE]".to_string()), prompt));
print!("{} {} ", Paint::blue("[INTERACTIVE]".to_string()), prompt);
print!("{} {prompt} ", Paint::blue("[INTERACTIVE]".to_string()));
let mut input = String::new();
let _ = std::io::stdout().flush();
let _ = std::io::stdin().read_line(&mut input);
Expand All @@ -134,7 +134,7 @@ fn main() {
let sources: Arc<Vec<String>> = match cli.get_inputs() {
Ok(s) => Arc::new(s),
Err(e) => {
eprintln!("{}", Paint::red(format!("{}", e)));
eprintln!("{}", Paint::red(format!("{e}")));
std::process::exit(1);
}
};
Expand Down Expand Up @@ -263,7 +263,7 @@ fn main() {
token: None,
});
tracing::error!(target: "cli", "COMPILER ERRORED: {}", e);
eprintln!("{}", Paint::red(format!("{}", e)));
eprintln!("{}", Paint::red(format!("{e}")));
std::process::exit(1);
}

Expand All @@ -277,7 +277,7 @@ fn main() {
.last()
{
Some(p) => match p.split('.').next() {
Some(p) => Some(format!("I{}", p)),
Some(p) => Some(format!("I{p}")),
None => {
tracing::warn!(target: "cli", "No file name found for artifact");
None
Expand All @@ -303,7 +303,7 @@ fn main() {
Paint::blue(
interfaces
.into_iter()
.map(|(_, i, _)| format!("{}.sol", i))
.map(|(_, i, _)| format!("{i}.sol"))
.collect::<Vec<_>>()
.join(", ")
)
Expand Down Expand Up @@ -347,7 +347,7 @@ fn main() {
ethers_core::abi::encode(&[str.clone()]);
let hex_args: String =
hex::encode(inner.as_slice());
format!("{}{}", acc, hex_args)
format!("{acc}{hex_args}")
});
appended_args.push_str(&encoded);
}
Expand All @@ -362,7 +362,7 @@ fn main() {
}
match Arc::get_mut(artifact) {
Some(art) => {
art.bytecode = format!("{}{}", art.bytecode, appended_args);
art.bytecode = format!("{}{appended_args}", art.bytecode);
}
None => {
tracing::warn!(target: "cli", "FAILED TO ACQUIRE MUTABLE REF TO ARTIFACT")
Expand Down Expand Up @@ -407,7 +407,7 @@ fn main() {
}
Err(e) => {
tracing::error!(target: "cli", "COMPILER ERRORED: {}", e);
eprintln!("{}", Paint::red(format!("{}", e)));
eprintln!("{}", Paint::red(format!("{e}")));
std::process::exit(1);
}
}
Expand Down
5 changes: 2 additions & 3 deletions huff_codegen/src/irgen/arg_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ pub fn bubble_arg_call(
tracing::info!(target: "codegen", "GOT LITERAL {} ARG FROM MACRO INVOCATION", bytes32_to_string(l, false));

let hex_literal: String = bytes32_to_string(l, false);
let push_bytes =
format!("{:02x}{}", 95 + hex_literal.len() / 2, hex_literal);
let push_bytes = format!("{:02x}{hex_literal}", 95 + hex_literal.len() / 2);
let b = Bytes(push_bytes);
*offset += b.0.len() / 2;
bytes.push((starting_offset, b));
Expand Down Expand Up @@ -111,7 +110,7 @@ pub fn bubble_arg_call(
let push_bytes = match &constant.value {
ConstVal::Literal(l) => {
let hex_literal: String = bytes32_to_string(l, false);
format!("{:02x}{}", 95 + hex_literal.len() / 2, hex_literal)
format!("{:02x}{hex_literal}", 95 + hex_literal.len() / 2)
}
ConstVal::FreeStoragePointer(fsp) => {
// If this is reached in codegen stage,
Expand Down
2 changes: 1 addition & 1 deletion huff_codegen/src/irgen/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn constant_gen(
let push_bytes = match &constant.value {
ConstVal::Literal(l) => {
let hex_literal: String = bytes32_to_string(l, false);
format!("{:02x}{}", 95 + hex_literal.len() / 2, hex_literal)
format!("{:02x}{hex_literal}", 95 + hex_literal.len() / 2)
}
ConstVal::FreeStoragePointer(fsp) => {
// If this is reached in codegen stage, the `derive_storage_pointers`
Expand Down
10 changes: 5 additions & 5 deletions huff_codegen/src/irgen/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pub fn statement_gen(
"{:02x}",
(res.bytes.iter().map(|(_, b)| b.0.len()).sum::<usize>() / 2)
));
let push_bytes = format!("{:02x}{}", 95 + size.len() / 2, size);
let push_bytes = format!("{:02x}{size}", 95 + size.len() / 2);

*offset += push_bytes.len() / 2;
bytes.push((starting_offset, Bytes(push_bytes)));
Expand All @@ -229,7 +229,7 @@ pub fn statement_gen(
};

let size = bytes32_to_string(&ir_table.size, false);
let push_bytes = format!("{:02x}{}", 95 + size.len() / 2, size);
let push_bytes = format!("{:02x}{size}", 95 + size.len() / 2);

if !utilized_tables.contains(&ir_table) {
utilized_tables.push(ir_table);
Expand Down Expand Up @@ -352,7 +352,7 @@ pub fn statement_gen(
.find(|e| bf.args[0].name.as_ref().unwrap().eq(&e.name))
{
let hash = bytes32_to_string(&event.hash, false);
let push_bytes = format!("{}{}", Opcode::Push32, hash);
let push_bytes = format!("{}{hash}", Opcode::Push32);
*offset += push_bytes.len() / 2;
bytes.push((starting_offset, Bytes(push_bytes)));
} else if let Some(s) = &bf.args[0].name {
Expand Down Expand Up @@ -402,7 +402,7 @@ pub fn statement_gen(
// Add 28 bytes to left-pad the 4 byte selector
let selector =
format!("{}{}", hex::encode(error.selector), "00".repeat(28));
let push_bytes = format!("{}{}", Opcode::Push32, selector);
let push_bytes = format!("{}{selector}", Opcode::Push32);
*offset += push_bytes.len() / 2;
bytes.push((starting_offset, Bytes(push_bytes)));
} else {
Expand Down Expand Up @@ -439,7 +439,7 @@ pub fn statement_gen(

let hex = format_even_bytes(bf.args[0].name.as_ref().unwrap().clone());
let push_bytes =
format!("{}{}{}", Opcode::Push32, hex, "0".repeat(64 - hex.len()));
format!("{}{hex}{}", Opcode::Push32, "0".repeat(64 - hex.len()));
*offset += push_bytes.len() / 2;
bytes.push((starting_offset, Bytes(push_bytes)));
}
Expand Down
31 changes: 15 additions & 16 deletions huff_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ impl Codegen {
});
}
};
let hex = format_even_bytes(format!("{:02x}", offset));
let hex = format_even_bytes(format!("{offset:02x}"));

table_code = format!("{}{}", table_code, pad_n_bytes(
table_code = format!("{table_code}{}", pad_n_bytes(
hex.as_str(),
if matches!(jt.kind, TableKind::JumpTablePacked) { 0x02 } else { 0x20 },
));
Expand All @@ -199,7 +199,7 @@ impl Codegen {
});
}

table_code = format!("{}{}", table_code, code);
table_code = format!("{table_code}{code}");
}
_ => {
return Err(CodegenError {
Expand All @@ -212,7 +212,7 @@ impl Codegen {
Ok(())
})?;
tracing::info!(target: "codegen", "SUCCESSFULLY GENERATED BYTECODE FOR TABLE: \"{}\"", jt.name);
bytecode = format!("{}{}", bytecode, table_code);
bytecode = format!("{bytecode}{table_code}");
Ok(())
})?;

Expand All @@ -222,7 +222,7 @@ impl Codegen {
let after = &bytecode[jump.bytecode_index * 2 + 6..];

bytecode =
format!("{}{}{}", before, pad_n_bytes(format!("{:02x}", o).as_str(), 2), after);
format!("{before}{}{after}", pad_n_bytes(format!("{o:02x}").as_str(), 2));
tracing::info!(target: "codegen", "FILLED JUMPDEST FOR LABEL \"{}\"", jump.label);
} else {
tracing::error!(
Expand Down Expand Up @@ -385,7 +385,7 @@ impl Codegen {
// at `code_index`
if let Some(jump_index) = label_indices.get(jump.label.as_str()) {
// Format the jump index as a 2 byte hex number
let jump_value = format!("{:04x}", jump_index);
let jump_value = format!("{jump_index:04x}");

// Get the bytes before & after the placeholder
let before = &formatted_bytes.0[0..jump.bytecode_index + 2];
Expand All @@ -403,7 +403,7 @@ impl Codegen {
}

// Replace the "xxxx" placeholder with the jump value
formatted_bytes = Bytes(format!("{}{}{}", before, jump_value, after));
formatted_bytes = Bytes(format!("{before}{jump_value}{after}"));
} else {
// The jump did not have a corresponding label index. Add it to the
// unmatched jumps vec.
Expand Down Expand Up @@ -542,10 +542,9 @@ impl Codegen {
// Check for "__CODECOPY_DYN_ARG" calls for this specific argument. If any
// exist, fill the placeholders.
let tok_len = hex::encode(&encoded[62..64]);
let rep_regex = Regex::new(
format!("xxxxxxxxxxxxxxxxxxxxxxxxxxxx{:02x}\\d{{4}}", i).as_str(),
)
.unwrap();
let rep_regex =
Regex::new(format!("xxxxxxxxxxxxxxxxxxxxxxxxxxxx{i:02x}\\d{{4}}").as_str())
.unwrap();
rep_regex.find_iter(main_bytecode.clone().as_str()).for_each(|s| {
// TODO: Enforce that the arg type is a literal so that this unwrap is safe.
let len_ptr = usize::from_str_radix(&s.as_str()[30..34], 16).unwrap();
Expand Down Expand Up @@ -600,11 +599,11 @@ impl Codegen {
// Constructor size optimizations
let mut bootstrap_code_size = 9;
let contract_size = if contract_length < 256 {
format!("60{}", pad_n_bytes(format!("{:x}", contract_length).as_str(), 1))
format!("60{}", pad_n_bytes(format!("{contract_length:x}").as_str(), 1))
} else {
bootstrap_code_size += 1;

format!("61{}", pad_n_bytes(format!("{:x}", contract_length).as_str(), 2))
format!("61{}", pad_n_bytes(format!("{contract_length:x}").as_str(), 2))
};
let contract_code_offset = if (bootstrap_code_size + constructor_length) < 256 {
format!(
Expand All @@ -625,13 +624,13 @@ impl Codegen {
let bootstrap_code = if has_custom_bootstrap {
String::default()
} else {
format!("{}80{}3d393df3", contract_size, contract_code_offset)
format!("{contract_size}80{contract_code_offset}3d393df3")
};

// Generate the final bytecode
let constructor_code = format!("{}{}", constructor_bytecode, bootstrap_code);
let constructor_code = format!("{constructor_bytecode}{bootstrap_code}");
artifact.bytecode =
format!("{}{}{}", constructor_code, main_bytecode, constructor_args).to_lowercase();
format!("{constructor_code}{main_bytecode}{constructor_args}").to_lowercase();
artifact.runtime = main_bytecode.to_lowercase();
artifact.file = file;
Ok(artifact.clone())
Expand Down
2 changes: 1 addition & 1 deletion huff_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'a> Compiler<'a> {
}
}
if let Err(e) = subscriber_builder.with_env_filter(env_filter).try_init() {
println!("Failed to initialize tracing!\nError: {:?}", e)
println!("Failed to initialize tracing!\nError: {e:?}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion huff_core/tests/compiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn compiles_constructor_bytecode() {

// Have the Codegen create the constructor bytecode
let cbytes = Codegen::generate_constructor_bytecode(&contract).unwrap();
println!("Constructor Bytecode Result: {:?}", cbytes);
println!("Constructor Bytecode Result: {cbytes:?}");
assert_eq!(cbytes, String::from("33600055"));
}

Expand Down
14 changes: 7 additions & 7 deletions huff_core/tests/macro_invoc_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn test_opcode_macro_args() {
let expected_bytecode = "60088060093d393df360ff3d5260203df3";

// Create bytecode
let bytecode = format!("60088060093d393df360ff{}", main_bytecode);
let bytecode = format!("60088060093d393df360ff{main_bytecode}");

// Check the bytecode
assert_eq!(bytecode.to_lowercase(), expected_bytecode.to_lowercase());
Expand Down Expand Up @@ -69,7 +69,7 @@ fn test_all_opcodes_in_macro_args() {
let expected_bytecode = format!("60088060093d393df360ff{}", Opcode::from_str(o).unwrap());

// Create bytecode
let bytecode = format!("60088060093d393df360ff{}", main_bytecode);
let bytecode = format!("60088060093d393df360ff{main_bytecode}");

// Check the bytecode
assert_eq!(bytecode.to_lowercase(), expected_bytecode.to_lowercase());
Expand Down Expand Up @@ -105,7 +105,7 @@ fn test_constant_macro_arg() {
let expected_bytecode = "60088060093d393df360ff6002";

// Create bytecode
let bytecode = format!("60088060093d393df360ff{}", main_bytecode);
let bytecode = format!("60088060093d393df360ff{main_bytecode}");

// Check the bytecode
assert_eq!(bytecode.to_lowercase(), expected_bytecode.to_lowercase());
Expand Down Expand Up @@ -143,7 +143,7 @@ fn test_bubbled_label_call_macro_arg() {
let expected_bytecode = "60088060093d393df360ff5b610000";

// Create bytecode
let bytecode = format!("60088060093d393df360ff{}", main_bytecode);
let bytecode = format!("60088060093d393df360ff{main_bytecode}");

// Check the bytecode
assert_eq!(bytecode.to_lowercase(), expected_bytecode.to_lowercase());
Expand Down Expand Up @@ -180,7 +180,7 @@ fn test_bubbled_literal_macro_arg() {
let expected_bytecode = "60088060093d393df360ff610420";

// Create bytecode
let bytecode = format!("60088060093d393df360ff{}", main_bytecode);
let bytecode = format!("60088060093d393df360ff{main_bytecode}");

// Check the bytecode
assert_eq!(bytecode.to_lowercase(), expected_bytecode.to_lowercase());
Expand Down Expand Up @@ -217,7 +217,7 @@ fn test_bubbled_opcode_macro_arg() {
let expected_bytecode = "60088060093d393df360ff3d";

// Create bytecode
let bytecode = format!("60088060093d393df360ff{}", main_bytecode);
let bytecode = format!("60088060093d393df360ff{main_bytecode}");

// Check the bytecode
assert_eq!(bytecode.to_lowercase(), expected_bytecode.to_lowercase());
Expand Down Expand Up @@ -256,7 +256,7 @@ fn test_bubbled_constant_macro_arg() {
let expected_bytecode = "60088060093d393df360ff6002";

// Create bytecode
let bytecode = format!("60088060093d393df360ff{}", main_bytecode);
let bytecode = format!("60088060093d393df360ff{main_bytecode}");

// Check the bytecode
assert_eq!(bytecode.to_lowercase(), expected_bytecode.to_lowercase());
Expand Down
5 changes: 2 additions & 3 deletions huff_core/tests/parser_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn test_invalid_constant_value() {
];

for (value, kind) in invalid_constant_values {
let source = &format!("#define constant CONSTANT = {}", value);
let source = &format!("#define constant CONSTANT = {value}");

let full_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(full_source);
Expand Down Expand Up @@ -255,8 +255,7 @@ fn test_invalid_single_arg() {
{
continue
}
let source =
&format!("#define macro CONSTANT() = takes ({}) returns (0) {{}}", random_char);
let source = &format!("#define macro CONSTANT() = takes ({random_char}) returns (0) {{}}");

let full_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(full_source);
Expand Down
8 changes: 4 additions & 4 deletions huff_core/tests/recurse_bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ fn recurse_macro_bytecode() {
// Size config
let contract_length = main_bytecode.len() / 2;
let constructor_length = constructor_bytecode.len() / 2;
let contract_size = format!("{:04x}", contract_length);
let contract_size = format!("{contract_length:04x}");
let contract_code_offset = format!("{:04x}", 13 + constructor_length);

// Generate artifact bytecode and runtime code
let bootstrap_code = format!("61{}8061{}6000396000f3", contract_size, contract_code_offset);
let constructor_code = format!("{}{}", constructor_bytecode, bootstrap_code);
artifact.bytecode = format!("{}{}{}", constructor_code, main_bytecode, constructor_args);
let bootstrap_code = format!("61{contract_size}8061{contract_code_offset}6000396000f3");
let constructor_code = format!("{constructor_bytecode}{bootstrap_code}");
artifact.bytecode = format!("{constructor_code}{main_bytecode}{constructor_args}");
artifact.runtime = main_bytecode;

// Check the bytecode
Expand Down
4 changes: 2 additions & 2 deletions huff_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ impl<'a> Iterator for Lexer<'a> {
),
span: self.current_span().clone(),
};
tracing::error!(target: "lexer", "{}", format!("{:?}", err));
tracing::error!(target: "lexer", "{}", format!("{err:?}"));
err
})
.unwrap();
Expand All @@ -551,7 +551,7 @@ impl<'a> Iterator for Lexer<'a> {
kind: LexicalErrorKind::InvalidPrimitiveType(&words[0]),
span: self.current_span().clone(),
};
tracing::error!(target: "lexer", "{}", format!("{:?}", err));
tracing::error!(target: "lexer", "{}", format!("{err:?}"));
}
} else {
// We don't want to consider any argument names or the "indexed"
Expand Down
Loading