From e81eb6d1e2aad4e170b07e7875e0e1479848e524 Mon Sep 17 00:00:00 2001 From: Andrew Morris Date: Mon, 24 Jul 2023 10:38:46 +1000 Subject: [PATCH] Fix clippy issues --- valuescript_common/src/instruction_byte.rs | 4 ++-- valuescript_compiler/src/asm.rs | 9 ++------- valuescript_compiler/src/assembly_parser.rs | 4 ++-- valuescript_compiler/src/optimization/kal.rs | 9 ++------- valuescript_compiler/src/target_accessor.rs | 4 ++-- valuescript_vm/src/builtins/number_builtin.rs | 2 +- valuescript_vm/src/bytecode_decoder.rs | 4 ++-- valuescript_vm/src/number_methods.rs | 4 ++-- valuescript_vm/src/vs_value.rs | 17 ++++++----------- vstc/src/run_command.rs | 4 ++-- 10 files changed, 23 insertions(+), 38 deletions(-) diff --git a/valuescript_common/src/instruction_byte.rs b/valuescript_common/src/instruction_byte.rs index 6b5c447..892ad06 100644 --- a/valuescript_common/src/instruction_byte.rs +++ b/valuescript_common/src/instruction_byte.rs @@ -64,7 +64,7 @@ impl InstructionByte { pub fn from_byte(byte: u8) -> InstructionByte { use InstructionByte::*; - return match byte { + match byte { 0x00 => End, 0x01 => Mov, 0x02 => OpInc, @@ -125,6 +125,6 @@ impl InstructionByte { 0x39 => YieldStar, _ => panic!("Unrecognized instruction: {}", byte), - }; + } } } diff --git a/valuescript_compiler/src/asm.rs b/valuescript_compiler/src/asm.rs index 85d2b2f..c5bddda 100644 --- a/valuescript_compiler/src/asm.rs +++ b/valuescript_compiler/src/asm.rs @@ -336,8 +336,9 @@ impl std::fmt::Display for LabelRef { } } -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] pub enum Value { + #[default] Void, Undefined, Null, @@ -352,12 +353,6 @@ pub enum Value { Builtin(Builtin), } -impl Default for Value { - fn default() -> Self { - Value::Void - } -} - #[derive(Debug, Clone)] pub struct Number(pub f64); diff --git a/valuescript_compiler/src/assembly_parser.rs b/valuescript_compiler/src/assembly_parser.rs index 94b1fc8..003f679 100644 --- a/valuescript_compiler/src/assembly_parser.rs +++ b/valuescript_compiler/src/assembly_parser.rs @@ -1007,11 +1007,11 @@ pub fn parse_module(content: &str) -> Module { } fn is_leading_identifier_char(c: char) -> bool { - c == '_' || ('a'..='z').contains(&c) || ('A'..='Z').contains(&c) + c == '_' || c.is_ascii_alphabetic() } fn is_identifier_char(c: char) -> bool { - c == '_' || ('0'..='9').contains(&c) || ('a'..='z').contains(&c) || ('A'..='Z').contains(&c) + c == '_' || c.is_ascii_alphanumeric() } fn advance_chars(iter: &mut std::iter::Peekable, len: usize) { diff --git a/valuescript_compiler/src/optimization/kal.rs b/valuescript_compiler/src/optimization/kal.rs index f959e8f..64d4ffb 100644 --- a/valuescript_compiler/src/optimization/kal.rs +++ b/valuescript_compiler/src/optimization/kal.rs @@ -33,8 +33,9 @@ use super::try_to_kal::TryToKal; * change program behavior due to believing false things), whereas sometimes type systems (notably * TypeScript) are not. */ -#[derive(Clone)] +#[derive(Clone, Default)] pub enum Kal { + #[default] Unknown, Void, Undefined, @@ -50,12 +51,6 @@ pub enum Kal { Builtin(Builtin), } -impl Default for Kal { - fn default() -> Self { - Kal::Unknown - } -} - #[derive(Clone)] pub struct Array { pub values: Vec, diff --git a/valuescript_compiler/src/target_accessor.rs b/valuescript_compiler/src/target_accessor.rs index 74a8637..a1bf353 100644 --- a/valuescript_compiler/src/target_accessor.rs +++ b/valuescript_compiler/src/target_accessor.rs @@ -56,7 +56,7 @@ impl TargetAccessor { ) -> TargetAccessor { use swc_ecma_ast::Expr::*; - return match expr { + match expr { Ident(ident) => TargetAccessor::compile_ident(ec, &CrateIdent::from_swc_ident(ident)), This(this) => TargetAccessor::compile_ident(ec, &CrateIdent::this(this.span)), Member(member) => { @@ -98,7 +98,7 @@ impl TargetAccessor { TargetAccessor::make_bad(ec) } - }; + } } pub fn compile_ident(ec: &mut ExpressionCompiler, ident: &CrateIdent) -> TargetAccessor { diff --git a/valuescript_vm/src/builtins/number_builtin.rs b/valuescript_vm/src/builtins/number_builtin.rs index cd85d8e..32da951 100644 --- a/valuescript_vm/src/builtins/number_builtin.rs +++ b/valuescript_vm/src/builtins/number_builtin.rs @@ -123,7 +123,7 @@ pub static PARSE_INT: NativeFunction = native_fn(|_this, params| { let string_value = value.to_string().trim_start().to_string(); let radix = params.get(1).and_then(|v| v.to_index()).unwrap_or(10); - if radix < 2 || radix > 36 { + if !(2..=36).contains(&radix) { return Ok(Val::Number(f64::NAN)); } diff --git a/valuescript_vm/src/bytecode_decoder.rs b/valuescript_vm/src/bytecode_decoder.rs index f61e495..5d57c6e 100644 --- a/valuescript_vm/src/bytecode_decoder.rs +++ b/valuescript_vm/src/bytecode_decoder.rs @@ -98,7 +98,7 @@ impl BytecodeDecoder { } pub fn decode_val(&mut self, registers: &mut Vec) -> Val { - return match self.decode_type() { + match self.decode_type() { BytecodeType::End => panic!("Cannot decode end"), BytecodeType::Void => Val::Void, BytecodeType::Undefined => Val::Undefined, @@ -153,7 +153,7 @@ impl BytecodeDecoder { BytecodeType::BigInt => self.decode_bigint().to_val(), BytecodeType::GeneratorFunction => self.decode_function(true), BytecodeType::Unrecognized => panic!("Unrecognized bytecode type at {}", self.pos - 1), - }; + } } pub fn decode_vec_val(&mut self, registers: &mut Vec) -> Vec { diff --git a/valuescript_vm/src/number_methods.rs b/valuescript_vm/src/number_methods.rs index 9a206b4..901d7cb 100644 --- a/valuescript_vm/src/number_methods.rs +++ b/valuescript_vm/src/number_methods.rs @@ -42,7 +42,7 @@ static TO_FIXED: NativeFunction = native_fn(|this, params| { precision = f64::floor(precision); - if precision < 1.0 || precision > 100.0 { + if !(1.0..=100.0).contains(&precision) { return Err("precision must be between 1 and 100".to_range_error()); } @@ -59,7 +59,7 @@ static TO_EXPONENTIAL: NativeFunction = native_fn(|this, params| { let mut precision = p.to_number(); precision = f64::floor(precision); - if precision < 0.0 || precision > 100.0 { + if !(0.0..=100.0).contains(&precision) { return Err("precision must be between 0 and 100".to_range_error()); } diff --git a/valuescript_vm/src/vs_value.rs b/valuescript_vm/src/vs_value.rs index fdae11c..ea71830 100644 --- a/valuescript_vm/src/vs_value.rs +++ b/valuescript_vm/src/vs_value.rs @@ -18,8 +18,9 @@ use crate::vs_function::VsFunction; use crate::vs_object::VsObject; use crate::vs_symbol::{symbol_to_name, VsSymbol}; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub enum Val { + #[default] Void, Undefined, Null, @@ -37,12 +38,6 @@ pub enum Val { CopyCounter(Box), } -impl Default for Val { - fn default() -> Self { - Val::Void - } -} - #[derive(PartialEq, Debug)] pub enum VsType { Undefined, @@ -222,7 +217,7 @@ impl ValTrait for Val { fn to_index(&self) -> Option { use Val::*; - return match self { + match self { Void => panic!("Shouldn't happen"), Undefined => None, Null => None, @@ -241,7 +236,7 @@ impl ValTrait for Val { Static(val) => val.to_index(), Dynamic(val) => val.to_index(), CopyCounter(_) => None, - }; + } } fn is_primitive(&self) -> bool { @@ -291,7 +286,7 @@ impl ValTrait for Val { fn is_nullish(&self) -> bool { use Val::*; - return match self { + match self { Void => panic!("Shouldn't happen"), // TODO: Or just true? Undefined => true, Null => true, @@ -307,7 +302,7 @@ impl ValTrait for Val { Static(_) => false, Dynamic(val) => val.is_nullish(), CopyCounter(_) => false, - }; + } } fn bind(&self, params: Vec) -> Option { diff --git a/vstc/src/run_command.rs b/vstc/src/run_command.rs index a17569e..72ff96b 100644 --- a/vstc/src/run_command.rs +++ b/vstc/src/run_command.rs @@ -77,7 +77,7 @@ fn format_from_path(file_path: &String) -> RunFormat { .and_then(OsStr::to_str) .unwrap_or(""); - return match ext { + match ext { "ts" => RunFormat::TypeScript, "mts" => RunFormat::TypeScript, "js" => RunFormat::TypeScript, @@ -85,7 +85,7 @@ fn format_from_path(file_path: &String) -> RunFormat { "vsm" => RunFormat::Assembly, "vsb" => RunFormat::Bytecode, _ => std::panic!("Unrecognized file extension \"{}\"", ext), - }; + } } fn to_bytecode(format: RunFormat, file_path: &String) -> Bytecode {