From 01b5cec04f079b7efe9fe643b310a7e9ce2a415a Mon Sep 17 00:00:00 2001 From: David Date: Fri, 25 Sep 2020 16:42:11 +0300 Subject: [PATCH] Fix clippy on Nightly (#668) --- boa/src/builtins/string/mod.rs | 19 ++++++++++--------- .../function_environment_record.rs | 5 +---- boa/src/environment/lexical_environment.rs | 16 ++++++++++------ boa/src/syntax/lexer/mod.rs | 8 ++++---- .../expression/assignment/exponentiation.rs | 18 +++++++++--------- .../parser/expression/assignment/mod.rs | 6 +----- boa/src/value/mod.rs | 5 +---- 7 files changed, 36 insertions(+), 41 deletions(-) diff --git a/boa/src/builtins/string/mod.rs b/boa/src/builtins/string/mod.rs index e4520ee4db..b69487e23f 100644 --- a/boa/src/builtins/string/mod.rs +++ b/boa/src/builtins/string/mod.rs @@ -788,15 +788,16 @@ impl String { // `\u{0085}' (next line) // And does not include: // '\u{FEFF}' (zero width non-breaking space) - match c { - // Explicit whitespace: https://tc39.es/ecma262/#sec-white-space - '\u{0009}' | '\u{000B}' | '\u{000C}' | '\u{0020}' | '\u{00A0}' | '\u{FEFF}' | - // Unicode Space_Seperator category - '\u{1680}' | '\u{2000}'..='\u{200A}' | '\u{202F}' | '\u{205F}' | '\u{3000}' | - // Line terminators: https://tc39.es/ecma262/#sec-line-terminators - '\u{000A}' | '\u{000D}' | '\u{2028}' | '\u{2029}' => true, - _ => false, - } + // Explicit whitespace: https://tc39.es/ecma262/#sec-white-space + matches!( + c, + '\u{0009}' | '\u{000B}' | '\u{000C}' | '\u{0020}' | '\u{00A0}' | '\u{FEFF}' | + // Unicode Space_Seperator category + '\u{1680}' | '\u{2000}' + ..='\u{200A}' | '\u{202F}' | '\u{205F}' | '\u{3000}' | + // Line terminators: https://tc39.es/ecma262/#sec-line-terminators + '\u{000A}' | '\u{000D}' | '\u{2028}' | '\u{2029}' + ) } /// String.prototype.trim() diff --git a/boa/src/environment/function_environment_record.rs b/boa/src/environment/function_environment_record.rs index 1681735d7b..af4a1b9ba6 100644 --- a/boa/src/environment/function_environment_record.rs +++ b/boa/src/environment/function_environment_record.rs @@ -218,10 +218,7 @@ impl EnvironmentRecordTrait for FunctionEnvironmentRecord { } fn has_this_binding(&self) -> bool { - match self.this_binding_status { - BindingStatus::Lexical => false, - _ => true, - } + !matches!(self.this_binding_status, BindingStatus::Lexical) } fn with_base_object(&self) -> Value { diff --git a/boa/src/environment/lexical_environment.rs b/boa/src/environment/lexical_environment.rs index 698acbd2dd..b7163ae621 100644 --- a/boa/src/environment/lexical_environment.rs +++ b/boa/src/environment/lexical_environment.rs @@ -130,9 +130,11 @@ impl LexicalEnvironment { // Find the first function or global environment (from the top of the stack) let env = self .environments() - .find(|env| match env.borrow().get_environment_type() { - EnvironmentType::Function | EnvironmentType::Global => true, - _ => false, + .find(|env| { + matches!( + env.borrow().get_environment_type(), + EnvironmentType::Function | EnvironmentType::Global + ) }) .expect("No function or global environment"); @@ -156,9 +158,11 @@ impl LexicalEnvironment { // Find the first function or global environment (from the top of the stack) let env = self .environments() - .find(|env| match env.borrow().get_environment_type() { - EnvironmentType::Function | EnvironmentType::Global => true, - _ => false, + .find(|env| { + matches!( + env.borrow().get_environment_type(), + EnvironmentType::Function | EnvironmentType::Global + ) }) .expect("No function or global environment"); diff --git a/boa/src/syntax/lexer/mod.rs b/boa/src/syntax/lexer/mod.rs index fffef6c9e2..4fd8f75c3a 100644 --- a/boa/src/syntax/lexer/mod.rs +++ b/boa/src/syntax/lexer/mod.rs @@ -70,12 +70,12 @@ impl Lexer { /// /// [More information](https://tc39.es/ecma262/#table-32) fn is_whitespace(ch: char) -> bool { - match ch { + matches!( + ch, '\u{0020}' | '\u{0009}' | '\u{000B}' | '\u{000C}' | '\u{00A0}' | '\u{FEFF}' | // Unicode Space_Seperator category (minus \u{0020} and \u{00A0} which are allready stated above) - '\u{1680}' | '\u{2000}'..='\u{200A}' | '\u{202F}' | '\u{205F}' | '\u{3000}' => true, - _ => false, - } + '\u{1680}' | '\u{2000}'..='\u{200A}' | '\u{202F}' | '\u{205F}' | '\u{3000}' + ) } /// Sets the goal symbol for the lexer. diff --git a/boa/src/syntax/parser/expression/assignment/exponentiation.rs b/boa/src/syntax/parser/expression/assignment/exponentiation.rs index 94b9ad6d9c..e9eac4c9dd 100644 --- a/boa/src/syntax/parser/expression/assignment/exponentiation.rs +++ b/boa/src/syntax/parser/expression/assignment/exponentiation.rs @@ -60,16 +60,16 @@ where R: Read, { Ok(if let Some(tok) = cursor.peek(0)? { - match tok.kind() { + matches!( + tok.kind(), TokenKind::Keyword(Keyword::Delete) - | TokenKind::Keyword(Keyword::Void) - | TokenKind::Keyword(Keyword::TypeOf) - | TokenKind::Punctuator(Punctuator::Add) - | TokenKind::Punctuator(Punctuator::Sub) - | TokenKind::Punctuator(Punctuator::Not) - | TokenKind::Punctuator(Punctuator::Neg) => true, - _ => false, - } + | TokenKind::Keyword(Keyword::Void) + | TokenKind::Keyword(Keyword::TypeOf) + | TokenKind::Punctuator(Punctuator::Add) + | TokenKind::Punctuator(Punctuator::Sub) + | TokenKind::Punctuator(Punctuator::Not) + | TokenKind::Punctuator(Punctuator::Neg) + ) } else { false }) diff --git a/boa/src/syntax/parser/expression/assignment/mod.rs b/boa/src/syntax/parser/expression/assignment/mod.rs index aa3baeec1f..6fccf62e02 100644 --- a/boa/src/syntax/parser/expression/assignment/mod.rs +++ b/boa/src/syntax/parser/expression/assignment/mod.rs @@ -217,9 +217,5 @@ where /// [spec]: https://tc39.es/ecma262/#sec-assignment-operators-static-semantics-early-errors #[inline] pub(crate) fn is_assignable(node: &Node) -> bool { - if let Node::Const(_) | Node::ArrayDecl(_) = node { - false - } else { - true - } + !matches!(node, Node::Const(_) | Node::ArrayDecl(_)) } diff --git a/boa/src/value/mod.rs b/boa/src/value/mod.rs index f10fbaedc0..c3149da12c 100644 --- a/boa/src/value/mod.rs +++ b/boa/src/value/mod.rs @@ -292,10 +292,7 @@ impl Value { /// Returns true if the value the global for a Realm pub fn is_global(&self) -> bool { match self { - Value::Object(object) => match object.borrow().data { - ObjectData::Global => true, - _ => false, - }, + Value::Object(object) => matches!(object.borrow().data, ObjectData::Global), _ => false, } }