Skip to content

Commit

Permalink
Clippy updates: add panics and etc. (#3235)
Browse files Browse the repository at this point in the history
* Adding Panics doc to Profiler's drop method

* forgot to rustfmt

* Address clippy lints/temporarily allow some

* boa_ast -> rustfmt

* all features and all targets

* Trigger re-run

* Add workspace.resolver

* markdown lint

* Trigger actions pt. 2

---------

Co-authored-by: jedel1043 <[email protected]>
  • Loading branch information
nekevss and jedel1043 authored Sep 5, 2023
1 parent b47087c commit f92e748
Show file tree
Hide file tree
Showing 35 changed files with 103 additions and 81 deletions.
2 changes: 1 addition & 1 deletion ABOUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ website][boa-web].
Try out the most recent release with Boa's live demo
[playground][boa-playground].

# Boa Crates
## Boa Crates

- [**`boa_ast`**][ast] - Boa's ECMAScript Abstract Syntax Tree.
- [**`boa_engine`**][engine] - Boa's implementation of ECMAScript builtin objects and
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"boa_ast",
"boa_cli",
Expand Down
4 changes: 2 additions & 2 deletions boa_ast/src/declaration/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl VisitWith for VariableList {
where
V: Visitor<'a>,
{
for variable in self.list.iter() {
for variable in &*self.list {
try_break!(visitor.visit_variable(variable));
}
ControlFlow::Continue(())
Expand All @@ -209,7 +209,7 @@ impl VisitWith for VariableList {
where
V: VisitorMut<'a>,
{
for variable in self.list.iter_mut() {
for variable in &mut *self.list {
try_break!(visitor.visit_variable_mut(variable));
}
ControlFlow::Continue(())
Expand Down
8 changes: 4 additions & 4 deletions boa_ast/src/expression/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl VisitWith for Call {
V: Visitor<'a>,
{
try_break!(visitor.visit_expression(&self.function));
for expr in self.args.iter() {
for expr in &*self.args {
try_break!(visitor.visit_expression(expr));
}
ControlFlow::Continue(())
Expand All @@ -89,7 +89,7 @@ impl VisitWith for Call {
V: VisitorMut<'a>,
{
try_break!(visitor.visit_expression_mut(&mut self.function));
for expr in self.args.iter_mut() {
for expr in &mut *self.args {
try_break!(visitor.visit_expression_mut(expr));
}
ControlFlow::Continue(())
Expand Down Expand Up @@ -146,7 +146,7 @@ impl VisitWith for SuperCall {
where
V: Visitor<'a>,
{
for expr in self.args.iter() {
for expr in &*self.args {
try_break!(visitor.visit_expression(expr));
}
ControlFlow::Continue(())
Expand All @@ -156,7 +156,7 @@ impl VisitWith for SuperCall {
where
V: VisitorMut<'a>,
{
for expr in self.args.iter_mut() {
for expr in &mut *self.args {
try_break!(visitor.visit_expression_mut(expr));
}
ControlFlow::Continue(())
Expand Down
6 changes: 3 additions & 3 deletions boa_ast/src/expression/literal/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl ToIndentedString for ObjectLiteral {
fn to_indented_string(&self, interner: &Interner, indent_n: usize) -> String {
let mut buf = "{\n".to_owned();
let indentation = " ".repeat(indent_n + 1);
for property in self.properties().iter() {
for property in &*self.properties {
buf.push_str(&match property {
PropertyDefinition::IdentifierReference(ident) => {
format!("{indentation}{},\n", interner.resolve_expect(ident.sym()))
Expand Down Expand Up @@ -324,7 +324,7 @@ impl VisitWith for ObjectLiteral {
where
V: Visitor<'a>,
{
for pd in self.properties.iter() {
for pd in &*self.properties {
try_break!(visitor.visit_property_definition(pd));
}
ControlFlow::Continue(())
Expand All @@ -334,7 +334,7 @@ impl VisitWith for ObjectLiteral {
where
V: VisitorMut<'a>,
{
for pd in self.properties.iter_mut() {
for pd in &mut *self.properties {
try_break!(visitor.visit_property_definition_mut(pd));
}
ControlFlow::Continue(())
Expand Down
6 changes: 3 additions & 3 deletions boa_ast/src/expression/literal/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl ToInternedString for TemplateLiteral {
fn to_interned_string(&self, interner: &Interner) -> String {
let mut buf = "`".to_owned();

for elt in self.elements.iter() {
for elt in &*self.elements {
match elt {
TemplateElement::String(s) => buf.push_str(&interner.resolve_expect(*s).join(
Cow::Borrowed,
Expand All @@ -93,7 +93,7 @@ impl VisitWith for TemplateLiteral {
where
V: Visitor<'a>,
{
for element in self.elements.iter() {
for element in &*self.elements {
try_break!(visitor.visit_template_element(element));
}
ControlFlow::Continue(())
Expand All @@ -103,7 +103,7 @@ impl VisitWith for TemplateLiteral {
where
V: VisitorMut<'a>,
{
for element in self.elements.iter_mut() {
for element in &mut *self.elements {
try_break!(visitor.visit_template_element_mut(element));
}
ControlFlow::Continue(())
Expand Down
4 changes: 2 additions & 2 deletions boa_ast/src/expression/optional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl VisitWith for Optional {
V: Visitor<'a>,
{
try_break!(visitor.visit_expression(&self.target));
for op in self.chain.iter() {
for op in &*self.chain {
try_break!(visitor.visit_optional_operation(op));
}
ControlFlow::Continue(())
Expand All @@ -197,7 +197,7 @@ impl VisitWith for Optional {
V: VisitorMut<'a>,
{
try_break!(visitor.visit_expression_mut(&mut self.target));
for op in self.chain.iter_mut() {
for op in &mut *self.chain {
try_break!(visitor.visit_optional_operation_mut(op));
}
ControlFlow::Continue(())
Expand Down
8 changes: 4 additions & 4 deletions boa_ast/src/expression/tagged_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ impl VisitWith for TaggedTemplate {
V: Visitor<'a>,
{
try_break!(visitor.visit_expression(&self.tag));
for raw in self.raws.iter() {
for raw in &*self.raws {
try_break!(visitor.visit_sym(raw));
}
for cooked in self.cookeds.iter().flatten() {
try_break!(visitor.visit_sym(cooked));
}
for expr in self.exprs.iter() {
for expr in &*self.exprs {
try_break!(visitor.visit_expression(expr));
}
ControlFlow::Continue(())
Expand All @@ -128,13 +128,13 @@ impl VisitWith for TaggedTemplate {
V: VisitorMut<'a>,
{
try_break!(visitor.visit_expression_mut(&mut self.tag));
for raw in self.raws.iter_mut() {
for raw in &mut *self.raws {
try_break!(visitor.visit_sym_mut(raw));
}
for cooked in self.cookeds.iter_mut().flatten() {
try_break!(visitor.visit_sym_mut(cooked));
}
for expr in self.exprs.iter_mut() {
for expr in &mut *self.exprs {
try_break!(visitor.visit_expression_mut(expr));
}
ControlFlow::Continue(())
Expand Down
6 changes: 3 additions & 3 deletions boa_ast/src/function/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl ToIndentedString for Class {
block_to_string(expr.body().statements(), interner, indent_n + 1)
));
}
for element in self.elements.iter() {
for element in &*self.elements {
buf.push_str(&match element {
ClassElement::MethodDefinition(name, method) => {
format!(
Expand Down Expand Up @@ -394,7 +394,7 @@ impl VisitWith for Class {
if let Some(func) = &self.constructor {
try_break!(visitor.visit_function(func));
}
for elem in self.elements.iter() {
for elem in &*self.elements {
try_break!(visitor.visit_class_element(elem));
}
ControlFlow::Continue(())
Expand All @@ -413,7 +413,7 @@ impl VisitWith for Class {
if let Some(func) = &mut self.constructor {
try_break!(visitor.visit_function_mut(func));
}
for elem in self.elements.iter_mut() {
for elem in &mut *self.elements {
try_break!(visitor.visit_class_element_mut(elem));
}
ControlFlow::Continue(())
Expand Down
6 changes: 4 additions & 2 deletions boa_ast/src/function/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,21 @@ impl VisitWith for FormalParameterList {
where
V: Visitor<'a>,
{
for parameter in self.parameters.iter() {
for parameter in &*self.parameters {
try_break!(visitor.visit_formal_parameter(parameter));
}

ControlFlow::Continue(())
}

fn visit_with_mut<'a, V>(&'a mut self, visitor: &mut V) -> ControlFlow<V::BreakTy>
where
V: VisitorMut<'a>,
{
for parameter in self.parameters.iter_mut() {
for parameter in &mut *self.parameters {
try_break!(visitor.visit_formal_parameter_mut(parameter));
}

// TODO recompute flags
ControlFlow::Continue(())
}
Expand Down
8 changes: 4 additions & 4 deletions boa_ast/src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl VisitWith for ObjectPattern {
where
V: Visitor<'a>,
{
for elem in self.0.iter() {
for elem in &*self.0 {
try_break!(visitor.visit_object_pattern_element(elem));
}
ControlFlow::Continue(())
Expand All @@ -181,7 +181,7 @@ impl VisitWith for ObjectPattern {
where
V: VisitorMut<'a>,
{
for elem in self.0.iter_mut() {
for elem in &mut *self.0 {
try_break!(visitor.visit_object_pattern_element_mut(elem));
}
ControlFlow::Continue(())
Expand Down Expand Up @@ -249,7 +249,7 @@ impl VisitWith for ArrayPattern {
where
V: Visitor<'a>,
{
for elem in self.0.iter() {
for elem in &*self.0 {
try_break!(visitor.visit_array_pattern_element(elem));
}
ControlFlow::Continue(())
Expand All @@ -259,7 +259,7 @@ impl VisitWith for ArrayPattern {
where
V: VisitorMut<'a>,
{
for elem in self.0.iter_mut() {
for elem in &mut *self.0 {
try_break!(visitor.visit_array_pattern_element_mut(elem));
}
ControlFlow::Continue(())
Expand Down
6 changes: 5 additions & 1 deletion boa_ast/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ pub struct Position {
}

impl Position {
/// Creates a new `Position`.
/// Creates a new `Position` from Non-Zero values.
///
/// # Panics
///
/// Will panic if the line number or column number is zero.
#[inline]
#[track_caller]
#[must_use]
Expand Down
6 changes: 3 additions & 3 deletions boa_ast/src/statement/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl ToIndentedString for Switch {
fn to_indented_string(&self, interner: &Interner, indentation: usize) -> String {
let indent = " ".repeat(indentation);
let mut buf = format!("switch ({}) {{\n", self.val().to_interned_string(interner));
for e in self.cases().iter() {
for e in &*self.cases {
if let Some(condition) = e.condition() {
buf.push_str(&format!(
"{indent} case {}:\n{}",
Expand Down Expand Up @@ -192,7 +192,7 @@ impl VisitWith for Switch {
V: Visitor<'a>,
{
try_break!(visitor.visit_expression(&self.val));
for case in self.cases.iter() {
for case in &*self.cases {
try_break!(visitor.visit_case(case));
}
ControlFlow::Continue(())
Expand All @@ -203,7 +203,7 @@ impl VisitWith for Switch {
V: VisitorMut<'a>,
{
try_break!(visitor.visit_expression_mut(&mut self.val));
for case in self.cases.iter_mut() {
for case in &mut *self.cases {
try_break!(visitor.visit_case_mut(case));
}
ControlFlow::Continue(())
Expand Down
6 changes: 3 additions & 3 deletions boa_ast/src/statement_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl ToIndentedString for StatementList {
fn to_indented_string(&self, interner: &Interner, indentation: usize) -> String {
let mut buf = String::new();
// Print statements
for item in self.statements.iter() {
for item in &*self.statements {
// We rely on the node to add the correct indent.
buf.push_str(&item.to_indented_string(interner, indentation));

Expand All @@ -177,7 +177,7 @@ impl VisitWith for StatementList {
where
V: Visitor<'a>,
{
for statement in self.statements.iter() {
for statement in &*self.statements {
try_break!(visitor.visit_statement_list_item(statement));
}
ControlFlow::Continue(())
Expand All @@ -187,7 +187,7 @@ impl VisitWith for StatementList {
where
V: VisitorMut<'a>,
{
for statement in self.statements.iter_mut() {
for statement in &mut *self.statements {
try_break!(visitor.visit_statement_list_item_mut(statement));
}
ControlFlow::Continue(())
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ impl Json {
partial.iter().map(Vec::as_slice),
&separator,
))
.chain([utf16!("\n"), &stepback[..], utf16!("}")].into_iter())
.chain([utf16!("\n"), &stepback[..], utf16!("}")])
.flatten()
.copied()
.collect::<Vec<_>>();
Expand Down Expand Up @@ -797,7 +797,7 @@ impl Json {
partial.iter().map(Cow::as_ref),
&separator,
))
.chain([utf16!("\n"), &stepback[..], utf16!("]")].into_iter())
.chain([utf16!("\n"), &stepback[..], utf16!("]")])
.flatten()
.copied()
.collect::<Vec<_>>();
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/map/ordered_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct OrderedMap<V, S = RandomState> {
impl<V: Trace, S: BuildHasher> Finalize for OrderedMap<V, S> {}
unsafe impl<V: Trace, S: BuildHasher> Trace for OrderedMap<V, S> {
custom_trace!(this, {
for (k, v) in this.map.iter() {
for (k, v) in &this.map {
if let MapKey::Key(key) = k {
mark(key);
}
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/regexp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ fn last_index() {
fn exec() {
run_test_actions([
TestAction::run_harness(),
TestAction::run(indoc! {r#"
TestAction::run(indoc! {r"
var re = /quick\s(brown).+?(jumps)/ig;
var result = re.exec('The Quick Brown Fox Jumps Over The Lazy Dog');
"#}),
"}),
TestAction::assert(indoc! {r#"
arrayEquals(
result,
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/set/ordered_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct OrderedSet<S = RandomState> {

unsafe impl<S: BuildHasher> Trace for OrderedSet<S> {
custom_trace!(this, {
for v in this.inner.iter() {
for v in &this.inner {
if let MapKey::Key(v) = v {
mark(v);
}
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl String {
let mut buf = [0; 2];

// 2. For each element next of codePoints, do
for arg in args.iter() {
for arg in args {
// a. Let nextCP be ? ToNumber(next).
let nextcp = arg.to_number(context)?;

Expand Down
Loading

0 comments on commit f92e748

Please sign in to comment.