From 8cc938747d7ac7f7d3a655d1588faed0549e0619 Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Mon, 14 Nov 2022 01:01:57 +0100 Subject: [PATCH 1/2] Restructure lint deny list in boa_ast --- boa_ast/src/declaration/mod.rs | 36 +++--- boa_ast/src/declaration/variable.rs | 46 ++++---- boa_ast/src/expression/access.rs | 38 +++--- boa_ast/src/expression/await.rs | 2 +- boa_ast/src/expression/call.rs | 6 +- boa_ast/src/expression/identifier.rs | 4 +- boa_ast/src/expression/literal/array.rs | 2 +- boa_ast/src/expression/literal/mod.rs | 6 +- boa_ast/src/expression/literal/object.rs | 18 +-- boa_ast/src/expression/literal/template.rs | 10 +- boa_ast/src/expression/mod.rs | 110 +++++++++--------- boa_ast/src/expression/new.rs | 6 +- boa_ast/src/expression/operator/assign/mod.rs | 24 ++-- boa_ast/src/expression/operator/assign/op.rs | 2 +- boa_ast/src/expression/operator/binary/mod.rs | 6 +- boa_ast/src/expression/operator/binary/op.rs | 10 +- .../src/expression/operator/conditional.rs | 6 +- boa_ast/src/expression/operator/unary/mod.rs | 2 +- boa_ast/src/expression/operator/unary/op.rs | 2 +- boa_ast/src/expression/optional.rs | 24 ++-- boa_ast/src/expression/spread.rs | 2 +- boa_ast/src/expression/tagged_template.rs | 8 +- boa_ast/src/expression/yield.rs | 2 +- boa_ast/src/function/arrow_function.rs | 12 +- boa_ast/src/function/async_arrow_function.rs | 8 +- boa_ast/src/function/async_function.rs | 10 +- boa_ast/src/function/async_generator.rs | 10 +- boa_ast/src/function/class.rs | 62 +++++----- boa_ast/src/function/generator.rs | 10 +- boa_ast/src/function/mod.rs | 12 +- boa_ast/src/function/parameters.rs | 22 ++-- boa_ast/src/keyword.rs | 4 +- boa_ast/src/lib.rs | 86 ++++++++------ boa_ast/src/pattern.rs | 68 ++++++----- boa_ast/src/position.rs | 8 +- boa_ast/src/property.rs | 65 +++++------ boa_ast/src/statement/block.rs | 2 +- boa_ast/src/statement/if.rs | 4 +- boa_ast/src/statement/iteration/break.rs | 13 +-- boa_ast/src/statement/iteration/continue.rs | 13 +-- .../src/statement/iteration/do_while_loop.rs | 4 +- .../src/statement/iteration/for_in_loop.rs | 6 +- boa_ast/src/statement/iteration/for_loop.rs | 36 +++--- .../src/statement/iteration/for_of_loop.rs | 8 +- boa_ast/src/statement/iteration/mod.rs | 20 ++-- boa_ast/src/statement/iteration/while_loop.rs | 4 +- boa_ast/src/statement/labelled.rs | 16 +-- boa_ast/src/statement/mod.rs | 68 +++++------ boa_ast/src/statement/return.rs | 12 +- boa_ast/src/statement/switch.rs | 12 +- boa_ast/src/statement/throw.rs | 4 +- boa_ast/src/statement/try.rs | 16 +-- boa_ast/src/statement_list.rs | 24 ++-- 53 files changed, 503 insertions(+), 508 deletions(-) diff --git a/boa_ast/src/declaration/mod.rs b/boa_ast/src/declaration/mod.rs index 02f3e584c85..fa89cca1f58 100644 --- a/boa_ast/src/declaration/mod.rs +++ b/boa_ast/src/declaration/mod.rs @@ -52,12 +52,12 @@ pub enum Declaration { impl ToIndentedString for Declaration { fn to_indented_string(&self, interner: &Interner, indentation: usize) -> String { match self { - Declaration::Function(f) => f.to_indented_string(interner, indentation), - Declaration::Generator(g) => g.to_indented_string(interner, indentation), - Declaration::AsyncFunction(af) => af.to_indented_string(interner, indentation), - Declaration::AsyncGenerator(ag) => ag.to_indented_string(interner, indentation), - Declaration::Class(c) => c.to_indented_string(interner, indentation), - Declaration::Lexical(l) => { + Self::Function(f) => f.to_indented_string(interner, indentation), + Self::Generator(g) => g.to_indented_string(interner, indentation), + Self::AsyncFunction(af) => af.to_indented_string(interner, indentation), + Self::AsyncGenerator(ag) => ag.to_indented_string(interner, indentation), + Self::Class(c) => c.to_indented_string(interner, indentation), + Self::Lexical(l) => { let mut s = l.to_interned_string(interner); s.push(';'); s @@ -72,12 +72,12 @@ impl VisitWith for Declaration { V: Visitor<'a>, { match self { - Declaration::Function(f) => visitor.visit_function(f), - Declaration::Generator(g) => visitor.visit_generator(g), - Declaration::AsyncFunction(af) => visitor.visit_async_function(af), - Declaration::AsyncGenerator(ag) => visitor.visit_async_generator(ag), - Declaration::Class(c) => visitor.visit_class(c), - Declaration::Lexical(ld) => visitor.visit_lexical_declaration(ld), + Self::Function(f) => visitor.visit_function(f), + Self::Generator(g) => visitor.visit_generator(g), + Self::AsyncFunction(af) => visitor.visit_async_function(af), + Self::AsyncGenerator(ag) => visitor.visit_async_generator(ag), + Self::Class(c) => visitor.visit_class(c), + Self::Lexical(ld) => visitor.visit_lexical_declaration(ld), } } @@ -86,12 +86,12 @@ impl VisitWith for Declaration { V: VisitorMut<'a>, { match self { - Declaration::Function(f) => visitor.visit_function_mut(f), - Declaration::Generator(g) => visitor.visit_generator_mut(g), - Declaration::AsyncFunction(af) => visitor.visit_async_function_mut(af), - Declaration::AsyncGenerator(ag) => visitor.visit_async_generator_mut(ag), - Declaration::Class(c) => visitor.visit_class_mut(c), - Declaration::Lexical(ld) => visitor.visit_lexical_declaration_mut(ld), + Self::Function(f) => visitor.visit_function_mut(f), + Self::Generator(g) => visitor.visit_generator_mut(g), + Self::AsyncFunction(af) => visitor.visit_async_function_mut(af), + Self::AsyncGenerator(ag) => visitor.visit_async_generator_mut(ag), + Self::Class(c) => visitor.visit_class_mut(c), + Self::Lexical(ld) => visitor.visit_lexical_declaration_mut(ld), } } } diff --git a/boa_ast/src/declaration/variable.rs b/boa_ast/src/declaration/variable.rs index 921f57ffe1e..e3012a7e270 100644 --- a/boa_ast/src/declaration/variable.rs +++ b/boa_ast/src/declaration/variable.rs @@ -51,7 +51,7 @@ pub struct VarDeclaration(pub VariableList); impl From for Statement { fn from(var: VarDeclaration) -> Self { - Statement::Var(var) + Self::Var(var) } } @@ -110,16 +110,16 @@ pub enum LexicalDeclaration { impl LexicalDeclaration { /// Gets the inner variable list of the `LexicalDeclaration` #[must_use] - pub fn variable_list(&self) -> &VariableList { + pub const fn variable_list(&self) -> &VariableList { match self { - LexicalDeclaration::Const(list) | LexicalDeclaration::Let(list) => list, + Self::Const(list) | Self::Let(list) => list, } } } impl From for Declaration { fn from(lex: LexicalDeclaration) -> Self { - Declaration::Lexical(lex) + Self::Lexical(lex) } } @@ -128,8 +128,8 @@ impl ToInternedString for LexicalDeclaration { format!( "{} {}", match &self { - LexicalDeclaration::Let(_) => "let", - LexicalDeclaration::Const(_) => "const", + Self::Let(_) => "let", + Self::Const(_) => "const", }, self.variable_list().to_interned_string(interner) ) @@ -142,9 +142,7 @@ impl VisitWith for LexicalDeclaration { V: Visitor<'a>, { match self { - LexicalDeclaration::Const(vars) | LexicalDeclaration::Let(vars) => { - visitor.visit_variable_list(vars) - } + Self::Const(vars) | Self::Let(vars) => visitor.visit_variable_list(vars), } } @@ -153,9 +151,7 @@ impl VisitWith for LexicalDeclaration { V: VisitorMut<'a>, { match self { - LexicalDeclaration::Const(vars) | LexicalDeclaration::Let(vars) => { - visitor.visit_variable_list_mut(vars) - } + Self::Const(vars) | Self::Let(vars) => visitor.visit_variable_list_mut(vars), } } } @@ -176,7 +172,7 @@ impl VariableList { return None; } - Some(VariableList { list }) + Some(Self { list }) } } @@ -228,7 +224,7 @@ impl TryFrom> for VariableList { type Error = TryFromVariableListError; fn try_from(value: Box<[Variable]>) -> Result { - VariableList::new(value).ok_or(TryFromVariableListError(())) + Self::new(value).ok_or(TryFromVariableListError(())) } } @@ -236,7 +232,7 @@ impl TryFrom> for VariableList { type Error = TryFromVariableListError; fn try_from(value: Vec) -> Result { - VariableList::try_from(value.into_boxed_slice()) + Self::try_from(value.into_boxed_slice()) } } @@ -275,7 +271,7 @@ impl Variable { /// Creates a new variable declaration from a `BindingIdentifier`. #[inline] #[must_use] - pub fn from_identifier(ident: Identifier, init: Option) -> Self { + pub const fn from_identifier(ident: Identifier, init: Option) -> Self { Self { binding: Binding::Identifier(ident), init, @@ -285,7 +281,7 @@ impl Variable { /// Creates a new variable declaration from a `Pattern`. #[inline] #[must_use] - pub fn from_pattern(pattern: Pattern, init: Option) -> Self { + pub const fn from_pattern(pattern: Pattern, init: Option) -> Self { Self { binding: Binding::Pattern(pattern), init, @@ -293,14 +289,14 @@ impl Variable { } /// Gets the variable declaration binding. #[must_use] - pub fn binding(&self) -> &Binding { + pub const fn binding(&self) -> &Binding { &self.binding } /// Gets the initialization expression for the variable declaration, if any. #[inline] #[must_use] - pub fn init(&self) -> Option<&Expression> { + pub const fn init(&self) -> Option<&Expression> { self.init.as_ref() } } @@ -360,8 +356,8 @@ impl From for Binding { impl ToInternedString for Binding { fn to_interned_string(&self, interner: &Interner) -> String { match self { - Binding::Identifier(id) => id.to_interned_string(interner), - Binding::Pattern(ref pattern) => pattern.to_interned_string(interner), + Self::Identifier(id) => id.to_interned_string(interner), + Self::Pattern(ref pattern) => pattern.to_interned_string(interner), } } } @@ -372,8 +368,8 @@ impl VisitWith for Binding { V: Visitor<'a>, { match self { - Binding::Identifier(id) => visitor.visit_identifier(id), - Binding::Pattern(pattern) => visitor.visit_pattern(pattern), + Self::Identifier(id) => visitor.visit_identifier(id), + Self::Pattern(pattern) => visitor.visit_pattern(pattern), } } @@ -382,8 +378,8 @@ impl VisitWith for Binding { V: VisitorMut<'a>, { match self { - Binding::Identifier(id) => visitor.visit_identifier_mut(id), - Binding::Pattern(pattern) => visitor.visit_pattern_mut(pattern), + Self::Identifier(id) => visitor.visit_identifier_mut(id), + Self::Pattern(pattern) => visitor.visit_pattern_mut(pattern), } } } diff --git a/boa_ast/src/expression/access.rs b/boa_ast/src/expression/access.rs index b66f2a11cff..9a8abe348a4 100644 --- a/boa_ast/src/expression/access.rs +++ b/boa_ast/src/expression/access.rs @@ -53,8 +53,8 @@ impl VisitWith for PropertyAccessField { V: Visitor<'a>, { match self { - PropertyAccessField::Const(sym) => visitor.visit_sym(sym), - PropertyAccessField::Expr(expr) => visitor.visit_expression(expr), + Self::Const(sym) => visitor.visit_sym(sym), + Self::Expr(expr) => visitor.visit_expression(expr), } } @@ -63,8 +63,8 @@ impl VisitWith for PropertyAccessField { V: VisitorMut<'a>, { match self { - PropertyAccessField::Const(sym) => visitor.visit_sym_mut(sym), - PropertyAccessField::Expr(expr) => visitor.visit_expression_mut(&mut *expr), + Self::Const(sym) => visitor.visit_sym_mut(sym), + Self::Expr(expr) => visitor.visit_expression_mut(&mut *expr), } } } @@ -88,9 +88,9 @@ impl ToInternedString for PropertyAccess { #[inline] fn to_interned_string(&self, interner: &Interner) -> String { match self { - PropertyAccess::Simple(s) => s.to_interned_string(interner), - PropertyAccess::Private(p) => p.to_interned_string(interner), - PropertyAccess::Super(s) => s.to_interned_string(interner), + Self::Simple(s) => s.to_interned_string(interner), + Self::Private(p) => p.to_interned_string(interner), + Self::Super(s) => s.to_interned_string(interner), } } } @@ -108,9 +108,9 @@ impl VisitWith for PropertyAccess { V: Visitor<'a>, { match self { - PropertyAccess::Simple(spa) => visitor.visit_simple_property_access(spa), - PropertyAccess::Private(ppa) => visitor.visit_private_property_access(ppa), - PropertyAccess::Super(supa) => visitor.visit_super_property_access(supa), + Self::Simple(spa) => visitor.visit_simple_property_access(spa), + Self::Private(ppa) => visitor.visit_private_property_access(ppa), + Self::Super(supa) => visitor.visit_super_property_access(supa), } } @@ -119,9 +119,9 @@ impl VisitWith for PropertyAccess { V: VisitorMut<'a>, { match self { - PropertyAccess::Simple(spa) => visitor.visit_simple_property_access_mut(spa), - PropertyAccess::Private(ppa) => visitor.visit_private_property_access_mut(ppa), - PropertyAccess::Super(supa) => visitor.visit_super_property_access_mut(supa), + Self::Simple(spa) => visitor.visit_simple_property_access_mut(spa), + Self::Private(ppa) => visitor.visit_private_property_access_mut(ppa), + Self::Super(supa) => visitor.visit_super_property_access_mut(supa), } } } @@ -139,14 +139,14 @@ impl SimplePropertyAccess { /// Gets the target object of the property access. #[inline] #[must_use] - pub fn target(&self) -> &Expression { + pub const fn target(&self) -> &Expression { &self.target } /// Gets the accessed field of the target object. #[inline] #[must_use] - pub fn field(&self) -> &PropertyAccessField { + pub const fn field(&self) -> &PropertyAccessField { &self.field } @@ -233,14 +233,14 @@ impl PrivatePropertyAccess { /// Gets the original object from where to get the field from. #[inline] #[must_use] - pub fn target(&self) -> &Expression { + pub const fn target(&self) -> &Expression { &self.target } /// Gets the name of the field to retrieve. #[inline] #[must_use] - pub fn field(&self) -> Sym { + pub const fn field(&self) -> Sym { self.field } } @@ -298,14 +298,14 @@ pub struct SuperPropertyAccess { impl SuperPropertyAccess { /// Creates a new property access field node. #[must_use] - pub fn new(field: PropertyAccessField) -> Self { + pub const fn new(field: PropertyAccessField) -> Self { Self { field } } /// Gets the name of the field to retrieve. #[inline] #[must_use] - pub fn field(&self) -> &PropertyAccessField { + pub const fn field(&self) -> &PropertyAccessField { &self.field } } diff --git a/boa_ast/src/expression/await.rs b/boa_ast/src/expression/await.rs index 8c8786311ad..079bf831c31 100644 --- a/boa_ast/src/expression/await.rs +++ b/boa_ast/src/expression/await.rs @@ -26,7 +26,7 @@ impl Await { /// Return the target expression that should be awaited. #[inline] #[must_use] - pub fn target(&self) -> &Expression { + pub const fn target(&self) -> &Expression { &self.target } } diff --git a/boa_ast/src/expression/call.rs b/boa_ast/src/expression/call.rs index 3787ad99d84..5b978242615 100644 --- a/boa_ast/src/expression/call.rs +++ b/boa_ast/src/expression/call.rs @@ -42,14 +42,14 @@ impl Call { /// Gets the target function of this call expression. #[inline] #[must_use] - pub fn function(&self) -> &Expression { + pub const fn function(&self) -> &Expression { &self.function } /// Retrieves the arguments passed to the function. #[inline] #[must_use] - pub fn args(&self) -> &[Expression] { + pub const fn args(&self) -> &[Expression] { &self.args } } @@ -122,7 +122,7 @@ impl SuperCall { /// Retrieves the arguments of the super call. #[must_use] - pub fn arguments(&self) -> &[Expression] { + pub const fn arguments(&self) -> &[Expression] { &self.args } } diff --git a/boa_ast/src/expression/identifier.rs b/boa_ast/src/expression/identifier.rs index 0bf6844744f..0f7f73a05b7 100644 --- a/boa_ast/src/expression/identifier.rs +++ b/boa_ast/src/expression/identifier.rs @@ -68,14 +68,14 @@ impl Identifier { /// Creates a new identifier AST Expression. #[inline] #[must_use] - pub fn new(ident: Sym) -> Self { + pub const fn new(ident: Sym) -> Self { Self { ident } } /// Retrieves the identifier's string symbol in the interner. #[inline] #[must_use] - pub fn sym(self) -> Sym { + pub const fn sym(self) -> Sym { self.ident } } diff --git a/boa_ast/src/expression/literal/array.rs b/boa_ast/src/expression/literal/array.rs index 631d0c9fb3a..2f599d12cf8 100644 --- a/boa_ast/src/expression/literal/array.rs +++ b/boa_ast/src/expression/literal/array.rs @@ -47,7 +47,7 @@ impl ArrayLiteral { /// Indicates if a spread operator in the array literal has a trailing comma. /// This is a syntax error in some cases. #[must_use] - pub fn has_trailing_comma_spread(&self) -> bool { + pub const fn has_trailing_comma_spread(&self) -> bool { self.has_trailing_comma_spread } diff --git a/boa_ast/src/expression/literal/mod.rs b/boa_ast/src/expression/literal/mod.rs index 60951351d3b..beed8d8f900 100644 --- a/boa_ast/src/expression/literal/mod.rs +++ b/boa_ast/src/expression/literal/mod.rs @@ -167,7 +167,7 @@ impl From for Literal { impl From for Expression { #[inline] fn from(lit: Literal) -> Self { - Expression::Literal(lit) + Self::Literal(lit) } } @@ -193,7 +193,7 @@ impl VisitWith for Literal { where V: Visitor<'a>, { - if let Literal::String(sym) = self { + if let Self::String(sym) = self { visitor.visit_sym(sym) } else { ControlFlow::Continue(()) @@ -204,7 +204,7 @@ impl VisitWith for Literal { where V: VisitorMut<'a>, { - if let Literal::String(sym) = self { + if let Self::String(sym) = self { visitor.visit_sym_mut(sym) } else { ControlFlow::Continue(()) diff --git a/boa_ast/src/expression/literal/object.rs b/boa_ast/src/expression/literal/object.rs index 1736a2e31f2..59c7587754a 100644 --- a/boa_ast/src/expression/literal/object.rs +++ b/boa_ast/src/expression/literal/object.rs @@ -43,7 +43,7 @@ impl ObjectLiteral { /// Gets the object literal properties #[inline] #[must_use] - pub fn properties(&self) -> &[PropertyDefinition] { + pub const fn properties(&self) -> &[PropertyDefinition] { &self.properties } @@ -121,18 +121,12 @@ impl ObjectLiteral { return None; } excluded_keys.push(*ident); - bindings.push(ObjectPatternElement::SingleName { - ident: *ident, - name: PropertyName::Literal(name), - default_init: Some(assign.rhs().clone()), - }); - } else { - bindings.push(ObjectPatternElement::SingleName { - ident: *ident, - name: PropertyName::Literal(name), - default_init: Some(assign.rhs().clone()), - }); } + bindings.push(ObjectPatternElement::SingleName { + ident: *ident, + name: PropertyName::Literal(name), + default_init: Some(assign.rhs().clone()), + }); } else { return None; } diff --git a/boa_ast/src/expression/literal/template.rs b/boa_ast/src/expression/literal/template.rs index 7c3f4bc189c..e899c4564d2 100644 --- a/boa_ast/src/expression/literal/template.rs +++ b/boa_ast/src/expression/literal/template.rs @@ -60,7 +60,7 @@ impl TemplateLiteral { /// Gets the element list of this `TemplateLiteral`. #[must_use] - pub fn elements(&self) -> &[TemplateElement] { + pub const fn elements(&self) -> &[TemplateElement] { &self.elements } } @@ -116,8 +116,8 @@ impl VisitWith for TemplateElement { V: Visitor<'a>, { match self { - TemplateElement::String(sym) => visitor.visit_sym(sym), - TemplateElement::Expr(expr) => visitor.visit_expression(expr), + Self::String(sym) => visitor.visit_sym(sym), + Self::Expr(expr) => visitor.visit_expression(expr), } } @@ -126,8 +126,8 @@ impl VisitWith for TemplateElement { V: VisitorMut<'a>, { match self { - TemplateElement::String(sym) => visitor.visit_sym_mut(sym), - TemplateElement::Expr(expr) => visitor.visit_expression_mut(expr), + Self::String(sym) => visitor.visit_sym_mut(sym), + Self::Expr(expr) => visitor.visit_expression_mut(expr), } } } diff --git a/boa_ast/src/expression/mod.rs b/boa_ast/src/expression/mod.rs index ad048080947..47b389b8067 100644 --- a/boa_ast/src/expression/mod.rs +++ b/boa_ast/src/expression/mod.rs @@ -200,7 +200,7 @@ impl Expression { impl From for Statement { #[inline] fn from(expr: Expression) -> Self { - Statement::Expression(expr) + Self::Expression(expr) } } @@ -217,33 +217,33 @@ impl VisitWith for Expression { V: Visitor<'a>, { match self { - Expression::Identifier(id) => visitor.visit_identifier(id), - Expression::Literal(lit) => visitor.visit_literal(lit), - Expression::ArrayLiteral(arlit) => visitor.visit_array_literal(arlit), - Expression::ObjectLiteral(olit) => visitor.visit_object_literal(olit), - Expression::Spread(sp) => visitor.visit_spread(sp), - Expression::Function(f) => visitor.visit_function(f), - Expression::ArrowFunction(af) => visitor.visit_arrow_function(af), - Expression::AsyncArrowFunction(af) => visitor.visit_async_arrow_function(af), - Expression::Generator(g) => visitor.visit_generator(g), - Expression::AsyncFunction(af) => visitor.visit_async_function(af), - Expression::AsyncGenerator(ag) => visitor.visit_async_generator(ag), - Expression::Class(c) => visitor.visit_class(c), - Expression::TemplateLiteral(tlit) => visitor.visit_template_literal(tlit), - Expression::PropertyAccess(pa) => visitor.visit_property_access(pa), - Expression::New(n) => visitor.visit_new(n), - Expression::Call(c) => visitor.visit_call(c), - Expression::SuperCall(sc) => visitor.visit_super_call(sc), - Expression::Optional(opt) => visitor.visit_optional(opt), - Expression::TaggedTemplate(tt) => visitor.visit_tagged_template(tt), - Expression::Assign(a) => visitor.visit_assign(a), - Expression::Unary(u) => visitor.visit_unary(u), - Expression::Binary(b) => visitor.visit_binary(b), - Expression::Conditional(c) => visitor.visit_conditional(c), - Expression::Await(a) => visitor.visit_await(a), - Expression::Yield(y) => visitor.visit_yield(y), - Expression::FormalParameterList(fpl) => visitor.visit_formal_parameter_list(fpl), - Expression::This | Expression::NewTarget => { + Self::Identifier(id) => visitor.visit_identifier(id), + Self::Literal(lit) => visitor.visit_literal(lit), + Self::ArrayLiteral(arlit) => visitor.visit_array_literal(arlit), + Self::ObjectLiteral(olit) => visitor.visit_object_literal(olit), + Self::Spread(sp) => visitor.visit_spread(sp), + Self::Function(f) => visitor.visit_function(f), + Self::ArrowFunction(af) => visitor.visit_arrow_function(af), + Self::AsyncArrowFunction(af) => visitor.visit_async_arrow_function(af), + Self::Generator(g) => visitor.visit_generator(g), + Self::AsyncFunction(af) => visitor.visit_async_function(af), + Self::AsyncGenerator(ag) => visitor.visit_async_generator(ag), + Self::Class(c) => visitor.visit_class(c), + Self::TemplateLiteral(tlit) => visitor.visit_template_literal(tlit), + Self::PropertyAccess(pa) => visitor.visit_property_access(pa), + Self::New(n) => visitor.visit_new(n), + Self::Call(c) => visitor.visit_call(c), + Self::SuperCall(sc) => visitor.visit_super_call(sc), + Self::Optional(opt) => visitor.visit_optional(opt), + Self::TaggedTemplate(tt) => visitor.visit_tagged_template(tt), + Self::Assign(a) => visitor.visit_assign(a), + Self::Unary(u) => visitor.visit_unary(u), + Self::Binary(b) => visitor.visit_binary(b), + Self::Conditional(c) => visitor.visit_conditional(c), + Self::Await(a) => visitor.visit_await(a), + Self::Yield(y) => visitor.visit_yield(y), + Self::FormalParameterList(fpl) => visitor.visit_formal_parameter_list(fpl), + Self::This | Self::NewTarget => { // do nothing; can be handled as special case by visitor ControlFlow::Continue(()) } @@ -255,33 +255,33 @@ impl VisitWith for Expression { V: VisitorMut<'a>, { match self { - Expression::Identifier(id) => visitor.visit_identifier_mut(id), - Expression::Literal(lit) => visitor.visit_literal_mut(lit), - Expression::ArrayLiteral(arlit) => visitor.visit_array_literal_mut(arlit), - Expression::ObjectLiteral(olit) => visitor.visit_object_literal_mut(olit), - Expression::Spread(sp) => visitor.visit_spread_mut(sp), - Expression::Function(f) => visitor.visit_function_mut(f), - Expression::ArrowFunction(af) => visitor.visit_arrow_function_mut(af), - Expression::AsyncArrowFunction(af) => visitor.visit_async_arrow_function_mut(af), - Expression::Generator(g) => visitor.visit_generator_mut(g), - Expression::AsyncFunction(af) => visitor.visit_async_function_mut(af), - Expression::AsyncGenerator(ag) => visitor.visit_async_generator_mut(ag), - Expression::Class(c) => visitor.visit_class_mut(c), - Expression::TemplateLiteral(tlit) => visitor.visit_template_literal_mut(tlit), - Expression::PropertyAccess(pa) => visitor.visit_property_access_mut(pa), - Expression::New(n) => visitor.visit_new_mut(n), - Expression::Call(c) => visitor.visit_call_mut(c), - Expression::SuperCall(sc) => visitor.visit_super_call_mut(sc), - Expression::Optional(opt) => visitor.visit_optional_mut(opt), - Expression::TaggedTemplate(tt) => visitor.visit_tagged_template_mut(tt), - Expression::Assign(a) => visitor.visit_assign_mut(a), - Expression::Unary(u) => visitor.visit_unary_mut(u), - Expression::Binary(b) => visitor.visit_binary_mut(b), - Expression::Conditional(c) => visitor.visit_conditional_mut(c), - Expression::Await(a) => visitor.visit_await_mut(a), - Expression::Yield(y) => visitor.visit_yield_mut(y), - Expression::FormalParameterList(fpl) => visitor.visit_formal_parameter_list_mut(fpl), - Expression::This | Expression::NewTarget => { + Self::Identifier(id) => visitor.visit_identifier_mut(id), + Self::Literal(lit) => visitor.visit_literal_mut(lit), + Self::ArrayLiteral(arlit) => visitor.visit_array_literal_mut(arlit), + Self::ObjectLiteral(olit) => visitor.visit_object_literal_mut(olit), + Self::Spread(sp) => visitor.visit_spread_mut(sp), + Self::Function(f) => visitor.visit_function_mut(f), + Self::ArrowFunction(af) => visitor.visit_arrow_function_mut(af), + Self::AsyncArrowFunction(af) => visitor.visit_async_arrow_function_mut(af), + Self::Generator(g) => visitor.visit_generator_mut(g), + Self::AsyncFunction(af) => visitor.visit_async_function_mut(af), + Self::AsyncGenerator(ag) => visitor.visit_async_generator_mut(ag), + Self::Class(c) => visitor.visit_class_mut(c), + Self::TemplateLiteral(tlit) => visitor.visit_template_literal_mut(tlit), + Self::PropertyAccess(pa) => visitor.visit_property_access_mut(pa), + Self::New(n) => visitor.visit_new_mut(n), + Self::Call(c) => visitor.visit_call_mut(c), + Self::SuperCall(sc) => visitor.visit_super_call_mut(sc), + Self::Optional(opt) => visitor.visit_optional_mut(opt), + Self::TaggedTemplate(tt) => visitor.visit_tagged_template_mut(tt), + Self::Assign(a) => visitor.visit_assign_mut(a), + Self::Unary(u) => visitor.visit_unary_mut(u), + Self::Binary(b) => visitor.visit_binary_mut(b), + Self::Conditional(c) => visitor.visit_conditional_mut(c), + Self::Await(a) => visitor.visit_await_mut(a), + Self::Yield(y) => visitor.visit_yield_mut(y), + Self::FormalParameterList(fpl) => visitor.visit_formal_parameter_list_mut(fpl), + Self::This | Self::NewTarget => { // do nothing; can be handled as special case by visitor ControlFlow::Continue(()) } diff --git a/boa_ast/src/expression/new.rs b/boa_ast/src/expression/new.rs index f93e7a9bea2..4b77e8323e6 100644 --- a/boa_ast/src/expression/new.rs +++ b/boa_ast/src/expression/new.rs @@ -31,20 +31,20 @@ impl New { /// Gets the constructor of the new expression. #[inline] #[must_use] - pub fn constructor(&self) -> &Expression { + pub const fn constructor(&self) -> &Expression { self.call.function() } /// Retrieves the arguments passed to the constructor. #[inline] #[must_use] - pub fn arguments(&self) -> &[Expression] { + pub const fn arguments(&self) -> &[Expression] { self.call.args() } /// Returns the inner call expression. #[must_use] - pub fn call(&self) -> &Call { + pub const fn call(&self) -> &Call { &self.call } } diff --git a/boa_ast/src/expression/operator/assign/mod.rs b/boa_ast/src/expression/operator/assign/mod.rs index a2bbc692461..588c844946f 100644 --- a/boa_ast/src/expression/operator/assign/mod.rs +++ b/boa_ast/src/expression/operator/assign/mod.rs @@ -50,21 +50,21 @@ impl Assign { /// Gets the operator of the assignment operation. #[inline] #[must_use] - pub fn op(&self) -> AssignOp { + pub const fn op(&self) -> AssignOp { self.op } /// Gets the left hand side of the assignment operation. #[inline] #[must_use] - pub fn lhs(&self) -> &AssignTarget { + pub const fn lhs(&self) -> &AssignTarget { &self.lhs } /// Gets the right hand side of the assignment operation. #[inline] #[must_use] - pub fn rhs(&self) -> &Expression { + pub const fn rhs(&self) -> &Expression { &self.rhs } } @@ -151,9 +151,9 @@ impl ToInternedString for AssignTarget { #[inline] fn to_interned_string(&self, interner: &Interner) -> String { match self { - AssignTarget::Identifier(id) => id.to_interned_string(interner), - AssignTarget::Access(access) => access.to_interned_string(interner), - AssignTarget::Pattern(pattern) => pattern.to_interned_string(interner), + Self::Identifier(id) => id.to_interned_string(interner), + Self::Access(access) => access.to_interned_string(interner), + Self::Pattern(pattern) => pattern.to_interned_string(interner), } } } @@ -171,9 +171,9 @@ impl VisitWith for AssignTarget { V: Visitor<'a>, { match self { - AssignTarget::Identifier(id) => visitor.visit_identifier(id), - AssignTarget::Access(pa) => visitor.visit_property_access(pa), - AssignTarget::Pattern(pat) => visitor.visit_pattern(pat), + Self::Identifier(id) => visitor.visit_identifier(id), + Self::Access(pa) => visitor.visit_property_access(pa), + Self::Pattern(pat) => visitor.visit_pattern(pat), } } @@ -182,9 +182,9 @@ impl VisitWith for AssignTarget { V: VisitorMut<'a>, { match self { - AssignTarget::Identifier(id) => visitor.visit_identifier_mut(id), - AssignTarget::Access(pa) => visitor.visit_property_access_mut(pa), - AssignTarget::Pattern(pat) => visitor.visit_pattern_mut(pat), + Self::Identifier(id) => visitor.visit_identifier_mut(id), + Self::Access(pa) => visitor.visit_property_access_mut(pa), + Self::Pattern(pat) => visitor.visit_pattern_mut(pat), } } } diff --git a/boa_ast/src/expression/operator/assign/op.rs b/boa_ast/src/expression/operator/assign/op.rs index a2c25df8cf5..e574b1e9137 100644 --- a/boa_ast/src/expression/operator/assign/op.rs +++ b/boa_ast/src/expression/operator/assign/op.rs @@ -214,7 +214,7 @@ pub enum AssignOp { impl AssignOp { /// Retrieves the operation as a static string. - fn as_str(self) -> &'static str { + const fn as_str(self) -> &'static str { match self { Self::Assign => "=", Self::Add => "+=", diff --git a/boa_ast/src/expression/operator/binary/mod.rs b/boa_ast/src/expression/operator/binary/mod.rs index 2e280392641..c39466056fb 100644 --- a/boa_ast/src/expression/operator/binary/mod.rs +++ b/boa_ast/src/expression/operator/binary/mod.rs @@ -53,21 +53,21 @@ impl Binary { /// Gets the binary operation of the Expression. #[inline] #[must_use] - pub fn op(&self) -> BinaryOp { + pub const fn op(&self) -> BinaryOp { self.op } /// Gets the left hand side of the binary operation. #[inline] #[must_use] - pub fn lhs(&self) -> &Expression { + pub const fn lhs(&self) -> &Expression { &self.lhs } /// Gets the right hand side of the binary operation. #[inline] #[must_use] - pub fn rhs(&self) -> &Expression { + pub const fn rhs(&self) -> &Expression { &self.rhs } } diff --git a/boa_ast/src/expression/operator/binary/op.rs b/boa_ast/src/expression/operator/binary/op.rs index 60ace261298..9bba78e85b1 100644 --- a/boa_ast/src/expression/operator/binary/op.rs +++ b/boa_ast/src/expression/operator/binary/op.rs @@ -61,7 +61,7 @@ impl From for BinaryOp { impl BinaryOp { /// Retrieves the operation as a static string. - fn as_str(self) -> &'static str { + const fn as_str(self) -> &'static str { match self { Self::Arithmetic(ref op) => op.as_str(), Self::Bitwise(ref op) => op.as_str(), @@ -171,7 +171,7 @@ pub enum ArithmeticOp { impl ArithmeticOp { /// Retrieves the operation as a static string. - fn as_str(self) -> &'static str { + const fn as_str(self) -> &'static str { match self { Self::Add => "+", Self::Sub => "-", @@ -287,7 +287,7 @@ pub enum BitwiseOp { impl BitwiseOp { /// Retrieves the operation as a static string. - fn as_str(self) -> &'static str { + const fn as_str(self) -> &'static str { match self { Self::And => "&", Self::Or => "|", @@ -481,7 +481,7 @@ pub enum RelationalOp { impl RelationalOp { /// Retrieves the operation as a static string. - fn as_str(self) -> &'static str { + const fn as_str(self) -> &'static str { match self { Self::Equal => "==", Self::NotEqual => "!=", @@ -561,7 +561,7 @@ pub enum LogicalOp { impl LogicalOp { /// Retrieves the operation as a static string. - fn as_str(self) -> &'static str { + const fn as_str(self) -> &'static str { match self { Self::And => "&&", Self::Or => "||", diff --git a/boa_ast/src/expression/operator/conditional.rs b/boa_ast/src/expression/operator/conditional.rs index a0ac5711d61..f18b8d8f6a1 100644 --- a/boa_ast/src/expression/operator/conditional.rs +++ b/boa_ast/src/expression/operator/conditional.rs @@ -33,21 +33,21 @@ impl Conditional { /// Gets the condition of the `Conditional` expression. #[inline] #[must_use] - pub fn condition(&self) -> &Expression { + pub const fn condition(&self) -> &Expression { &self.condition } /// Gets the expression returned if `condition` is truthy. #[inline] #[must_use] - pub fn if_true(&self) -> &Expression { + pub const fn if_true(&self) -> &Expression { &self.if_true } /// Gets the expression returned if `condition` is falsy. #[inline] #[must_use] - pub fn if_false(&self) -> &Expression { + pub const fn if_false(&self) -> &Expression { &self.if_false } diff --git a/boa_ast/src/expression/operator/unary/mod.rs b/boa_ast/src/expression/operator/unary/mod.rs index ecf77b0f9c6..9c133e86e76 100644 --- a/boa_ast/src/expression/operator/unary/mod.rs +++ b/boa_ast/src/expression/operator/unary/mod.rs @@ -50,7 +50,7 @@ impl Unary { /// Gets the unary operation of the Expression. #[inline] #[must_use] - pub fn op(&self) -> UnaryOp { + pub const fn op(&self) -> UnaryOp { self.op } diff --git a/boa_ast/src/expression/operator/unary/op.rs b/boa_ast/src/expression/operator/unary/op.rs index ce3c7f607c9..f4e2461efd2 100644 --- a/boa_ast/src/expression/operator/unary/op.rs +++ b/boa_ast/src/expression/operator/unary/op.rs @@ -193,7 +193,7 @@ pub enum UnaryOp { impl UnaryOp { /// Retrieves the operation as a static string. - fn as_str(self) -> &'static str { + const fn as_str(self) -> &'static str { match self { Self::IncrementPost | Self::IncrementPre => "++", Self::DecrementPost | Self::DecrementPre => "--", diff --git a/boa_ast/src/expression/optional.rs b/boa_ast/src/expression/optional.rs index 7d7ff48cdd6..b7d16b3ea91 100644 --- a/boa_ast/src/expression/optional.rs +++ b/boa_ast/src/expression/optional.rs @@ -35,11 +35,9 @@ impl VisitWith for OptionalOperationKind { V: Visitor<'a>, { match self { - OptionalOperationKind::SimplePropertyAccess { field } => { - visitor.visit_property_access_field(field) - } - OptionalOperationKind::PrivatePropertyAccess { field } => visitor.visit_sym(field), - OptionalOperationKind::Call { args } => { + Self::SimplePropertyAccess { field } => visitor.visit_property_access_field(field), + Self::PrivatePropertyAccess { field } => visitor.visit_sym(field), + Self::Call { args } => { for arg in args.iter() { try_break!(visitor.visit_expression(arg)); } @@ -53,11 +51,9 @@ impl VisitWith for OptionalOperationKind { V: VisitorMut<'a>, { match self { - OptionalOperationKind::SimplePropertyAccess { field } => { - visitor.visit_property_access_field_mut(field) - } - OptionalOperationKind::PrivatePropertyAccess { field } => visitor.visit_sym_mut(field), - OptionalOperationKind::Call { args } => { + Self::SimplePropertyAccess { field } => visitor.visit_property_access_field_mut(field), + Self::PrivatePropertyAccess { field } => visitor.visit_sym_mut(field), + Self::Call { args } => { for arg in args.iter_mut() { try_break!(visitor.visit_expression_mut(arg)); } @@ -85,13 +81,13 @@ impl OptionalOperation { /// Creates a new `OptionalOperation`. #[inline] #[must_use] - pub fn new(kind: OptionalOperationKind, shorted: bool) -> Self { + pub const fn new(kind: OptionalOperationKind, shorted: bool) -> Self { Self { kind, shorted } } /// Gets the kind of operation. #[inline] #[must_use] - pub fn kind(&self) -> &OptionalOperationKind { + pub const fn kind(&self) -> &OptionalOperationKind { &self.kind } @@ -99,7 +95,7 @@ impl OptionalOperation { /// `undefined` or `null`. #[inline] #[must_use] - pub fn shorted(&self) -> bool { + pub const fn shorted(&self) -> bool { self.shorted } } @@ -236,7 +232,7 @@ impl Optional { impl From for Expression { fn from(opt: Optional) -> Self { - Expression::Optional(opt) + Self::Optional(opt) } } diff --git a/boa_ast/src/expression/spread.rs b/boa_ast/src/expression/spread.rs index fc86dde42ad..95d4ed4b17e 100644 --- a/boa_ast/src/expression/spread.rs +++ b/boa_ast/src/expression/spread.rs @@ -33,7 +33,7 @@ impl Spread { /// Gets the target expression to be expanded by the spread operator. #[inline] #[must_use] - pub fn target(&self) -> &Expression { + pub const fn target(&self) -> &Expression { &self.target } diff --git a/boa_ast/src/expression/tagged_template.rs b/boa_ast/src/expression/tagged_template.rs index 2a01bbbf200..68d79f61ac1 100644 --- a/boa_ast/src/expression/tagged_template.rs +++ b/boa_ast/src/expression/tagged_template.rs @@ -45,28 +45,28 @@ impl TaggedTemplate { /// Gets the tag function of the template. #[inline] #[must_use] - pub fn tag(&self) -> &Expression { + pub const fn tag(&self) -> &Expression { &self.tag } /// Gets the inner raw strings of the template. #[inline] #[must_use] - pub fn raws(&self) -> &[Sym] { + pub const fn raws(&self) -> &[Sym] { &self.raws } /// Gets the cooked strings of the template. #[inline] #[must_use] - pub fn cookeds(&self) -> &[Option] { + pub const fn cookeds(&self) -> &[Option] { &self.cookeds } /// Gets the interpolated expressions of the template. #[inline] #[must_use] - pub fn exprs(&self) -> &[Expression] { + pub const fn exprs(&self) -> &[Expression] { &self.exprs } } diff --git a/boa_ast/src/expression/yield.rs b/boa_ast/src/expression/yield.rs index 7357e00c64d..91c2cd01b4a 100644 --- a/boa_ast/src/expression/yield.rs +++ b/boa_ast/src/expression/yield.rs @@ -31,7 +31,7 @@ impl Yield { /// Returns `true` if this `Yield` statement delegates to another generator or iterable object. #[inline] #[must_use] - pub fn delegate(&self) -> bool { + pub const fn delegate(&self) -> bool { self.delegate } diff --git a/boa_ast/src/function/arrow_function.rs b/boa_ast/src/function/arrow_function.rs index c02c3a8e2a3..0c5a5b5b85d 100644 --- a/boa_ast/src/function/arrow_function.rs +++ b/boa_ast/src/function/arrow_function.rs @@ -31,7 +31,11 @@ impl ArrowFunction { /// Creates a new `ArrowFunctionDecl` AST Expression. #[inline] #[must_use] - pub fn new(name: Option, params: FormalParameterList, body: StatementList) -> Self { + pub const fn new( + name: Option, + params: FormalParameterList, + body: StatementList, + ) -> Self { Self { name, parameters: params, @@ -42,7 +46,7 @@ impl ArrowFunction { /// Gets the name of the function declaration. #[inline] #[must_use] - pub fn name(&self) -> Option { + pub const fn name(&self) -> Option { self.name } @@ -55,14 +59,14 @@ impl ArrowFunction { /// Gets the list of parameters of the arrow function. #[inline] #[must_use] - pub fn parameters(&self) -> &FormalParameterList { + pub const fn parameters(&self) -> &FormalParameterList { &self.parameters } /// Gets the body of the arrow function. #[inline] #[must_use] - pub fn body(&self) -> &StatementList { + pub const fn body(&self) -> &StatementList { &self.body } } diff --git a/boa_ast/src/function/async_arrow_function.rs b/boa_ast/src/function/async_arrow_function.rs index 191de2f5422..378dbfe8c07 100644 --- a/boa_ast/src/function/async_arrow_function.rs +++ b/boa_ast/src/function/async_arrow_function.rs @@ -31,7 +31,7 @@ impl AsyncArrowFunction { /// Creates a new `AsyncArrowFunction` AST Expression. #[inline] #[must_use] - pub fn new( + pub const fn new( name: Option, parameters: FormalParameterList, body: StatementList, @@ -46,7 +46,7 @@ impl AsyncArrowFunction { /// Gets the name of the function declaration. #[inline] #[must_use] - pub fn name(&self) -> Option { + pub const fn name(&self) -> Option { self.name } @@ -60,14 +60,14 @@ impl AsyncArrowFunction { /// Gets the list of parameters of the arrow function. #[inline] #[must_use] - pub fn parameters(&self) -> &FormalParameterList { + pub const fn parameters(&self) -> &FormalParameterList { &self.parameters } /// Gets the body of the arrow function. #[inline] #[must_use] - pub fn body(&self) -> &StatementList { + pub const fn body(&self) -> &StatementList { &self.body } } diff --git a/boa_ast/src/function/async_function.rs b/boa_ast/src/function/async_function.rs index 17df80504f8..74100ee8739 100644 --- a/boa_ast/src/function/async_function.rs +++ b/boa_ast/src/function/async_function.rs @@ -33,7 +33,7 @@ impl AsyncFunction { /// Creates a new function expression #[inline] #[must_use] - pub fn new( + pub const fn new( name: Option, parameters: FormalParameterList, body: StatementList, @@ -50,28 +50,28 @@ impl AsyncFunction { /// Gets the name of the function declaration. #[inline] #[must_use] - pub fn name(&self) -> Option { + pub const fn name(&self) -> Option { self.name } /// Gets the list of parameters of the function declaration. #[inline] #[must_use] - pub fn parameters(&self) -> &FormalParameterList { + pub const fn parameters(&self) -> &FormalParameterList { &self.parameters } /// Gets the body of the function declaration. #[inline] #[must_use] - pub fn body(&self) -> &StatementList { + pub const fn body(&self) -> &StatementList { &self.body } /// Returns whether the function expression has a binding identifier. #[inline] #[must_use] - pub fn has_binding_identifier(&self) -> bool { + pub const fn has_binding_identifier(&self) -> bool { self.has_binding_identifier } } diff --git a/boa_ast/src/function/async_generator.rs b/boa_ast/src/function/async_generator.rs index 420a8bbd23f..f98309237af 100644 --- a/boa_ast/src/function/async_generator.rs +++ b/boa_ast/src/function/async_generator.rs @@ -32,7 +32,7 @@ impl AsyncGenerator { /// Creates a new async generator expression #[inline] #[must_use] - pub fn new( + pub const fn new( name: Option, parameters: FormalParameterList, body: StatementList, @@ -49,28 +49,28 @@ impl AsyncGenerator { /// Gets the name of the async generator expression #[inline] #[must_use] - pub fn name(&self) -> Option { + pub const fn name(&self) -> Option { self.name } /// Gets the list of parameters of the async generator expression #[inline] #[must_use] - pub fn parameters(&self) -> &FormalParameterList { + pub const fn parameters(&self) -> &FormalParameterList { &self.parameters } /// Gets the body of the async generator expression #[inline] #[must_use] - pub fn body(&self) -> &StatementList { + pub const fn body(&self) -> &StatementList { &self.body } /// Returns whether the function expression has a binding identifier. #[inline] #[must_use] - pub fn has_binding_identifier(&self) -> bool { + pub const fn has_binding_identifier(&self) -> bool { self.has_binding_identifier } } diff --git a/boa_ast/src/function/class.rs b/boa_ast/src/function/class.rs index dea5811eedf..1106371932d 100644 --- a/boa_ast/src/function/class.rs +++ b/boa_ast/src/function/class.rs @@ -52,28 +52,28 @@ impl Class { /// Returns the name of the class. #[inline] #[must_use] - pub fn name(&self) -> Option { + pub const fn name(&self) -> Option { self.name } /// Returns the super class ref of the class. #[inline] #[must_use] - pub fn super_ref(&self) -> Option<&Expression> { + pub const fn super_ref(&self) -> Option<&Expression> { self.super_ref.as_ref() } /// Returns the constructor of the class. #[inline] #[must_use] - pub fn constructor(&self) -> Option<&Function> { + pub const fn constructor(&self) -> Option<&Function> { self.constructor.as_ref() } /// Gets the list of all fields defined on the class. #[inline] #[must_use] - pub fn elements(&self) -> &[ClassElement] { + pub const fn elements(&self) -> &[ClassElement] { &self.elements } } @@ -90,21 +90,23 @@ impl ToIndentedString for Class { if self.elements.is_empty() && self.constructor().is_none() { return format!( "class {class_name}{} {{}}", - if let Some(sup) = &self.super_ref { - format!(" extends {}", sup.to_interned_string(interner)) - } else { - String::new() - } + self.super_ref + .as_ref() + .map_or_else(String::new, |sup| format!( + " extends {}", + sup.to_interned_string(interner) + )) ); } let indentation = " ".repeat(indent_n + 1); let mut buf = format!( "class {class_name}{} {{\n", - if let Some(sup) = &self.super_ref { - format!("extends {}", sup.to_interned_string(interner)) - } else { - String::new() - } + self.super_ref + .as_ref() + .map_or_else(String::new, |sup| format!( + "extends {}", + sup.to_interned_string(interner) + )) ); if let Some(expr) = &self.constructor { buf.push_str(&format!( @@ -438,13 +440,11 @@ impl VisitWith for ClassElement { V: Visitor<'a>, { match self { - ClassElement::MethodDefinition(pn, md) - | ClassElement::StaticMethodDefinition(pn, md) => { + Self::MethodDefinition(pn, md) | Self::StaticMethodDefinition(pn, md) => { try_break!(visitor.visit_property_name(pn)); visitor.visit_method_definition(md) } - ClassElement::FieldDefinition(pn, maybe_expr) - | ClassElement::StaticFieldDefinition(pn, maybe_expr) => { + Self::FieldDefinition(pn, maybe_expr) | Self::StaticFieldDefinition(pn, maybe_expr) => { try_break!(visitor.visit_property_name(pn)); if let Some(expr) = maybe_expr { visitor.visit_expression(expr) @@ -452,13 +452,13 @@ impl VisitWith for ClassElement { ControlFlow::Continue(()) } } - ClassElement::PrivateMethodDefinition(sym, md) - | ClassElement::PrivateStaticMethodDefinition(sym, md) => { + Self::PrivateMethodDefinition(sym, md) + | Self::PrivateStaticMethodDefinition(sym, md) => { try_break!(visitor.visit_sym(sym)); visitor.visit_method_definition(md) } - ClassElement::PrivateFieldDefinition(sym, maybe_expr) - | ClassElement::PrivateStaticFieldDefinition(sym, maybe_expr) => { + Self::PrivateFieldDefinition(sym, maybe_expr) + | Self::PrivateStaticFieldDefinition(sym, maybe_expr) => { try_break!(visitor.visit_sym(sym)); if let Some(expr) = maybe_expr { visitor.visit_expression(expr) @@ -466,7 +466,7 @@ impl VisitWith for ClassElement { ControlFlow::Continue(()) } } - ClassElement::StaticBlock(sl) => visitor.visit_statement_list(sl), + Self::StaticBlock(sl) => visitor.visit_statement_list(sl), } } @@ -475,13 +475,11 @@ impl VisitWith for ClassElement { V: VisitorMut<'a>, { match self { - ClassElement::MethodDefinition(pn, md) - | ClassElement::StaticMethodDefinition(pn, md) => { + Self::MethodDefinition(pn, md) | Self::StaticMethodDefinition(pn, md) => { try_break!(visitor.visit_property_name_mut(pn)); visitor.visit_method_definition_mut(md) } - ClassElement::FieldDefinition(pn, maybe_expr) - | ClassElement::StaticFieldDefinition(pn, maybe_expr) => { + Self::FieldDefinition(pn, maybe_expr) | Self::StaticFieldDefinition(pn, maybe_expr) => { try_break!(visitor.visit_property_name_mut(pn)); if let Some(expr) = maybe_expr { visitor.visit_expression_mut(expr) @@ -489,13 +487,13 @@ impl VisitWith for ClassElement { ControlFlow::Continue(()) } } - ClassElement::PrivateMethodDefinition(sym, md) - | ClassElement::PrivateStaticMethodDefinition(sym, md) => { + Self::PrivateMethodDefinition(sym, md) + | Self::PrivateStaticMethodDefinition(sym, md) => { try_break!(visitor.visit_sym_mut(sym)); visitor.visit_method_definition_mut(md) } - ClassElement::PrivateFieldDefinition(sym, maybe_expr) - | ClassElement::PrivateStaticFieldDefinition(sym, maybe_expr) => { + Self::PrivateFieldDefinition(sym, maybe_expr) + | Self::PrivateStaticFieldDefinition(sym, maybe_expr) => { try_break!(visitor.visit_sym_mut(sym)); if let Some(expr) = maybe_expr { visitor.visit_expression_mut(expr) @@ -503,7 +501,7 @@ impl VisitWith for ClassElement { ControlFlow::Continue(()) } } - ClassElement::StaticBlock(sl) => visitor.visit_statement_list_mut(sl), + Self::StaticBlock(sl) => visitor.visit_statement_list_mut(sl), } } } diff --git a/boa_ast/src/function/generator.rs b/boa_ast/src/function/generator.rs index 5478633d46e..9f18623c38b 100644 --- a/boa_ast/src/function/generator.rs +++ b/boa_ast/src/function/generator.rs @@ -34,7 +34,7 @@ impl Generator { /// Creates a new generator expression #[inline] #[must_use] - pub fn new( + pub const fn new( name: Option, parameters: FormalParameterList, body: StatementList, @@ -51,28 +51,28 @@ impl Generator { /// Gets the name of the generator declaration. #[inline] #[must_use] - pub fn name(&self) -> Option { + pub const fn name(&self) -> Option { self.name } /// Gets the list of parameters of the generator declaration. #[inline] #[must_use] - pub fn parameters(&self) -> &FormalParameterList { + pub const fn parameters(&self) -> &FormalParameterList { &self.parameters } /// Gets the body of the generator declaration. #[inline] #[must_use] - pub fn body(&self) -> &StatementList { + pub const fn body(&self) -> &StatementList { &self.body } /// Returns whether the function expression has a binding identifier. #[inline] #[must_use] - pub fn has_binding_identifier(&self) -> bool { + pub const fn has_binding_identifier(&self) -> bool { self.has_binding_identifier } } diff --git a/boa_ast/src/function/mod.rs b/boa_ast/src/function/mod.rs index 4aa1d06c395..c043f07b248 100644 --- a/boa_ast/src/function/mod.rs +++ b/boa_ast/src/function/mod.rs @@ -70,7 +70,7 @@ impl Function { /// Creates a new function expression. #[inline] #[must_use] - pub fn new( + pub const fn new( name: Option, parameters: FormalParameterList, body: StatementList, @@ -86,7 +86,7 @@ impl Function { /// Creates a new function expression with an expression binding identifier. #[inline] #[must_use] - pub fn new_with_binding_identifier( + pub const fn new_with_binding_identifier( name: Option, parameters: FormalParameterList, body: StatementList, @@ -103,28 +103,28 @@ impl Function { /// Gets the name of the function declaration. #[inline] #[must_use] - pub fn name(&self) -> Option { + pub const fn name(&self) -> Option { self.name } /// Gets the list of parameters of the function declaration. #[inline] #[must_use] - pub fn parameters(&self) -> &FormalParameterList { + pub const fn parameters(&self) -> &FormalParameterList { &self.parameters } /// Gets the body of the function declaration. #[inline] #[must_use] - pub fn body(&self) -> &StatementList { + pub const fn body(&self) -> &StatementList { &self.body } /// Returns whether the function expression has a binding identifier. #[inline] #[must_use] - pub fn has_binding_identifier(&self) -> bool { + pub const fn has_binding_identifier(&self) -> bool { self.has_binding_identifier } } diff --git a/boa_ast/src/function/parameters.rs b/boa_ast/src/function/parameters.rs index 9d80ebd86b7..eba5b034fe9 100644 --- a/boa_ast/src/function/parameters.rs +++ b/boa_ast/src/function/parameters.rs @@ -81,46 +81,46 @@ impl FormalParameterList { /// Returns the length of the parameter list. /// Note that this is not equal to the length of the parameters slice. #[must_use] - pub fn length(&self) -> u32 { + pub const fn length(&self) -> u32 { self.length } /// Returns the parameter list flags. #[must_use] - pub fn flags(&self) -> FormalParameterListFlags { + pub const fn flags(&self) -> FormalParameterListFlags { self.flags } /// Indicates if the parameter list is simple. #[must_use] - pub fn is_simple(&self) -> bool { + pub const fn is_simple(&self) -> bool { self.flags.contains(FormalParameterListFlags::IS_SIMPLE) } /// Indicates if the parameter list has duplicate parameters. #[must_use] - pub fn has_duplicates(&self) -> bool { + pub const fn has_duplicates(&self) -> bool { self.flags .contains(FormalParameterListFlags::HAS_DUPLICATES) } /// Indicates if the parameter list has a rest parameter. #[must_use] - pub fn has_rest_parameter(&self) -> bool { + pub const fn has_rest_parameter(&self) -> bool { self.flags .contains(FormalParameterListFlags::HAS_REST_PARAMETER) } /// Indicates if the parameter list has expressions in it's parameters. #[must_use] - pub fn has_expressions(&self) -> bool { + pub const fn has_expressions(&self) -> bool { self.flags .contains(FormalParameterListFlags::HAS_EXPRESSIONS) } /// Indicates if the parameter list has parameters named 'arguments'. #[must_use] - pub fn has_arguments(&self) -> bool { + pub const fn has_arguments(&self) -> bool { self.flags.contains(FormalParameterListFlags::HAS_ARGUMENTS) } } @@ -235,25 +235,25 @@ impl FormalParameter { /// Gets the variable of the formal parameter #[must_use] - pub fn variable(&self) -> &Variable { + pub const fn variable(&self) -> &Variable { &self.variable } /// Gets the initialization node of the formal parameter, if any. #[must_use] - pub fn init(&self) -> Option<&Expression> { + pub const fn init(&self) -> Option<&Expression> { self.variable.init() } /// Returns `true` if the parameter is a rest parameter. #[must_use] - pub fn is_rest_param(&self) -> bool { + pub const fn is_rest_param(&self) -> bool { self.is_rest_param } /// Returns `true` if the parameter is an identifier. #[must_use] - pub fn is_identifier(&self) -> bool { + pub const fn is_identifier(&self) -> bool { matches!(&self.variable.binding(), Binding::Identifier(_)) } } diff --git a/boa_ast/src/keyword.rs b/boa_ast/src/keyword.rs index a59527929b6..a90ac7f73be 100644 --- a/boa_ast/src/keyword.rs +++ b/boa_ast/src/keyword.rs @@ -478,7 +478,7 @@ impl Keyword { /// Gets the keyword as a binary operation, if this keyword is the `in` or the `instanceof` /// keywords. #[must_use] - pub fn as_binary_op(self) -> Option { + pub const fn as_binary_op(self) -> Option { match self { Self::In => Some(BinaryOp::Relational(RelationalOp::In)), Self::InstanceOf => Some(BinaryOp::Relational(RelationalOp::InstanceOf)), @@ -488,7 +488,7 @@ impl Keyword { /// Gets the keyword as a tuple of strings. #[must_use] - pub fn as_str(self) -> (&'static str, &'static [u16]) { + pub const fn as_str(self) -> (&'static str, &'static [u16]) { match self { Self::Await => ("await", utf16!("await")), Self::Async => ("async", utf16!("async")), diff --git a/boa_ast/src/lib.rs b/boa_ast/src/lib.rs index c9781d2b546..f4ec5360375 100644 --- a/boa_ast/src/lib.rs +++ b/boa_ast/src/lib.rs @@ -12,44 +12,64 @@ //! [early]: https://tc39.es/ecma262/#sec-static-semantic-rules #![cfg_attr(not(test), forbid(clippy::unwrap_used))] -#![warn( - clippy::perf, - clippy::single_match_else, - clippy::dbg_macro, - clippy::doc_markdown, - clippy::wildcard_imports, - clippy::struct_excessive_bools, - clippy::doc_markdown, - clippy::semicolon_if_nothing_returned, - clippy::pedantic -)] +#![warn(clippy::dbg_macro)] #![deny( - clippy::all, - clippy::cast_lossless, - clippy::redundant_closure_for_method_calls, - clippy::unnested_or_patterns, - clippy::trivially_copy_pass_by_ref, - clippy::needless_pass_by_value, - clippy::match_wildcard_for_single_variants, - clippy::map_unwrap_or, - unused_qualifications, + // rustc lint groups https://doc.rust-lang.org/rustc/lints/groups.html + warnings, + future_incompatible, + let_underscore, + nonstandard_style, + rust_2018_compatibility, + rust_2018_idioms, + rust_2021_compatibility, + unused, + + // rustc allowed-by-default lints https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html + macro_use_extern_crate, + meta_variable_misuse, + missing_abi, + missing_copy_implementations, + missing_debug_implementations, + missing_docs, + non_ascii_idents, + noop_method_call, + single_use_lifetimes, + trivial_casts, + trivial_numeric_casts, + unreachable_pub, + unsafe_op_in_unsafe_fn, + unused_crate_dependencies, unused_import_braces, unused_lifetimes, - unreachable_pub, - trivial_numeric_casts, + unused_qualifications, + unused_tuple_struct_fields, + variant_size_differences, + + // rustdoc lints https://doc.rust-lang.org/rustdoc/lints.html rustdoc::broken_intra_doc_links, - missing_debug_implementations, - missing_copy_implementations, - deprecated_in_future, - meta_variable_misuse, - non_ascii_idents, - rust_2018_compatibility, - rust_2018_idioms, - future_incompatible, - nonstandard_style, - missing_docs + rustdoc::private_intra_doc_links, + rustdoc::missing_crate_level_docs, + rustdoc::private_doc_tests, + rustdoc::invalid_codeblock_attributes, + rustdoc::invalid_rust_codeblocks, + rustdoc::bare_urls, + + // clippy categories https://doc.rust-lang.org/clippy/ + clippy::all, + clippy::correctness, + clippy::suspicious, + clippy::style, + clippy::complexity, + clippy::perf, + clippy::pedantic, + clippy::nursery, +)] +#![allow( + clippy::module_name_repetitions, + clippy::too_many_lines, + clippy::option_if_let_else, + clippy::use_self )] -#![allow(clippy::module_name_repetitions, clippy::too_many_lines)] mod position; mod punctuator; diff --git a/boa_ast/src/pattern.rs b/boa_ast/src/pattern.rs index bd9b8694306..a8b1644b33c 100644 --- a/boa_ast/src/pattern.rs +++ b/boa_ast/src/pattern.rs @@ -47,13 +47,13 @@ pub enum Pattern { impl From for Pattern { fn from(obj: ObjectPattern) -> Self { - Pattern::Object(obj) + Self::Object(obj) } } impl From for Pattern { fn from(obj: ArrayPattern) -> Self { - Pattern::Array(obj) + Self::Array(obj) } } @@ -71,8 +71,8 @@ impl From> for Pattern { impl ToInternedString for Pattern { fn to_interned_string(&self, interner: &Interner) -> String { match &self { - Pattern::Object(o) => o.to_interned_string(interner), - Pattern::Array(a) => a.to_interned_string(interner), + Self::Object(o) => o.to_interned_string(interner), + Self::Array(a) => a.to_interned_string(interner), } } } @@ -83,8 +83,8 @@ impl VisitWith for Pattern { V: Visitor<'a>, { match self { - Pattern::Object(op) => visitor.visit_object_pattern(op), - Pattern::Array(ap) => visitor.visit_array_pattern(ap), + Self::Object(op) => visitor.visit_object_pattern(op), + Self::Array(ap) => visitor.visit_array_pattern(ap), } } @@ -93,8 +93,8 @@ impl VisitWith for Pattern { V: VisitorMut<'a>, { match self { - Pattern::Object(op) => visitor.visit_object_pattern_mut(op), - Pattern::Array(ap) => visitor.visit_array_pattern_mut(ap), + Self::Object(op) => visitor.visit_object_pattern_mut(op), + Self::Array(ap) => visitor.visit_array_pattern_mut(ap), } } } @@ -151,14 +151,14 @@ impl ObjectPattern { /// Gets the bindings for the object binding pattern. #[inline] #[must_use] - pub fn bindings(&self) -> &[ObjectPatternElement] { + pub const fn bindings(&self) -> &[ObjectPatternElement] { &self.0 } /// Returns true if the object binding pattern has a rest element. #[inline] #[must_use] - pub fn has_rest(&self) -> bool { + pub const fn has_rest(&self) -> bool { matches!( self.0.last(), Some(ObjectPatternElement::RestProperty { .. }) @@ -239,7 +239,7 @@ impl ArrayPattern { /// Gets the bindings for the array binding pattern. #[inline] #[must_use] - pub fn bindings(&self) -> &[ArrayPatternElement] { + pub const fn bindings(&self) -> &[ArrayPatternElement] { &self.0 } } @@ -468,7 +468,7 @@ impl VisitWith for ObjectPatternElement { V: Visitor<'a>, { match self { - ObjectPatternElement::SingleName { + Self::SingleName { name, ident, default_init, @@ -481,8 +481,8 @@ impl VisitWith for ObjectPatternElement { ControlFlow::Continue(()) } } - ObjectPatternElement::RestProperty { ident, .. } => visitor.visit_identifier(ident), - ObjectPatternElement::AssignmentPropertyAccess { + Self::RestProperty { ident, .. } => visitor.visit_identifier(ident), + Self::AssignmentPropertyAccess { name, access, default_init, @@ -495,10 +495,10 @@ impl VisitWith for ObjectPatternElement { ControlFlow::Continue(()) } } - ObjectPatternElement::AssignmentRestPropertyAccess { access, .. } => { + Self::AssignmentRestPropertyAccess { access, .. } => { visitor.visit_property_access(access) } - ObjectPatternElement::Pattern { + Self::Pattern { name, pattern, default_init, @@ -519,7 +519,7 @@ impl VisitWith for ObjectPatternElement { V: VisitorMut<'a>, { match self { - ObjectPatternElement::SingleName { + Self::SingleName { name, ident, default_init, @@ -532,8 +532,8 @@ impl VisitWith for ObjectPatternElement { ControlFlow::Continue(()) } } - ObjectPatternElement::RestProperty { ident, .. } => visitor.visit_identifier_mut(ident), - ObjectPatternElement::AssignmentPropertyAccess { + Self::RestProperty { ident, .. } => visitor.visit_identifier_mut(ident), + Self::AssignmentPropertyAccess { name, access, default_init, @@ -546,10 +546,10 @@ impl VisitWith for ObjectPatternElement { ControlFlow::Continue(()) } } - ObjectPatternElement::AssignmentRestPropertyAccess { access, .. } => { + Self::AssignmentRestPropertyAccess { access, .. } => { visitor.visit_property_access_mut(access) } - ObjectPatternElement::Pattern { + Self::Pattern { name, pattern, default_init, @@ -712,7 +712,7 @@ impl VisitWith for ArrayPatternElement { V: Visitor<'a>, { match self { - ArrayPatternElement::SingleName { + Self::SingleName { ident, default_init, } => { @@ -723,11 +723,10 @@ impl VisitWith for ArrayPatternElement { ControlFlow::Continue(()) } } - ArrayPatternElement::PropertyAccess { access } - | ArrayPatternElement::PropertyAccessRest { access } => { + Self::PropertyAccess { access } | Self::PropertyAccessRest { access } => { visitor.visit_property_access(access) } - ArrayPatternElement::Pattern { + Self::Pattern { pattern, default_init, } => { @@ -738,9 +737,9 @@ impl VisitWith for ArrayPatternElement { ControlFlow::Continue(()) } } - ArrayPatternElement::SingleNameRest { ident } => visitor.visit_identifier(ident), - ArrayPatternElement::PatternRest { pattern } => visitor.visit_pattern(pattern), - ArrayPatternElement::Elision => { + Self::SingleNameRest { ident } => visitor.visit_identifier(ident), + Self::PatternRest { pattern } => visitor.visit_pattern(pattern), + Self::Elision => { // special case to be handled by user ControlFlow::Continue(()) } @@ -752,7 +751,7 @@ impl VisitWith for ArrayPatternElement { V: VisitorMut<'a>, { match self { - ArrayPatternElement::SingleName { + Self::SingleName { ident, default_init, } => { @@ -763,11 +762,10 @@ impl VisitWith for ArrayPatternElement { ControlFlow::Continue(()) } } - ArrayPatternElement::PropertyAccess { access } - | ArrayPatternElement::PropertyAccessRest { access } => { + Self::PropertyAccess { access } | Self::PropertyAccessRest { access } => { visitor.visit_property_access_mut(access) } - ArrayPatternElement::Pattern { + Self::Pattern { pattern, default_init, } => { @@ -778,9 +776,9 @@ impl VisitWith for ArrayPatternElement { ControlFlow::Continue(()) } } - ArrayPatternElement::SingleNameRest { ident } => visitor.visit_identifier_mut(ident), - ArrayPatternElement::PatternRest { pattern } => visitor.visit_pattern_mut(pattern), - ArrayPatternElement::Elision => { + Self::SingleNameRest { ident } => visitor.visit_identifier_mut(ident), + Self::PatternRest { pattern } => visitor.visit_pattern_mut(pattern), + Self::Elision => { // special case to be handled by user ControlFlow::Continue(()) } diff --git a/boa_ast/src/position.rs b/boa_ast/src/position.rs index dafba2fb30c..5c7a0956b4b 100644 --- a/boa_ast/src/position.rs +++ b/boa_ast/src/position.rs @@ -30,14 +30,14 @@ impl Position { /// Gets the line number of the position. #[inline] #[must_use] - pub fn line_number(self) -> u32 { + pub const fn line_number(self) -> u32 { self.line_number.get() } /// Gets the column number of the position. #[inline] #[must_use] - pub fn column_number(self) -> u32 { + pub const fn column_number(self) -> u32 { self.column_number.get() } } @@ -79,14 +79,14 @@ impl Span { /// Gets the starting position of the span. #[inline] #[must_use] - pub fn start(self) -> Position { + pub const fn start(self) -> Position { self.start } /// Gets the final position of the span. #[inline] #[must_use] - pub fn end(self) -> Position { + pub const fn end(self) -> Position { self.end } diff --git a/boa_ast/src/property.rs b/boa_ast/src/property.rs index c6537199038..6f5b5d063fd 100644 --- a/boa_ast/src/property.rs +++ b/boa_ast/src/property.rs @@ -86,17 +86,17 @@ impl VisitWith for PropertyDefinition { V: Visitor<'a>, { match self { - PropertyDefinition::IdentifierReference(id) => visitor.visit_identifier(id), - PropertyDefinition::Property(pn, expr) => { + Self::IdentifierReference(id) => visitor.visit_identifier(id), + Self::Property(pn, expr) => { try_break!(visitor.visit_property_name(pn)); visitor.visit_expression(expr) } - PropertyDefinition::MethodDefinition(pn, md) => { + Self::MethodDefinition(pn, md) => { try_break!(visitor.visit_property_name(pn)); visitor.visit_method_definition(md) } - PropertyDefinition::SpreadObject(expr) => visitor.visit_expression(expr), - PropertyDefinition::CoverInitializedName(id, expr) => { + Self::SpreadObject(expr) => visitor.visit_expression(expr), + Self::CoverInitializedName(id, expr) => { try_break!(visitor.visit_identifier(id)); visitor.visit_expression(expr) } @@ -108,17 +108,17 @@ impl VisitWith for PropertyDefinition { V: VisitorMut<'a>, { match self { - PropertyDefinition::IdentifierReference(id) => visitor.visit_identifier_mut(id), - PropertyDefinition::Property(pn, expr) => { + Self::IdentifierReference(id) => visitor.visit_identifier_mut(id), + Self::Property(pn, expr) => { try_break!(visitor.visit_property_name_mut(pn)); visitor.visit_expression_mut(expr) } - PropertyDefinition::MethodDefinition(pn, md) => { + Self::MethodDefinition(pn, md) => { try_break!(visitor.visit_property_name_mut(pn)); visitor.visit_method_definition_mut(md) } - PropertyDefinition::SpreadObject(expr) => visitor.visit_expression_mut(expr), - PropertyDefinition::CoverInitializedName(id, expr) => { + Self::SpreadObject(expr) => visitor.visit_expression_mut(expr), + Self::CoverInitializedName(id, expr) => { try_break!(visitor.visit_identifier_mut(id)); visitor.visit_expression_mut(expr) } @@ -219,12 +219,10 @@ impl VisitWith for MethodDefinition { V: Visitor<'a>, { match self { - MethodDefinition::Get(f) | MethodDefinition::Set(f) | MethodDefinition::Ordinary(f) => { - visitor.visit_function(f) - } - MethodDefinition::Generator(g) => visitor.visit_generator(g), - MethodDefinition::AsyncGenerator(ag) => visitor.visit_async_generator(ag), - MethodDefinition::Async(af) => visitor.visit_async_function(af), + Self::Get(f) | Self::Set(f) | Self::Ordinary(f) => visitor.visit_function(f), + Self::Generator(g) => visitor.visit_generator(g), + Self::AsyncGenerator(ag) => visitor.visit_async_generator(ag), + Self::Async(af) => visitor.visit_async_function(af), } } @@ -233,12 +231,10 @@ impl VisitWith for MethodDefinition { V: VisitorMut<'a>, { match self { - MethodDefinition::Get(f) | MethodDefinition::Set(f) | MethodDefinition::Ordinary(f) => { - visitor.visit_function_mut(f) - } - MethodDefinition::Generator(g) => visitor.visit_generator_mut(g), - MethodDefinition::AsyncGenerator(ag) => visitor.visit_async_generator_mut(ag), - MethodDefinition::Async(af) => visitor.visit_async_function_mut(af), + Self::Get(f) | Self::Set(f) | Self::Ordinary(f) => visitor.visit_function_mut(f), + Self::Generator(g) => visitor.visit_generator_mut(g), + Self::AsyncGenerator(ag) => visitor.visit_async_generator_mut(ag), + Self::Async(af) => visitor.visit_async_function_mut(af), } } } @@ -273,7 +269,7 @@ pub enum PropertyName { impl PropertyName { /// Returns the literal property name if it exists. #[must_use] - pub fn literal(&self) -> Option { + pub const fn literal(&self) -> Option { if let Self::Literal(sym) = self { Some(*sym) } else { @@ -283,7 +279,7 @@ impl PropertyName { /// Returns the expression if the property name is computed. #[must_use] - pub fn computed(&self) -> Option<&Expression> { + pub const fn computed(&self) -> Option<&Expression> { if let Self::Computed(expr) = self { Some(expr) } else { @@ -293,11 +289,12 @@ impl PropertyName { /// Returns either the literal property name or the computed const string property name. #[must_use] - pub fn prop_name(&self) -> Option { + pub const fn prop_name(&self) -> Option { match self { - PropertyName::Literal(sym) - | PropertyName::Computed(Expression::Literal(Literal::String(sym))) => Some(*sym), - PropertyName::Computed(_) => None, + Self::Literal(sym) | Self::Computed(Expression::Literal(Literal::String(sym))) => { + Some(*sym) + } + Self::Computed(_) => None, } } } @@ -305,8 +302,8 @@ impl PropertyName { impl ToInternedString for PropertyName { fn to_interned_string(&self, interner: &Interner) -> String { match self { - PropertyName::Literal(key) => interner.resolve_expect(*key).to_string(), - PropertyName::Computed(key) => key.to_interned_string(interner), + Self::Literal(key) => interner.resolve_expect(*key).to_string(), + Self::Computed(key) => key.to_interned_string(interner), } } } @@ -329,8 +326,8 @@ impl VisitWith for PropertyName { V: Visitor<'a>, { match self { - PropertyName::Literal(sym) => visitor.visit_sym(sym), - PropertyName::Computed(expr) => visitor.visit_expression(expr), + Self::Literal(sym) => visitor.visit_sym(sym), + Self::Computed(expr) => visitor.visit_expression(expr), } } @@ -339,8 +336,8 @@ impl VisitWith for PropertyName { V: VisitorMut<'a>, { match self { - PropertyName::Literal(sym) => visitor.visit_sym_mut(sym), - PropertyName::Computed(expr) => visitor.visit_expression_mut(expr), + Self::Literal(sym) => visitor.visit_sym_mut(sym), + Self::Computed(expr) => visitor.visit_expression_mut(expr), } } } diff --git a/boa_ast/src/statement/block.rs b/boa_ast/src/statement/block.rs index afd402ae33e..ca7f4ff548c 100644 --- a/boa_ast/src/statement/block.rs +++ b/boa_ast/src/statement/block.rs @@ -34,7 +34,7 @@ impl Block { /// Gets the list of statements and declarations in this block. #[inline] #[must_use] - pub fn statement_list(&self) -> &StatementList { + pub const fn statement_list(&self) -> &StatementList { &self.statements } } diff --git a/boa_ast/src/statement/if.rs b/boa_ast/src/statement/if.rs index f41cbae6614..0a9445ac74b 100644 --- a/boa_ast/src/statement/if.rs +++ b/boa_ast/src/statement/if.rs @@ -38,14 +38,14 @@ impl If { /// Gets the condition of the if statement. #[inline] #[must_use] - pub fn cond(&self) -> &Expression { + pub const fn cond(&self) -> &Expression { &self.condition } /// Gets the body to execute if the condition is true. #[inline] #[must_use] - pub fn body(&self) -> &Statement { + pub const fn body(&self) -> &Statement { &self.body } diff --git a/boa_ast/src/statement/iteration/break.rs b/boa_ast/src/statement/iteration/break.rs index 578f91a9027..f1f5f821c0a 100644 --- a/boa_ast/src/statement/iteration/break.rs +++ b/boa_ast/src/statement/iteration/break.rs @@ -28,24 +28,23 @@ pub struct Break { impl Break { /// Creates a `Break` AST node. #[must_use] - pub fn new(label: Option) -> Self { + pub const fn new(label: Option) -> Self { Self { label } } /// Gets the label of the break statement, if any. #[must_use] - pub fn label(&self) -> Option { + pub const fn label(&self) -> Option { self.label } } impl ToInternedString for Break { fn to_interned_string(&self, interner: &Interner) -> String { - if let Some(label) = self.label { - format!("break {}", interner.resolve_expect(label)) - } else { - "break".to_owned() - } + self.label.map_or_else( + || "break".to_owned(), + |label| format!("break {}", interner.resolve_expect(label)), + ) } } diff --git a/boa_ast/src/statement/iteration/continue.rs b/boa_ast/src/statement/iteration/continue.rs index ed2a19f527e..ed5ddb2f2c0 100644 --- a/boa_ast/src/statement/iteration/continue.rs +++ b/boa_ast/src/statement/iteration/continue.rs @@ -26,24 +26,23 @@ pub struct Continue { impl Continue { /// Creates a `Continue` AST node. #[must_use] - pub fn new(label: Option) -> Self { + pub const fn new(label: Option) -> Self { Self { label } } /// Gets the label of this `Continue` statement. #[must_use] - pub fn label(&self) -> Option { + pub const fn label(&self) -> Option { self.label } } impl ToInternedString for Continue { fn to_interned_string(&self, interner: &Interner) -> String { - if let Some(label) = self.label { - format!("continue {}", interner.resolve_expect(label)) - } else { - "continue".to_owned() - } + self.label.map_or_else( + || "continue".to_owned(), + |label| format!("continue {}", interner.resolve_expect(label)), + ) } } diff --git a/boa_ast/src/statement/iteration/do_while_loop.rs b/boa_ast/src/statement/iteration/do_while_loop.rs index 34fd03f33a4..f3e0b3062b7 100644 --- a/boa_ast/src/statement/iteration/do_while_loop.rs +++ b/boa_ast/src/statement/iteration/do_while_loop.rs @@ -31,14 +31,14 @@ impl DoWhileLoop { /// Gets the body of the do-while loop. #[inline] #[must_use] - pub fn body(&self) -> &Statement { + pub const fn body(&self) -> &Statement { &self.body } /// Gets the condition of the do-while loop. #[inline] #[must_use] - pub fn cond(&self) -> &Expression { + pub const fn cond(&self) -> &Expression { &self.condition } /// Creates a `DoWhileLoop` AST node. diff --git a/boa_ast/src/statement/iteration/for_in_loop.rs b/boa_ast/src/statement/iteration/for_in_loop.rs index 41e11083eff..9c2774accee 100644 --- a/boa_ast/src/statement/iteration/for_in_loop.rs +++ b/boa_ast/src/statement/iteration/for_in_loop.rs @@ -38,21 +38,21 @@ impl ForInLoop { /// Gets the initializer of the for...in loop. #[inline] #[must_use] - pub fn initializer(&self) -> &IterableLoopInitializer { + pub const fn initializer(&self) -> &IterableLoopInitializer { &self.initializer } /// Gets the target object of the for...in loop. #[inline] #[must_use] - pub fn target(&self) -> &Expression { + pub const fn target(&self) -> &Expression { &self.target } /// Gets the body of the for...in loop. #[inline] #[must_use] - pub fn body(&self) -> &Statement { + pub const fn body(&self) -> &Statement { &self.body } } diff --git a/boa_ast/src/statement/iteration/for_loop.rs b/boa_ast/src/statement/iteration/for_loop.rs index ea661100447..d0c79dc09a2 100644 --- a/boa_ast/src/statement/iteration/for_loop.rs +++ b/boa_ast/src/statement/iteration/for_loop.rs @@ -44,28 +44,28 @@ impl ForLoop { /// Gets the initialization node. #[inline] #[must_use] - pub fn init(&self) -> Option<&ForLoopInitializer> { + pub const fn init(&self) -> Option<&ForLoopInitializer> { self.inner.init() } /// Gets the loop condition node. #[inline] #[must_use] - pub fn condition(&self) -> Option<&Expression> { + pub const fn condition(&self) -> Option<&Expression> { self.inner.condition() } /// Gets the final expression node. #[inline] #[must_use] - pub fn final_expr(&self) -> Option<&Expression> { + pub const fn final_expr(&self) -> Option<&Expression> { self.inner.final_expr() } /// Gets the body of the for loop. #[inline] #[must_use] - pub fn body(&self) -> &Statement { + pub const fn body(&self) -> &Statement { self.inner.body() } } @@ -148,7 +148,7 @@ struct InnerForLoop { impl InnerForLoop { /// Creates a new inner for loop. #[inline] - fn new( + const fn new( init: Option, condition: Option, final_expr: Option, @@ -164,25 +164,25 @@ impl InnerForLoop { /// Gets the initialization node. #[inline] - fn init(&self) -> Option<&ForLoopInitializer> { + const fn init(&self) -> Option<&ForLoopInitializer> { self.init.as_ref() } /// Gets the loop condition node. #[inline] - fn condition(&self) -> Option<&Expression> { + const fn condition(&self) -> Option<&Expression> { self.condition.as_ref() } /// Gets the final expression node. #[inline] - fn final_expr(&self) -> Option<&Expression> { + const fn final_expr(&self) -> Option<&Expression> { self.final_expr.as_ref() } /// Gets the body of the for loop. #[inline] - fn body(&self) -> &Statement { + const fn body(&self) -> &Statement { &self.body } } @@ -220,21 +220,21 @@ impl ToInternedString for ForLoopInitializer { impl From for ForLoopInitializer { #[inline] fn from(expr: Expression) -> Self { - ForLoopInitializer::Expression(expr) + Self::Expression(expr) } } impl From for ForLoopInitializer { #[inline] fn from(list: LexicalDeclaration) -> Self { - ForLoopInitializer::Lexical(list) + Self::Lexical(list) } } impl From for ForLoopInitializer { #[inline] fn from(list: VarDeclaration) -> Self { - ForLoopInitializer::Var(list) + Self::Var(list) } } @@ -244,9 +244,9 @@ impl VisitWith for ForLoopInitializer { V: Visitor<'a>, { match self { - ForLoopInitializer::Expression(expr) => visitor.visit_expression(expr), - ForLoopInitializer::Var(vd) => visitor.visit_var_declaration(vd), - ForLoopInitializer::Lexical(ld) => visitor.visit_lexical_declaration(ld), + Self::Expression(expr) => visitor.visit_expression(expr), + Self::Var(vd) => visitor.visit_var_declaration(vd), + Self::Lexical(ld) => visitor.visit_lexical_declaration(ld), } } @@ -255,9 +255,9 @@ impl VisitWith for ForLoopInitializer { V: VisitorMut<'a>, { match self { - ForLoopInitializer::Expression(expr) => visitor.visit_expression_mut(expr), - ForLoopInitializer::Var(vd) => visitor.visit_var_declaration_mut(vd), - ForLoopInitializer::Lexical(ld) => visitor.visit_lexical_declaration_mut(ld), + Self::Expression(expr) => visitor.visit_expression_mut(expr), + Self::Var(vd) => visitor.visit_var_declaration_mut(vd), + Self::Lexical(ld) => visitor.visit_lexical_declaration_mut(ld), } } } diff --git a/boa_ast/src/statement/iteration/for_of_loop.rs b/boa_ast/src/statement/iteration/for_of_loop.rs index ead1768106c..d5b02aa4975 100644 --- a/boa_ast/src/statement/iteration/for_of_loop.rs +++ b/boa_ast/src/statement/iteration/for_of_loop.rs @@ -50,28 +50,28 @@ impl ForOfLoop { /// Gets the initializer of the for...of loop. #[inline] #[must_use] - pub fn initializer(&self) -> &IterableLoopInitializer { + pub const fn initializer(&self) -> &IterableLoopInitializer { &self.init } /// Gets the iterable expression of the for...of loop. #[inline] #[must_use] - pub fn iterable(&self) -> &Expression { + pub const fn iterable(&self) -> &Expression { &self.iterable } /// Gets the body to execute in the for...of loop. #[inline] #[must_use] - pub fn body(&self) -> &Statement { + pub const fn body(&self) -> &Statement { &self.body } /// Returns true if this "for...of" loop is an "for await...of" loop. #[inline] #[must_use] - pub fn r#await(&self) -> bool { + pub const fn r#await(&self) -> bool { self.r#await } } diff --git a/boa_ast/src/statement/iteration/mod.rs b/boa_ast/src/statement/iteration/mod.rs index 4377bedc694..de7ebc7c87d 100644 --- a/boa_ast/src/statement/iteration/mod.rs +++ b/boa_ast/src/statement/iteration/mod.rs @@ -73,12 +73,10 @@ impl VisitWith for IterableLoopInitializer { V: Visitor<'a>, { match self { - IterableLoopInitializer::Identifier(id) => visitor.visit_identifier(id), - IterableLoopInitializer::Access(pa) => visitor.visit_property_access(pa), - IterableLoopInitializer::Var(b) - | IterableLoopInitializer::Let(b) - | IterableLoopInitializer::Const(b) => visitor.visit_binding(b), - IterableLoopInitializer::Pattern(p) => visitor.visit_pattern(p), + Self::Identifier(id) => visitor.visit_identifier(id), + Self::Access(pa) => visitor.visit_property_access(pa), + Self::Var(b) | Self::Let(b) | Self::Const(b) => visitor.visit_binding(b), + Self::Pattern(p) => visitor.visit_pattern(p), } } @@ -87,12 +85,10 @@ impl VisitWith for IterableLoopInitializer { V: VisitorMut<'a>, { match self { - IterableLoopInitializer::Identifier(id) => visitor.visit_identifier_mut(id), - IterableLoopInitializer::Access(pa) => visitor.visit_property_access_mut(pa), - IterableLoopInitializer::Var(b) - | IterableLoopInitializer::Let(b) - | IterableLoopInitializer::Const(b) => visitor.visit_binding_mut(b), - IterableLoopInitializer::Pattern(p) => visitor.visit_pattern_mut(p), + Self::Identifier(id) => visitor.visit_identifier_mut(id), + Self::Access(pa) => visitor.visit_property_access_mut(pa), + Self::Var(b) | Self::Let(b) | Self::Const(b) => visitor.visit_binding_mut(b), + Self::Pattern(p) => visitor.visit_pattern_mut(p), } } } diff --git a/boa_ast/src/statement/iteration/while_loop.rs b/boa_ast/src/statement/iteration/while_loop.rs index ab568182100..00494d66ae8 100644 --- a/boa_ast/src/statement/iteration/while_loop.rs +++ b/boa_ast/src/statement/iteration/while_loop.rs @@ -40,14 +40,14 @@ impl WhileLoop { /// Gets the condition of the while loop. #[inline] #[must_use] - pub fn condition(&self) -> &Expression { + pub const fn condition(&self) -> &Expression { &self.condition } /// Gets the body of the while loop. #[inline] #[must_use] - pub fn body(&self) -> &Statement { + pub const fn body(&self) -> &Statement { &self.body } } diff --git a/boa_ast/src/statement/labelled.rs b/boa_ast/src/statement/labelled.rs index 89884ff8537..1fb5cdd3c4e 100644 --- a/boa_ast/src/statement/labelled.rs +++ b/boa_ast/src/statement/labelled.rs @@ -29,8 +29,8 @@ pub enum LabelledItem { impl LabelledItem { pub(crate) fn to_indented_string(&self, interner: &Interner, indentation: usize) -> String { match self { - LabelledItem::Function(f) => f.to_indented_string(interner, indentation), - LabelledItem::Statement(stmt) => stmt.to_indented_string(interner, indentation), + Self::Function(f) => f.to_indented_string(interner, indentation), + Self::Statement(stmt) => stmt.to_indented_string(interner, indentation), } } } @@ -59,8 +59,8 @@ impl VisitWith for LabelledItem { V: Visitor<'a>, { match self { - LabelledItem::Function(f) => visitor.visit_function(f), - LabelledItem::Statement(s) => visitor.visit_statement(s), + Self::Function(f) => visitor.visit_function(f), + Self::Statement(s) => visitor.visit_statement(s), } } @@ -69,8 +69,8 @@ impl VisitWith for LabelledItem { V: VisitorMut<'a>, { match self { - LabelledItem::Function(f) => visitor.visit_function_mut(f), - LabelledItem::Statement(s) => visitor.visit_statement_mut(s), + Self::Function(f) => visitor.visit_function_mut(f), + Self::Statement(s) => visitor.visit_statement_mut(s), } } } @@ -101,13 +101,13 @@ impl Labelled { /// Gets the labelled item. #[must_use] - pub fn item(&self) -> &LabelledItem { + pub const fn item(&self) -> &LabelledItem { &self.item } /// Gets the label name. #[must_use] - pub fn label(&self) -> Sym { + pub const fn label(&self) -> Sym { self.label } diff --git a/boa_ast/src/statement/mod.rs b/boa_ast/src/statement/mod.rs index f412a47b98b..bbd610b190a 100644 --- a/boa_ast/src/statement/mod.rs +++ b/boa_ast/src/statement/mod.rs @@ -188,26 +188,26 @@ impl VisitWith for Statement { V: Visitor<'a>, { match self { - Statement::Block(b) => visitor.visit_block(b), - Statement::Var(v) => visitor.visit_var_declaration(v), - Statement::Empty => { + Self::Block(b) => visitor.visit_block(b), + Self::Var(v) => visitor.visit_var_declaration(v), + Self::Empty => { // do nothing; there is nothing to visit here ControlFlow::Continue(()) } - Statement::Expression(e) => visitor.visit_expression(e), - Statement::If(i) => visitor.visit_if(i), - Statement::DoWhileLoop(dw) => visitor.visit_do_while_loop(dw), - Statement::WhileLoop(w) => visitor.visit_while_loop(w), - Statement::ForLoop(f) => visitor.visit_for_loop(f), - Statement::ForInLoop(fi) => visitor.visit_for_in_loop(fi), - Statement::ForOfLoop(fo) => visitor.visit_for_of_loop(fo), - Statement::Switch(s) => visitor.visit_switch(s), - Statement::Continue(c) => visitor.visit_continue(c), - Statement::Break(b) => visitor.visit_break(b), - Statement::Return(r) => visitor.visit_return(r), - Statement::Labelled(l) => visitor.visit_labelled(l), - Statement::Throw(th) => visitor.visit_throw(th), - Statement::Try(tr) => visitor.visit_try(tr), + Self::Expression(e) => visitor.visit_expression(e), + Self::If(i) => visitor.visit_if(i), + Self::DoWhileLoop(dw) => visitor.visit_do_while_loop(dw), + Self::WhileLoop(w) => visitor.visit_while_loop(w), + Self::ForLoop(f) => visitor.visit_for_loop(f), + Self::ForInLoop(fi) => visitor.visit_for_in_loop(fi), + Self::ForOfLoop(fo) => visitor.visit_for_of_loop(fo), + Self::Switch(s) => visitor.visit_switch(s), + Self::Continue(c) => visitor.visit_continue(c), + Self::Break(b) => visitor.visit_break(b), + Self::Return(r) => visitor.visit_return(r), + Self::Labelled(l) => visitor.visit_labelled(l), + Self::Throw(th) => visitor.visit_throw(th), + Self::Try(tr) => visitor.visit_try(tr), } } @@ -216,26 +216,26 @@ impl VisitWith for Statement { V: VisitorMut<'a>, { match self { - Statement::Block(b) => visitor.visit_block_mut(b), - Statement::Var(v) => visitor.visit_var_declaration_mut(v), - Statement::Empty => { + Self::Block(b) => visitor.visit_block_mut(b), + Self::Var(v) => visitor.visit_var_declaration_mut(v), + Self::Empty => { // do nothing; there is nothing to visit here ControlFlow::Continue(()) } - Statement::Expression(e) => visitor.visit_expression_mut(e), - Statement::If(i) => visitor.visit_if_mut(i), - Statement::DoWhileLoop(dw) => visitor.visit_do_while_loop_mut(dw), - Statement::WhileLoop(w) => visitor.visit_while_loop_mut(w), - Statement::ForLoop(f) => visitor.visit_for_loop_mut(f), - Statement::ForInLoop(fi) => visitor.visit_for_in_loop_mut(fi), - Statement::ForOfLoop(fo) => visitor.visit_for_of_loop_mut(fo), - Statement::Switch(s) => visitor.visit_switch_mut(s), - Statement::Continue(c) => visitor.visit_continue_mut(c), - Statement::Break(b) => visitor.visit_break_mut(b), - Statement::Return(r) => visitor.visit_return_mut(r), - Statement::Labelled(l) => visitor.visit_labelled_mut(l), - Statement::Throw(th) => visitor.visit_throw_mut(th), - Statement::Try(tr) => visitor.visit_try_mut(tr), + Self::Expression(e) => visitor.visit_expression_mut(e), + Self::If(i) => visitor.visit_if_mut(i), + Self::DoWhileLoop(dw) => visitor.visit_do_while_loop_mut(dw), + Self::WhileLoop(w) => visitor.visit_while_loop_mut(w), + Self::ForLoop(f) => visitor.visit_for_loop_mut(f), + Self::ForInLoop(fi) => visitor.visit_for_in_loop_mut(fi), + Self::ForOfLoop(fo) => visitor.visit_for_of_loop_mut(fo), + Self::Switch(s) => visitor.visit_switch_mut(s), + Self::Continue(c) => visitor.visit_continue_mut(c), + Self::Break(b) => visitor.visit_break_mut(b), + Self::Return(r) => visitor.visit_return_mut(r), + Self::Labelled(l) => visitor.visit_labelled_mut(l), + Self::Throw(th) => visitor.visit_throw_mut(th), + Self::Try(tr) => visitor.visit_try_mut(tr), } } } diff --git a/boa_ast/src/statement/return.rs b/boa_ast/src/statement/return.rs index 6cd3d36ba22..9477a2805bf 100644 --- a/boa_ast/src/statement/return.rs +++ b/boa_ast/src/statement/return.rs @@ -33,13 +33,13 @@ pub struct Return { impl Return { /// Gets the target expression value of this `Return` statement. #[must_use] - pub fn target(&self) -> Option<&Expression> { + pub const fn target(&self) -> Option<&Expression> { self.target.as_ref() } /// Creates a `Return` AST node. #[must_use] - pub fn new(expression: Option) -> Self { + pub const fn new(expression: Option) -> Self { Self { target: expression } } } @@ -52,10 +52,10 @@ impl From for Statement { impl ToInternedString for Return { fn to_interned_string(&self, interner: &Interner) -> String { - match self.target() { - Some(ex) => format!("return {}", ex.to_interned_string(interner)), - None => "return".to_owned(), - } + self.target().map_or_else( + || "return".to_owned(), + |ex| format!("return {}", ex.to_interned_string(interner)), + ) } } diff --git a/boa_ast/src/statement/switch.rs b/boa_ast/src/statement/switch.rs index 77ce5d79442..6da9f8e2c14 100644 --- a/boa_ast/src/statement/switch.rs +++ b/boa_ast/src/statement/switch.rs @@ -30,21 +30,21 @@ impl Case { /// Creates a `Case` AST node. #[inline] #[must_use] - pub fn new(condition: Expression, body: StatementList) -> Self { + pub const fn new(condition: Expression, body: StatementList) -> Self { Self { condition, body } } /// Gets the condition of the case. #[inline] #[must_use] - pub fn condition(&self) -> &Expression { + pub const fn condition(&self) -> &Expression { &self.condition } /// Gets the statement listin the body of the case. #[inline] #[must_use] - pub fn body(&self) -> &StatementList { + pub const fn body(&self) -> &StatementList { &self.body } } @@ -107,21 +107,21 @@ impl Switch { /// Gets the value to switch. #[inline] #[must_use] - pub fn val(&self) -> &Expression { + pub const fn val(&self) -> &Expression { &self.val } /// Gets the list of cases for the switch statement. #[inline] #[must_use] - pub fn cases(&self) -> &[Case] { + pub const fn cases(&self) -> &[Case] { &self.cases } /// Gets the default statement list, if any. #[inline] #[must_use] - pub fn default(&self) -> Option<&StatementList> { + pub const fn default(&self) -> Option<&StatementList> { self.default.as_ref() } } diff --git a/boa_ast/src/statement/throw.rs b/boa_ast/src/statement/throw.rs index e3936d5c919..90df3b04ad3 100644 --- a/boa_ast/src/statement/throw.rs +++ b/boa_ast/src/statement/throw.rs @@ -30,13 +30,13 @@ pub struct Throw { impl Throw { /// Gets the target expression of this `Throw` statement. #[must_use] - pub fn target(&self) -> &Expression { + pub const fn target(&self) -> &Expression { &self.target } /// Creates a `Throw` AST node. #[must_use] - pub fn new(target: Expression) -> Self { + pub const fn new(target: Expression) -> Self { Self { target } } } diff --git a/boa_ast/src/statement/try.rs b/boa_ast/src/statement/try.rs index c8c673e69a1..2e5a67bc87e 100644 --- a/boa_ast/src/statement/try.rs +++ b/boa_ast/src/statement/try.rs @@ -47,21 +47,21 @@ impl Try { /// Creates a new `Try` AST node. #[inline] #[must_use] - pub fn new(block: Block, handler: ErrorHandler) -> Self { + pub const fn new(block: Block, handler: ErrorHandler) -> Self { Self { block, handler } } /// Gets the `try` block. #[inline] #[must_use] - pub fn block(&self) -> &Block { + pub const fn block(&self) -> &Block { &self.block } /// Gets the `catch` block, if any. #[inline] #[must_use] - pub fn catch(&self) -> Option<&Catch> { + pub const fn catch(&self) -> Option<&Catch> { match &self.handler { ErrorHandler::Catch(c) | ErrorHandler::Full(c, _) => Some(c), ErrorHandler::Finally(_) => None, @@ -71,7 +71,7 @@ impl Try { /// Gets the `finally` block, if any. #[inline] #[must_use] - pub fn finally(&self) -> Option<&Finally> { + pub const fn finally(&self) -> Option<&Finally> { match &self.handler { ErrorHandler::Finally(f) | ErrorHandler::Full(_, f) => Some(f), ErrorHandler::Catch(_) => None, @@ -150,21 +150,21 @@ impl Catch { /// Creates a new catch block. #[inline] #[must_use] - pub fn new(parameter: Option, block: Block) -> Self { + pub const fn new(parameter: Option, block: Block) -> Self { Self { parameter, block } } /// Gets the parameter of the catch block. #[inline] #[must_use] - pub fn parameter(&self) -> Option<&Binding> { + pub const fn parameter(&self) -> Option<&Binding> { self.parameter.as_ref() } /// Retrieves the catch execution block. #[inline] #[must_use] - pub fn block(&self) -> &Block { + pub const fn block(&self) -> &Block { &self.block } } @@ -218,7 +218,7 @@ impl Finally { /// Gets the finally block. #[inline] #[must_use] - pub fn block(&self) -> &Block { + pub const fn block(&self) -> &Block { &self.block } } diff --git a/boa_ast/src/statement_list.rs b/boa_ast/src/statement_list.rs index 35221ecf070..1e6cacf6da3 100644 --- a/boa_ast/src/statement_list.rs +++ b/boa_ast/src/statement_list.rs @@ -30,7 +30,7 @@ pub enum StatementListItem { impl StatementListItem { /// Returns a node ordering based on the hoistability of each statement. #[must_use] - pub fn hoistable_order(a: &Self, b: &Self) -> Ordering { + pub const fn hoistable_order(a: &Self, b: &Self) -> Ordering { match (a, b) { ( Self::Declaration(Declaration::Function(_)), @@ -59,10 +59,10 @@ impl ToIndentedString for StatementListItem { let mut buf = " ".repeat(indentation); match self { - StatementListItem::Statement(stmt) => { + Self::Statement(stmt) => { buf.push_str(&stmt.to_no_indent_string(interner, indentation)); } - StatementListItem::Declaration(decl) => { + Self::Declaration(decl) => { buf.push_str(&decl.to_indented_string(interner, indentation)); } } @@ -74,14 +74,14 @@ impl ToIndentedString for StatementListItem { impl From for StatementListItem { #[inline] fn from(stmt: Statement) -> Self { - StatementListItem::Statement(stmt) + Self::Statement(stmt) } } impl From for StatementListItem { #[inline] fn from(decl: Declaration) -> Self { - StatementListItem::Declaration(decl) + Self::Declaration(decl) } } @@ -91,8 +91,8 @@ impl VisitWith for StatementListItem { V: Visitor<'a>, { match self { - StatementListItem::Statement(statement) => visitor.visit_statement(statement), - StatementListItem::Declaration(declaration) => visitor.visit_declaration(declaration), + Self::Statement(statement) => visitor.visit_statement(statement), + Self::Declaration(declaration) => visitor.visit_declaration(declaration), } } @@ -101,10 +101,8 @@ impl VisitWith for StatementListItem { V: VisitorMut<'a>, { match self { - StatementListItem::Statement(statement) => visitor.visit_statement_mut(statement), - StatementListItem::Declaration(declaration) => { - visitor.visit_declaration_mut(declaration) - } + Self::Statement(statement) => visitor.visit_statement_mut(statement), + Self::Declaration(declaration) => visitor.visit_declaration_mut(declaration), } } } @@ -126,14 +124,14 @@ impl StatementList { /// Gets the list of statements. #[inline] #[must_use] - pub fn statements(&self) -> &[StatementListItem] { + pub const fn statements(&self) -> &[StatementListItem] { &self.statements } /// Get the strict mode. #[inline] #[must_use] - pub fn strict(&self) -> bool { + pub const fn strict(&self) -> bool { self.strict } From 9ca70b115930fc17c799bf55bda8298ea4829e3a Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Mon, 14 Nov 2022 22:57:35 +0100 Subject: [PATCH 2/2] Move `missing_docs` to warn --- boa_ast/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/boa_ast/src/lib.rs b/boa_ast/src/lib.rs index f4ec5360375..61bb575bcca 100644 --- a/boa_ast/src/lib.rs +++ b/boa_ast/src/lib.rs @@ -12,7 +12,7 @@ //! [early]: https://tc39.es/ecma262/#sec-static-semantic-rules #![cfg_attr(not(test), forbid(clippy::unwrap_used))] -#![warn(clippy::dbg_macro)] +#![warn(missing_docs, clippy::dbg_macro)] #![deny( // rustc lint groups https://doc.rust-lang.org/rustc/lints/groups.html warnings, @@ -30,7 +30,6 @@ missing_abi, missing_copy_implementations, missing_debug_implementations, - missing_docs, non_ascii_idents, noop_method_call, single_use_lifetimes,