Fix clippy issues

This commit is contained in:
Andrew Morris
2023-07-24 10:38:46 +10:00
parent d649272a6e
commit e81eb6d1e2
10 changed files with 23 additions and 38 deletions

View File

@@ -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),
};
}
}
}

View File

@@ -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);

View File

@@ -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<std::str::Chars>, len: usize) {

View File

@@ -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<Kal>,

View File

@@ -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 {

View File

@@ -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));
}

View File

@@ -98,7 +98,7 @@ impl BytecodeDecoder {
}
pub fn decode_val(&mut self, registers: &mut Vec<Val>) -> 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<Val>) -> Vec<Val> {

View File

@@ -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());
}

View File

@@ -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<CopyCounter>),
}
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<usize> {
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<Val>) -> Option<Val> {

View File

@@ -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 {