Skip to content

Commit

Permalink
Make clippy a happy chappy
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Jul 7, 2023
1 parent 6c72b32 commit 581965e
Show file tree
Hide file tree
Showing 59 changed files with 734 additions and 998 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"rust-analyzer.inlayHints.typeHints.enable": false,
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
},
"rust-analyzer.check.command": "clippy"
}
15 changes: 6 additions & 9 deletions bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ fn main() {

let mut failed_paths = HashSet::<PathBuf>::new();

let mut files =
get_files_recursively(&input_dir_path.to_path_buf()).expect("Failed to get files");
let mut files = get_files_recursively(&input_dir_path).expect("Failed to get files");

files.sort();

Expand Down Expand Up @@ -52,7 +51,7 @@ fn main() {
});

for (path, diagnostics) in compile_result.diagnostics.iter() {
if diagnostics.len() > 0 {
if !diagnostics.is_empty() {
dbg!(&path.path, diagnostics);
}

Expand Down Expand Up @@ -80,7 +79,7 @@ fn main() {

let bytecode = Rc::new(Bytecode::new(assemble(&module)));

let mut vm = VirtualMachine::new();
let mut vm = VirtualMachine::default();

let mut file_results = Vec::<f64>::new();

Expand All @@ -96,7 +95,7 @@ fn main() {
file_results.push(duration_ms as f64);

if let Err(result) = result {
assert!(false, "{} failed: {}", friendly_file_path, result.codify());
panic!("{} failed: {}", friendly_file_path, result.codify());
}
}

Expand All @@ -117,7 +116,7 @@ fn main() {
println!("{:<37} {:>6.1}ms", "Score", score);

if !failed_paths.is_empty() {
assert!(false, "See failures above");
panic!("See failures above");
}
}

Expand Down Expand Up @@ -151,9 +150,7 @@ pub fn resolve_entry_path(entry_path: &String) -> ResolvedPath {
.to_string(),
};

let resolved_entry_path = resolve_path(&cwd_file, entry_path);

resolved_entry_path
resolve_path(&cwd_file, entry_path)
}

fn geometric_mean(vals: &[f64]) -> f64 {
Expand Down
4 changes: 2 additions & 2 deletions compile_to_rust_tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn fib(n: Val) -> Result<Val, Val> {
let mut _tmp3 = fib(_tmp1)?;
_return = op_plus(&_tmp2, &_tmp3)?;

return Ok(_return);
Ok(_return)
}

// 0.120s
Expand All @@ -91,5 +91,5 @@ pub fn fib2(n: f64) -> f64 {
return n;
}

return fib2(n - 1.0) + fib2(n - 2.0);
fib2(n - 1.0) + fib2(n - 2.0)
}
4 changes: 1 addition & 3 deletions measure_bytecode_size/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,5 @@ fn resolve_entry_path(entry_path: &String) -> ResolvedPath {
.to_string(),
};

let resolved_entry_path = resolve_path(&cwd_file, entry_path);

resolved_entry_path
resolve_path(&cwd_file, entry_path)
}
70 changes: 33 additions & 37 deletions valuescript_compiler/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ pub struct Module {
impl Module {
pub fn as_lines(&self) -> Vec<String> {
let assembly_str = self.to_string();
let assembly_lines = assembly_str.split("\n");
let assembly_lines_vec = assembly_lines.map(|s| s.to_string()).collect();
let assembly_lines = assembly_str.split('\n');

return assembly_lines_vec;
assembly_lines.map(|s| s.to_string()).collect()
}
}

Expand All @@ -37,13 +36,13 @@ impl Default for Module {

impl std::fmt::Display for Module {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if self.export_star.properties.len() == 0 {
if self.export_star.properties.is_empty() {
write!(f, "export {} {}", self.export_default, self.export_star)?;
} else {
write!(f, "export {} {{\n", self.export_default)?;
writeln!(f, "export {} {{", self.export_default)?;

for (name, value) in &self.export_star.properties {
write!(f, " {}: {},\n", name, value)?;
writeln!(f, " {}: {},", name, value)?;
}

write!(f, "}}")?;
Expand All @@ -53,7 +52,7 @@ impl std::fmt::Display for Module {
write!(f, "\n\n{}", definition)?;
}

return Ok(());
Ok(())
}
}

Expand Down Expand Up @@ -138,14 +137,14 @@ impl std::fmt::Display for Function {
}
write!(f, "{}", parameter)?;
}
write!(f, ") {{\n")?;
writeln!(f, ") {{")?;
for fn_line in &self.body {
match fn_line {
FnLine::Instruction(instruction) => write!(f, " {}\n", instruction)?,
FnLine::Label(label) => write!(f, " {}\n", label)?,
FnLine::Empty => write!(f, "\n")?,
FnLine::Comment(message) => write!(f, " // {}\n", message)?,
FnLine::Release(reg) => write!(f, " (release {})\n", reg)?,
FnLine::Instruction(instruction) => writeln!(f, " {}", instruction)?,
FnLine::Label(label) => writeln!(f, " {}", label)?,
FnLine::Empty => writeln!(f)?,
FnLine::Comment(message) => writeln!(f, " // {}", message)?,
FnLine::Release(reg) => writeln!(f, " (release {})", reg)?,
}
}
write!(f, "}}")
Expand All @@ -169,12 +168,12 @@ impl std::fmt::Display for Class {

match &self.prototype {
Value::Object(object) => {
if object.properties.len() == 0 {
if object.properties.is_empty() {
writeln!(f, "{{}},")?;
} else {
write!(f, "{{\n")?;
writeln!(f, "{{")?;
for (name, method) in &object.properties {
write!(f, " {}: {},\n", name, method)?;
writeln!(f, " {}: {},", name, method)?;
}
writeln!(f, " }},")?;
}
Expand All @@ -188,12 +187,12 @@ impl std::fmt::Display for Class {

match &self.static_ {
Value::Object(object) => {
if object.properties.len() == 0 {
if object.properties.is_empty() {
writeln!(f, "{{}},")?;
} else {
write!(f, "{{\n")?;
writeln!(f, "{{")?;
for (name, method) in &object.properties {
write!(f, " {}: {},\n", name, method)?;
writeln!(f, " {}: {},", name, method)?;
}
writeln!(f, " }},")?;
}
Expand All @@ -205,7 +204,7 @@ impl std::fmt::Display for Class {

write!(f, "}}")?;

return Ok(());
Ok(())
}
}

Expand Down Expand Up @@ -256,26 +255,23 @@ impl Register {
}

pub fn is_return(&self) -> bool {
return self.name == "return";
self.name == "return"
}

pub fn is_this(&self) -> bool {
return self.name == "this";
self.name == "this"
}

pub fn is_named(&self) -> bool {
match self.name.as_str() {
"return" | "this" | "ignore" => false,
_ => true,
}
!matches!(self.name.as_str(), "return" | "this" | "ignore")
}

pub fn is_ignore(&self) -> bool {
return self.name == "ignore";
self.name == "ignore"
}

pub fn is_special(&self) -> bool {
return self.is_return() || self.is_this() || self.is_ignore();
self.is_return() || self.is_this() || self.is_ignore()
}

pub fn value_type(&self) -> ValueType {
Expand Down Expand Up @@ -398,7 +394,7 @@ impl Value {

pub fn visit_values_mut<F>(&mut self, visit: &mut F)
where
F: FnMut(&mut Value) -> (),
F: FnMut(&mut Value),
{
visit(self);

Expand Down Expand Up @@ -429,7 +425,7 @@ impl Value {

pub fn visit_registers_mut_rev<F>(&mut self, visit: &mut F)
where
F: FnMut(RegisterVisitMut) -> (),
F: FnMut(RegisterVisitMut),
{
match self {
Value::Array(array) => {
Expand Down Expand Up @@ -499,15 +495,15 @@ pub struct Lazy {

impl std::fmt::Display for Lazy {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "lazy {{\n")?;
writeln!(f, "lazy {{")?;

for fn_line in &self.body {
match fn_line {
FnLine::Instruction(instruction) => write!(f, " {}\n", instruction)?,
FnLine::Label(label) => write!(f, " {}\n", label)?,
FnLine::Empty => write!(f, "\n")?,
FnLine::Comment(message) => write!(f, " // {}\n", message)?,
FnLine::Release(reg) => write!(f, " (release {})\n", reg)?,
FnLine::Instruction(instruction) => writeln!(f, " {}", instruction)?,
FnLine::Label(label) => writeln!(f, " {}", label)?,
FnLine::Empty => writeln!(f)?,
FnLine::Comment(message) => writeln!(f, " // {}", message)?,
FnLine::Release(reg) => writeln!(f, " (release {})", reg)?,
}
}

Expand Down Expand Up @@ -551,7 +547,7 @@ pub struct Object {

impl std::fmt::Display for Object {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.properties.len() == 0 {
if self.properties.is_empty() {
return write!(f, "{{}}");
}

Expand Down
4 changes: 2 additions & 2 deletions valuescript_compiler/src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl Assembler {
self.output.push(ValueType::Builtin as u8);

let builtin_name = BuiltinName::from_str(&builtin.name)
.expect(format!("Unknown builtin: {}", builtin.name).as_str());
.unwrap_or_else(|_| panic!("Unknown builtin: {}", builtin.name));

self.varsize_uint(builtin_name.to_code());
}
Expand Down Expand Up @@ -476,7 +476,7 @@ impl LocationMap {
output.push(0xff); // TODO: Support >65535
}

fn resolve(&self, output: &mut Vec<u8>) {
fn resolve(&self, output: &mut [u8]) {
for (name, ref_locations) in &self.references {
let location_optional = self.found_locations.get(name);

Expand Down
Loading

0 comments on commit 581965e

Please sign in to comment.