diff --git a/Cargo.toml b/Cargo.toml index 26d7b306260f3..18e8815351255 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,7 +89,6 @@ suspicious_operation_groupings = "warn" redundant_clone = "warn" redundant_pub_crate = "allow" # FIXME debug_assert_with_mut_call = "allow" # FIXME -needless_pass_by_ref_mut = "allow" # FIXME # cargo cargo = { level = "warn", priority = -1 } multiple_crate_versions = "allow" diff --git a/crates/oxc_isolated_declarations/src/function.rs b/crates/oxc_isolated_declarations/src/function.rs index 775bbcecd4e98..03a9268b7f49c 100644 --- a/crates/oxc_isolated_declarations/src/function.rs +++ b/crates/oxc_isolated_declarations/src/function.rs @@ -13,7 +13,7 @@ use crate::{ impl<'a> IsolatedDeclarations<'a> { pub(crate) fn transform_function( - &mut self, + &self, func: &Function<'a>, declare: Option, ) -> Box<'a, Function<'a>> { diff --git a/crates/oxc_isolated_declarations/src/module.rs b/crates/oxc_isolated_declarations/src/module.rs index 1339999462e82..75462ef1a8b27 100644 --- a/crates/oxc_isolated_declarations/src/module.rs +++ b/crates/oxc_isolated_declarations/src/module.rs @@ -21,7 +21,7 @@ impl<'a> IsolatedDeclarations<'a> { )) } - pub(crate) fn create_unique_name(&mut self, name: &str) -> Atom<'a> { + pub(crate) fn create_unique_name(&self, name: &str) -> Atom<'a> { let mut binding = self.ast.atom(name); let mut i = 1; while self.scope.has_reference(&binding) { @@ -32,7 +32,7 @@ impl<'a> IsolatedDeclarations<'a> { } pub(crate) fn transform_export_default_declaration( - &mut self, + &self, decl: &ExportDefaultDeclaration<'a>, ) -> Option<(Option>, Statement<'a>)> { let declaration = match &decl.declaration { @@ -69,7 +69,7 @@ impl<'a> IsolatedDeclarations<'a> { } fn transform_export_expression( - &mut self, + &self, expr: &Expression<'a>, ) -> Option<(Option>, Expression<'a>)> { if matches!(expr, Expression::Identifier(_)) { @@ -102,7 +102,7 @@ impl<'a> IsolatedDeclarations<'a> { } pub(crate) fn transform_ts_export_assignment( - &mut self, + &self, decl: &TSExportAssignment<'a>, ) -> Option<(Option>, Statement<'a>)> { self.transform_export_expression(&decl.expression).map(|(var_decl, expr)| { diff --git a/crates/oxc_minifier/src/lib.rs b/crates/oxc_minifier/src/lib.rs index 3068e77b95781..cf89773a93223 100644 --- a/crates/oxc_minifier/src/lib.rs +++ b/crates/oxc_minifier/src/lib.rs @@ -1,5 +1,7 @@ //! ECMAScript Minifier +#![allow(clippy::needless_pass_by_ref_mut)] + mod compressor; mod ctx; mod keep_var; diff --git a/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs b/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs index d8663ad1c3364..ff474ab166c47 100644 --- a/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs +++ b/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs @@ -1104,7 +1104,7 @@ impl<'a> LatePeepholeOptimizations { DELIMITERS.into_iter().find(|&delimiter| strings.clone().all(|s| !s.contains(delimiter))) } - pub fn substitute_catch_clause(&mut self, catch: &mut CatchClause<'a>, ctx: Ctx<'a, '_>) { + pub fn substitute_catch_clause(&self, catch: &mut CatchClause<'a>, ctx: Ctx<'a, '_>) { if self.target >= ESTarget::ES2019 { if let Some(param) = &catch.param { if let BindingPatternKind::BindingIdentifier(ident) = ¶m.pattern.kind { diff --git a/crates/oxc_parser/src/cursor.rs b/crates/oxc_parser/src/cursor.rs index 66d5bf0de31d4..fd207c6590942 100644 --- a/crates/oxc_parser/src/cursor.rs +++ b/crates/oxc_parser/src/cursor.rs @@ -188,7 +188,7 @@ impl<'a> ParserImpl<'a> { } /// # Errors - pub(crate) fn expect_without_advance(&mut self, kind: Kind) -> Result<()> { + pub(crate) fn expect_without_advance(&self, kind: Kind) -> Result<()> { if !self.at(kind) { let range = self.cur_token().span(); return Err(diagnostics::expect_token(kind.to_str(), self.cur_kind().to_str(), range)); diff --git a/crates/oxc_parser/src/js/expression.rs b/crates/oxc_parser/src/js/expression.rs index 99795601852e4..7d60a3eab74f9 100644 --- a/crates/oxc_parser/src/js/expression.rs +++ b/crates/oxc_parser/src/js/expression.rs @@ -437,7 +437,7 @@ impl<'a> ParserImpl<'a> { /// Elision : /// , /// Elision , - pub(crate) fn parse_elision(&mut self) -> ArrayExpressionElement<'a> { + pub(crate) fn parse_elision(&self) -> ArrayExpressionElement<'a> { self.ast.array_expression_element_elision(self.cur_token().span()) } diff --git a/crates/oxc_parser/src/modifiers.rs b/crates/oxc_parser/src/modifiers.rs index 972fa512e9cb8..3cc31c8d42349 100644 --- a/crates/oxc_parser/src/modifiers.rs +++ b/crates/oxc_parser/src/modifiers.rs @@ -507,7 +507,7 @@ impl<'a> ParserImpl<'a> { self.can_follow_export_modifier() } - fn can_follow_export_modifier(&mut self) -> bool { + fn can_follow_export_modifier(&self) -> bool { let kind = self.cur_kind(); kind == Kind::At && kind != Kind::Star @@ -516,7 +516,7 @@ impl<'a> ParserImpl<'a> { && self.can_follow_modifier() } - fn can_follow_modifier(&mut self) -> bool { + fn can_follow_modifier(&self) -> bool { match self.cur_kind() { Kind::PrivateIdentifier | Kind::LBrack | Kind::LCurly | Kind::Star | Kind::Dot3 => true, kind => kind.is_identifier_or_keyword(), diff --git a/crates/oxc_parser/src/ts/types.rs b/crates/oxc_parser/src/ts/types.rs index 3682196866112..f21e08f95516c 100644 --- a/crates/oxc_parser/src/ts/types.rs +++ b/crates/oxc_parser/src/ts/types.rs @@ -1367,7 +1367,7 @@ impl<'a> ParserImpl<'a> { )) } - fn is_binary_operator(&mut self) -> bool { + fn is_binary_operator(&self) -> bool { if self.ctx.has_in() && self.at(Kind::In) { return false; } diff --git a/crates/oxc_prettier/src/comments/print.rs b/crates/oxc_prettier/src/comments/print.rs index 317f70c7d1c11..2219b91b5c49a 100644 --- a/crates/oxc_prettier/src/comments/print.rs +++ b/crates/oxc_prettier/src/comments/print.rs @@ -8,7 +8,7 @@ use super::{CommentFlags, DanglingCommentsPrintOptions}; impl<'a> Prettier<'a> { #[must_use] pub(crate) fn print_comments( - &mut self, + &self, before: Option>, doc: Doc<'a>, after: Option>, @@ -27,28 +27,28 @@ impl<'a> Prettier<'a> { doc } - pub(crate) fn has_comment(&mut self, _span: Span, _flags: CommentFlags) -> bool { + pub(crate) fn has_comment(&self, _span: Span, _flags: CommentFlags) -> bool { false } #[must_use] - pub(crate) fn print_leading_comments(&mut self, _span: Span) -> Option> { + pub(crate) fn print_leading_comments(&self, _span: Span) -> Option> { None } #[must_use] - pub(crate) fn print_trailing_comments(&mut self, _span: Span) -> Option> { + pub(crate) fn print_trailing_comments(&self, _span: Span) -> Option> { None } #[must_use] - pub(crate) fn print_inner_comment(&mut self, _span: Span) -> Vec<'a, Doc<'a>> { + pub(crate) fn print_inner_comment(&self, _span: Span) -> Vec<'a, Doc<'a>> { Vec::new_in(self.allocator) } #[must_use] pub(crate) fn print_dangling_comments( - &mut self, + &self, _span: Span, _dangling_options: Option<&DanglingCommentsPrintOptions>, ) -> Option> { diff --git a/crates/oxc_prettier/src/format/print/arrow_function.rs b/crates/oxc_prettier/src/format/print/arrow_function.rs index b7891eb12f090..aba6cfa898503 100644 --- a/crates/oxc_prettier/src/format/print/arrow_function.rs +++ b/crates/oxc_prettier/src/format/print/arrow_function.rs @@ -43,7 +43,7 @@ pub fn print_arrow_function<'a>( } pub fn should_print_params_without_parens<'a>( - p: &mut Prettier<'a>, + p: &Prettier<'a>, expr: &ArrowFunctionExpression<'a>, ) -> bool { match p.options.arrow_parens { diff --git a/crates/oxc_prettier/src/format/print/class.rs b/crates/oxc_prettier/src/format/print/class.rs index da3a8518e30a6..9cac541176ab8 100644 --- a/crates/oxc_prettier/src/format/print/class.rs +++ b/crates/oxc_prettier/src/format/print/class.rs @@ -229,7 +229,7 @@ impl<'a> ClassPropertyLike<'a, '_> { } } - fn format_accessibility(&self, p: &mut Prettier<'a>) -> Option> { + fn format_accessibility(&self, p: &Prettier<'a>) -> Option> { match self { ClassPropertyLike::AccessorProperty(def) => { def.accessibility.map(|v| text!(v.as_str())) diff --git a/crates/oxc_prettier/src/format/print/function_parameters.rs b/crates/oxc_prettier/src/format/print/function_parameters.rs index ddcd47cbb1a19..23f8626329430 100644 --- a/crates/oxc_prettier/src/format/print/function_parameters.rs +++ b/crates/oxc_prettier/src/format/print/function_parameters.rs @@ -7,7 +7,7 @@ use crate::{ }; pub fn should_hug_the_only_function_parameter( - p: &mut Prettier<'_>, + p: &Prettier<'_>, params: &FormalParameters<'_>, ) -> bool { if params.parameters_count() != 1 { diff --git a/crates/oxc_prettier/src/format/print/object.rs b/crates/oxc_prettier/src/format/print/object.rs index 9ed082668fbf9..0712d5375f98f 100644 --- a/crates/oxc_prettier/src/format/print/object.rs +++ b/crates/oxc_prettier/src/format/print/object.rs @@ -300,7 +300,7 @@ pub fn print_object<'a>(p: &mut Prettier<'a>, obj: &ObjectLike<'a, '_>) -> Doc<' group!(p, parts, should_break, None) } -fn should_hug_the_only_parameter(p: &mut Prettier<'_>, kind: AstKind<'_>) -> bool { +fn should_hug_the_only_parameter(p: &Prettier<'_>, kind: AstKind<'_>) -> bool { match kind { AstKind::FormalParameters(params) => { function_parameters::should_hug_the_only_function_parameter(p, params) diff --git a/crates/oxc_regular_expression/src/parser/reader/string_literal_parser/parser_impl.rs b/crates/oxc_regular_expression/src/parser/reader/string_literal_parser/parser_impl.rs index 94e104cd3d609..2eb3750f2c5eb 100644 --- a/crates/oxc_regular_expression/src/parser/reader/string_literal_parser/parser_impl.rs +++ b/crates/oxc_regular_expression/src/parser/reader/string_literal_parser/parser_impl.rs @@ -517,16 +517,16 @@ impl Parser { self.offset } - fn peek_nth(&mut self, n: usize) -> Option { + fn peek_nth(&self, n: usize) -> Option { let nth = self.index + n; self.chars.get(nth).copied() } - fn peek(&mut self) -> Option { + fn peek(&self) -> Option { self.peek_nth(0) } - fn peek2(&mut self) -> Option { + fn peek2(&self) -> Option { self.peek_nth(1) } } diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index f4fb1d86dde22..57755a3345870 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -5,6 +5,8 @@ //! * //! * +#![allow(clippy::needless_pass_by_ref_mut)] + use std::path::Path; use oxc_allocator::{Allocator, Vec as ArenaVec}; diff --git a/crates/oxc_traverse/src/context/scoping.rs b/crates/oxc_traverse/src/context/scoping.rs index a11a7a8e6e9c2..708fc092a1d65 100644 --- a/crates/oxc_traverse/src/context/scoping.rs +++ b/crates/oxc_traverse/src/context/scoping.rs @@ -425,7 +425,7 @@ impl TraverseScoping { /// /// Once this set is created, generating a UID is a relatively quick operation, rather than /// iterating over all symbols and unresolved references every time generate a UID. - fn get_uid_names(&mut self) -> FxHashSet { + fn get_uid_names(&self) -> FxHashSet { self.scopes .root_unresolved_references() .keys() diff --git a/crates/oxc_wasm/src/lib.rs b/crates/oxc_wasm/src/lib.rs index 2c69f2ba0ca32..5494fbedd4d22 100644 --- a/crates/oxc_wasm/src/lib.rs +++ b/crates/oxc_wasm/src/lib.rs @@ -311,7 +311,7 @@ impl Oxc { } fn run_linter( - &mut self, + &self, run_options: &OxcRunOptions, path: &Path, program: &Program, diff --git a/tasks/ast_tools/src/parse/parse.rs b/tasks/ast_tools/src/parse/parse.rs index d64f8d9f7f24e..c7cdb8a3cd214 100644 --- a/tasks/ast_tools/src/parse/parse.rs +++ b/tasks/ast_tools/src/parse/parse.rs @@ -167,7 +167,7 @@ impl<'c> Parser<'c> { } /// Get type name for a [`TypeId`]. - fn type_name(&mut self, type_id: TypeId) -> &str { + fn type_name(&self, type_id: TypeId) -> &str { &self.type_names[type_id.index()] } @@ -516,7 +516,7 @@ impl<'c> Parser<'c> { /// /// [`Derive`]: crate::Derive /// [`Generator`]: crate::Generator - fn parse_type_attrs(&mut self, type_def: &mut TypeDef, attrs: &[Attribute]) { + fn parse_type_attrs(&self, type_def: &mut TypeDef, attrs: &[Attribute]) { for attr in attrs { if !matches!(attr.style, AttrStyle::Outer) { continue; @@ -600,7 +600,7 @@ impl<'c> Parser<'c> { /// /// [`Derive`]: crate::Derive /// [`Generator`]: crate::Generator - fn parse_ast_attr(&mut self, type_def: &mut TypeDef, attr: &Attribute) { + fn parse_ast_attr(&self, type_def: &mut TypeDef, attr: &Attribute) { let parts = match &attr.meta { Meta::Path(_) => return, Meta::List(meta_list) => meta_list @@ -687,7 +687,7 @@ impl<'c> Parser<'c> { } /// Parse [`Skeleton`] to yield a [`MetaType`]. - fn parse_meta_type(&mut self, meta_id: MetaId, skeleton: Skeleton) -> MetaType { + fn parse_meta_type(&self, meta_id: MetaId, skeleton: Skeleton) -> MetaType { let (type_name, file_id, attrs) = match skeleton { Skeleton::Struct(skeleton) => (skeleton.name, skeleton.file_id, skeleton.item.attrs), Skeleton::Enum(skeleton) => (skeleton.name, skeleton.file_id, skeleton.item.attrs), diff --git a/tasks/transform_conformance/src/test_case.rs b/tasks/transform_conformance/src/test_case.rs index 06aad91f5edfc..69ef7c67bb866 100644 --- a/tasks/transform_conformance/src/test_case.rs +++ b/tasks/transform_conformance/src/test_case.rs @@ -389,7 +389,7 @@ impl TestCase { } } - fn test_exec(&mut self, filtered: bool) { + fn test_exec(&self, filtered: bool) { if filtered { println!("input_path: {:?}", &self.path); println!("Input:\n{}\n", fs::read_to_string(&self.path).unwrap());