From f33ceca2aa251fb1b383d6539efaacc49ef614d4 Mon Sep 17 00:00:00 2001 From: RageKnify Date: Mon, 29 Mar 2021 19:27:09 +0100 Subject: [PATCH] Style: Respect the new lints from 1.51 --- boa/src/builtins/array/mod.rs | 2 +- boa/src/builtins/bigint/conversions.rs | 2 +- boa/src/builtins/math/mod.rs | 2 +- boa/src/builtins/string/mod.rs | 9 ++++----- boa/src/exec/tests.rs | 2 +- boa/src/lib.rs | 2 ++ boa/src/object/internal_methods.rs | 4 ++-- .../ast/node/declaration/arrow_function_decl/mod.rs | 4 ++-- boa/src/syntax/ast/node/field/get_const_field/mod.rs | 2 +- boa/src/syntax/ast/node/field/get_field/mod.rs | 2 +- boa/src/syntax/ast/node/template/mod.rs | 3 +-- .../syntax/parser/expression/primary/template/mod.rs | 11 ++++++----- boa/src/value/mod.rs | 3 +-- boa/src/value/operations.rs | 6 +++--- boa/src/value/tests.rs | 4 ++-- boa_cli/src/helper.rs | 1 + 16 files changed, 30 insertions(+), 29 deletions(-) diff --git a/boa/src/builtins/array/mod.rs b/boa/src/builtins/array/mod.rs index 3d4a4c56caf..521f719c2a5 100644 --- a/boa/src/builtins/array/mod.rs +++ b/boa/src/builtins/array/mod.rs @@ -353,7 +353,7 @@ impl Array { /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push pub(crate) fn push(this: &Value, args: &[Value], context: &mut Context) -> Result { let new_array = Self::add_to_array_object(this, args, context)?; - Ok(new_array.get_field("length", context)?) + new_array.get_field("length", context) } /// `Array.prototype.pop()` diff --git a/boa/src/builtins/bigint/conversions.rs b/boa/src/builtins/bigint/conversions.rs index 6cdb1f14f20..1841e5439a4 100644 --- a/boa/src/builtins/bigint/conversions.rs +++ b/boa/src/builtins/bigint/conversions.rs @@ -56,7 +56,7 @@ impl BigInt { /// Returns `std::f64::INFINITY` if the BigInt is too big. #[inline] pub fn to_f64(&self) -> f64 { - self.0.to_f64().unwrap_or(std::f64::INFINITY) + self.0.to_f64().unwrap_or(f64::INFINITY) } #[inline] diff --git a/boa/src/builtins/math/mod.rs b/boa/src/builtins/math/mod.rs index ed177fef3a6..59d1e75f556 100644 --- a/boa/src/builtins/math/mod.rs +++ b/boa/src/builtins/math/mod.rs @@ -15,7 +15,6 @@ use crate::{ builtins::BuiltIn, object::ObjectInitializer, property::Attribute, BoaProfiler, Context, Result, Value, }; -use std::f64; #[cfg(test)] mod tests; @@ -33,6 +32,7 @@ impl BuiltIn for Math { fn init(context: &mut Context) -> (&'static str, Value, Attribute) { let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); + use std::f64; let attribute = Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT; let object = ObjectInitializer::new(context) diff --git a/boa/src/builtins/string/mod.rs b/boa/src/builtins/string/mod.rs index 1e309ada8b4..af9fbcc75a3 100644 --- a/boa/src/builtins/string/mod.rs +++ b/boa/src/builtins/string/mod.rs @@ -27,7 +27,6 @@ use regress::Regex; use std::{ char::{decode_utf16, from_u32}, cmp::{max, min}, - f64::NAN, string::String as StdString, }; @@ -335,7 +334,7 @@ impl String { // Fast path returning NaN when pos is obviously out of range if pos < 0 || pos >= primitive_val.len() as i32 { - return Ok(Value::from(NAN)); + return Ok(Value::from(f64::NAN)); } // Calling .len() on a string would give the wrong result, as they are bytes not the number of unicode code points @@ -344,7 +343,7 @@ impl String { if let Some(utf16_val) = primitive_val.encode_utf16().nth(pos as usize) { Ok(Value::from(f64::from(utf16_val))) } else { - Ok(Value::from(NAN)) + Ok(Value::from(f64::NAN)) } } @@ -1167,7 +1166,7 @@ impl String { // the number of code units from start to the end of the string, // which should always be smaller or equals to both +infinity and i32::max_value let end = if args.len() < 2 { - i32::max_value() + i32::MAX } else { args.get(1) .expect("Could not get argument") @@ -1245,7 +1244,7 @@ impl String { .get(1) .map(|arg| arg.to_integer(context).map(|limit| limit as usize)) .transpose()? - .unwrap_or(std::u32::MAX as usize); + .unwrap_or(u32::MAX as usize); let values: Vec = match separator { None if limit == 0 => vec![], diff --git a/boa/src/exec/tests.rs b/boa/src/exec/tests.rs index 7ee43f05c9b..e86deaca9c8 100644 --- a/boa/src/exec/tests.rs +++ b/boa/src/exec/tests.rs @@ -992,7 +992,7 @@ fn to_int32() { ($from:expr => $to:expr) => { assert_eq!(Value::from($from).to_i32(&mut context).unwrap(), $to); }; - }; + } check_to_int32!(f64::NAN => 0); check_to_int32!(f64::NEG_INFINITY => 0); diff --git a/boa/src/lib.rs b/boa/src/lib.rs index 25c54e44e75..26ba04ca8c0 100644 --- a/boa/src/lib.rs +++ b/boa/src/lib.rs @@ -53,6 +53,8 @@ pub mod object; pub mod profiler; pub mod property; pub mod realm; +// syntax module has a lot of acronyms +#[allow(clippy::upper_case_acronyms)] pub mod syntax; pub mod value; #[cfg(feature = "vm")] diff --git a/boa/src/object/internal_methods.rs b/boa/src/object/internal_methods.rs index 2b9541f5ccc..99409dd7348 100644 --- a/boa/src/object/internal_methods.rs +++ b/boa/src/object/internal_methods.rs @@ -106,7 +106,7 @@ impl GcObject { let own_desc = if let Some(desc) = self.get_own_property(&key) { desc } else if let Some(ref mut parent) = self.get_prototype_of().as_object() { - return Ok(parent.set(key, val, receiver, context)?); + return parent.set(key, val, receiver, context); } else { DataDescriptor::new(Value::undefined(), Attribute::all()).into() }; @@ -363,7 +363,7 @@ impl GcObject { return Ok(false); } if self.ordinary_define_own_property(key, desc) { - if index >= old_len && index < std::u32::MAX { + if index >= old_len && index < u32::MAX { let desc = PropertyDescriptor::Data(DataDescriptor::new( index + 1, old_len_data_desc.attributes(), diff --git a/boa/src/syntax/ast/node/declaration/arrow_function_decl/mod.rs b/boa/src/syntax/ast/node/declaration/arrow_function_decl/mod.rs index f1306209d20..6646a9542dd 100644 --- a/boa/src/syntax/ast/node/declaration/arrow_function_decl/mod.rs +++ b/boa/src/syntax/ast/node/declaration/arrow_function_decl/mod.rs @@ -68,13 +68,13 @@ impl ArrowFunctionDecl { impl Executable for ArrowFunctionDecl { fn run(&self, context: &mut Context) -> Result { - Ok(context.create_function( + context.create_function( self.params().to_vec(), self.body().to_vec(), FunctionFlags::CALLABLE | FunctionFlags::CONSTRUCTABLE | FunctionFlags::LEXICAL_THIS_MODE, - )?) + ) } } diff --git a/boa/src/syntax/ast/node/field/get_const_field/mod.rs b/boa/src/syntax/ast/node/field/get_const_field/mod.rs index 80287d076e5..c5b1de5dbe7 100644 --- a/boa/src/syntax/ast/node/field/get_const_field/mod.rs +++ b/boa/src/syntax/ast/node/field/get_const_field/mod.rs @@ -69,7 +69,7 @@ impl Executable for GetConstField { obj = Value::Object(obj.to_object(context)?); } - Ok(obj.get_field(self.field(), context)?) + obj.get_field(self.field(), context) } } diff --git a/boa/src/syntax/ast/node/field/get_field/mod.rs b/boa/src/syntax/ast/node/field/get_field/mod.rs index e85ac02333a..4fc5fbcb2da 100644 --- a/boa/src/syntax/ast/node/field/get_field/mod.rs +++ b/boa/src/syntax/ast/node/field/get_field/mod.rs @@ -69,7 +69,7 @@ impl Executable for GetField { } let field = self.field().run(context)?; - Ok(obj.get_field(field.to_property_key(context)?, context)?) + obj.get_field(field.to_property_key(context)?, context) } } diff --git a/boa/src/syntax/ast/node/template/mod.rs b/boa/src/syntax/ast/node/template/mod.rs index 5ab8f321692..ec8bb8a67d0 100644 --- a/boa/src/syntax/ast/node/template/mod.rs +++ b/boa/src/syntax/ast/node/template/mod.rs @@ -134,8 +134,7 @@ impl Executable for TaggedTemplate { ), }; - let mut args = Vec::new(); - args.push(template_object); + let mut args = vec![template_object]; for expr in self.exprs.iter() { args.push(expr.run(context)?); } diff --git a/boa/src/syntax/parser/expression/primary/template/mod.rs b/boa/src/syntax/parser/expression/primary/template/mod.rs index cdfed7ea4fa..77721bbacd7 100644 --- a/boa/src/syntax/parser/expression/primary/template/mod.rs +++ b/boa/src/syntax/parser/expression/primary/template/mod.rs @@ -62,11 +62,12 @@ where fn parse(self, cursor: &mut Cursor) -> Result { let _timer = BoaProfiler::global().start_event("TemplateLiteral", "Parsing"); - let mut elements = Vec::new(); - elements.push(TemplateElement::String(self.first.into_boxed_str())); - elements.push(TemplateElement::Expr( - Expression::new(true, self.allow_yield, self.allow_await).parse(cursor)?, - )); + let mut elements = vec![ + TemplateElement::String(self.first.into_boxed_str()), + TemplateElement::Expr( + Expression::new(true, self.allow_yield, self.allow_await).parse(cursor)?, + ), + ]; cursor.expect( TokenKind::Punctuator(Punctuator::CloseBlock), "template literal", diff --git a/boa/src/value/mod.rs b/boa/src/value/mod.rs index 44c91047ba9..99163dc3e20 100644 --- a/boa/src/value/mod.rs +++ b/boa/src/value/mod.rs @@ -20,7 +20,6 @@ use serde_json::{Number as JSONNumber, Value as JSONValue}; use std::{ collections::HashSet, convert::TryFrom, - f64::NAN, fmt::{self, Display}, str::FromStr, }; @@ -92,7 +91,7 @@ impl Value { /// Creates a new number with `NaN` value. #[inline] pub fn nan() -> Self { - Self::number(NAN) + Self::number(f64::NAN) } /// Creates a new string value. diff --git a/boa/src/value/operations.rs b/boa/src/value/operations.rs index 44cc173f8b3..d7e0ac9341a 100644 --- a/boa/src/value/operations.rs +++ b/boa/src/value/operations.rs @@ -423,14 +423,14 @@ impl Value { #[inline] pub fn neg(&self, context: &mut Context) -> Result { Ok(match *self { - Self::Symbol(_) | Self::Undefined => Self::rational(NAN), + Self::Symbol(_) | Self::Undefined => Self::rational(f64::NAN), Self::Object(_) => Self::rational(match self.to_numeric_number(context) { Ok(num) => -num, - Err(_) => NAN, + Err(_) => f64::NAN, }), Self::String(ref str) => Self::rational(match f64::from_str(str) { Ok(num) => -num, - Err(_) => NAN, + Err(_) => f64::NAN, }), Self::Rational(num) => Self::rational(-num), Self::Integer(num) => Self::rational(-f64::from(num)), diff --git a/boa/src/value/tests.rs b/boa/src/value/tests.rs index 81619ffd474..c87e39e9c91 100644 --- a/boa/src/value/tests.rs +++ b/boa/src/value/tests.rs @@ -58,7 +58,7 @@ fn number_is_true() { assert_eq!(Value::from(0.0).to_boolean(), false); assert_eq!(Value::from(-0.0).to_boolean(), false); assert_eq!(Value::from(-1.0).to_boolean(), true); - assert_eq!(Value::from(NAN).to_boolean(), false); + assert_eq!(Value::from(f64::NAN).to_boolean(), false); } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness @@ -569,7 +569,7 @@ fn to_integer_or_infinity() { Ok(IntegerOrInfinity::Integer(0)) ); assert_eq!( - Value::from(NAN).to_integer_or_infinity(&mut context), + Value::from(f64::NAN).to_integer_or_infinity(&mut context), Ok(IntegerOrInfinity::Integer(0)) ); assert_eq!( diff --git a/boa_cli/src/helper.rs b/boa_cli/src/helper.rs index 0049f4a95e5..23f6c9ae7d9 100644 --- a/boa_cli/src/helper.rs +++ b/boa_cli/src/helper.rs @@ -34,6 +34,7 @@ const IDENTIFIER_COLOR: Color = Color::TrueColor { b: 214, }; +#[allow(clippy::upper_case_acronyms)] #[derive(Completer, Helper, Hinter)] pub(crate) struct RLHelper { highlighter: LineHighlighter,