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

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