Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style: Respect the new lints from 1.51 #1194

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boa/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value> {
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()`
Expand Down
2 changes: 1 addition & 1 deletion boa/src/builtins/bigint/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion boa/src/builtins/math/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::{
builtins::BuiltIn, object::ObjectInitializer, property::Attribute, BoaProfiler, Context,
Result, Value,
};
use std::f64;

#[cfg(test)]
mod tests;
Expand All @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions boa/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use regress::Regex;
use std::{
char::{decode_utf16, from_u32},
cmp::{max, min},
f64::NAN,
string::String as StdString,
};

Expand Down Expand Up @@ -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
Expand All @@ -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))
}
}

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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<Value> = match separator {
None if limit == 0 => vec![],
Expand Down
2 changes: 1 addition & 1 deletion boa/src/exec/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions boa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
4 changes: 2 additions & 2 deletions boa/src/object/internal_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ impl ArrowFunctionDecl {

impl Executable for ArrowFunctionDecl {
fn run(&self, context: &mut Context) -> Result<Value> {
Ok(context.create_function(
context.create_function(
self.params().to_vec(),
self.body().to_vec(),
FunctionFlags::CALLABLE
| FunctionFlags::CONSTRUCTABLE
| FunctionFlags::LEXICAL_THIS_MODE,
)?)
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion boa/src/syntax/ast/node/field/get_const_field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion boa/src/syntax/ast/node/field/get_field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
3 changes: 1 addition & 2 deletions boa/src/syntax/ast/node/template/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?);
}
Expand Down
11 changes: 6 additions & 5 deletions boa/src/syntax/parser/expression/primary/template/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ where
fn parse(self, cursor: &mut Cursor<R>) -> Result<Self::Output, ParseError> {
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",
Expand Down
3 changes: 1 addition & 2 deletions boa/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions boa/src/value/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,14 @@ impl Value {
#[inline]
pub fn neg(&self, context: &mut Context) -> Result<Value> {
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)),
Expand Down
4 changes: 2 additions & 2 deletions boa/src/value/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!(
Expand Down
1 change: 1 addition & 0 deletions boa_cli/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down