From aac39cdd4b534df77d885a3c4ac0a3f538a14c55 Mon Sep 17 00:00:00 2001 From: Annika Date: Thu, 31 Dec 2020 14:19:08 -0800 Subject: [PATCH] Fix Clippy erorrs (#1015) --- boa/src/builtins/bigint/mod.rs | 2 +- boa/src/builtins/date/mod.rs | 6 +++--- boa/src/builtins/number/mod.rs | 2 +- boa/src/object/mod.rs | 4 ++-- boa/src/syntax/lexer/cursor.rs | 5 +---- boa/src/syntax/lexer/mod.rs | 2 +- boa/src/syntax/lexer/tests.rs | 1 + 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/boa/src/builtins/bigint/mod.rs b/boa/src/builtins/bigint/mod.rs index c6e37c6a59..b5a80f40fa 100644 --- a/boa/src/builtins/bigint/mod.rs +++ b/boa/src/builtins/bigint/mod.rs @@ -139,7 +139,7 @@ impl BigInt { } else { 10 }; - if radix < 2 || radix > 36 { + if !(2..=36).contains(&radix) { return context .throw_range_error("radix must be an integer at least 2 and no greater than 36"); } diff --git a/boa/src/builtins/date/mod.rs b/boa/src/builtins/date/mod.rs index e097e5ce4e..46a437ea52 100644 --- a/boa/src/builtins/date/mod.rs +++ b/boa/src/builtins/date/mod.rs @@ -454,7 +454,7 @@ impl Date { let sec = sec as u32; let milli = milli as u32; - let year = if 0 <= year && year <= 99 { + let year = if (0..=99).contains(&year) { 1900 + year } else { year @@ -936,7 +936,7 @@ impl Date { /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setYear pub fn set_year(&mut self, year: Option, month: Option, day: Option) { if let Some(mut year) = year { - year += if 0f64 <= year && year < 100f64 { + year += if (0f64..100f64).contains(&year) { 1900f64 } else { 0f64 @@ -1330,7 +1330,7 @@ impl Date { let sec = sec as u32; let milli = milli as u32; - let year = if 0 <= year && year <= 99 { + let year = if (0..=99).contains(&year) { 1900 + year } else { year diff --git a/boa/src/builtins/number/mod.rs b/boa/src/builtins/number/mod.rs index 4a8ddd1dcf..8c49d6bb2b 100644 --- a/boa/src/builtins/number/mod.rs +++ b/boa/src/builtins/number/mod.rs @@ -591,7 +591,7 @@ impl Number { .map_or(10, |radix| radix as u8); // 4. If radixNumber < 2 or radixNumber > 36, throw a RangeError exception. - if radix < 2 || radix > 36 { + if !(2..=36).contains(&radix) { return context .throw_range_error("radix must be an integer at least 2 and no greater than 36"); } diff --git a/boa/src/object/mod.rs b/boa/src/object/mod.rs index a2aecf2f07..02ef2b7d74 100644 --- a/boa/src/object/mod.rs +++ b/boa/src/object/mod.rs @@ -169,7 +169,7 @@ impl Object { // TODO: proto should be a &Value here #[inline] pub fn create(proto: Value) -> Self { - let mut obj = Self::default(); + let mut obj = Self::new(); obj.prototype = proto; obj } @@ -474,7 +474,7 @@ impl Object { /// Similar to `Value::new_object`, but you can pass a prototype to create from, plus a kind #[inline] pub fn with_prototype(proto: Value, data: ObjectData) -> Object { - let mut object = Object::default(); + let mut object = Object::new(); object.data = data; object.set_prototype_instance(proto); object diff --git a/boa/src/syntax/lexer/cursor.rs b/boa/src/syntax/lexer/cursor.rs index 79dc699969..7446744603 100644 --- a/boa/src/syntax/lexer/cursor.rs +++ b/boa/src/syntax/lexer/cursor.rs @@ -491,10 +491,7 @@ fn utf8_is_first_byte(byte: u8) -> bool { #[inline] fn unwrap_or_0(opt: Option) -> u8 { - match opt { - Some(byte) => byte, - None => 0, - } + opt.unwrap_or(0) } #[inline] diff --git a/boa/src/syntax/lexer/mod.rs b/boa/src/syntax/lexer/mod.rs index d4ca507abb..cff616fe4b 100644 --- a/boa/src/syntax/lexer/mod.rs +++ b/boa/src/syntax/lexer/mod.rs @@ -214,7 +214,7 @@ impl Lexer { Span::new(start, self.cursor.pos()), )), '.' => { - if self.cursor.peek()?.map(|c| c >= b'0' && c <= b'9') == Some(true) { + if self.cursor.peek()?.map(|c| (b'0'..=b'9').contains(&c)) == Some(true) { NumberLiteral::new(next_ch as u8).lex(&mut self.cursor, start) } else { SpreadLiteral::new().lex(&mut self.cursor, start) diff --git a/boa/src/syntax/lexer/tests.rs b/boa/src/syntax/lexer/tests.rs index 5806b81adc..ebffe9e5b3 100644 --- a/boa/src/syntax/lexer/tests.rs +++ b/boa/src/syntax/lexer/tests.rs @@ -759,6 +759,7 @@ fn illegal_code_point_following_numeric_literal() { let mut lexer = Lexer::new(&br#"17.4\u{2764}"#[..]); assert!( lexer.next().is_err(), + "{}", r#"IdentifierStart \u{2764} following NumericLiteral not rejected as expected"# ); }