{"record":{"id":"b3cf02dd4e4ac6e8","repo":"swc-project/swc","slug":"fast-path-injection-for-fold-visitmut-where-patt","errorCode":null,"errorMessage":"Fast-path injection for Fold / VisitMut where pattern is not an ident","messagePattern":"Fast-path injection for Fold / VisitMut where pattern is not an ident","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_macros/src/fast.rs","lineNumber":106,"sourceCode":"        let ty_arg = m\n            .sig\n            .inputs\n            .last()\n            .expect(\"method of Fold / VisitMut must accept two parameters\");\n        let ty_arg = match ty_arg {\n            FnArg::Receiver(_) => unreachable!(),\n            FnArg::Typed(ty) => ty,\n        };\n        if m.sig.ident == \"visit_mut_ident\" || m.sig.ident == \"fold_ident\" {\n            return m;\n        }\n        if m.block.stmts.is_empty() {\n            return m;\n        }\n\n        let arg = match &*ty_arg.pat {\n            Pat::Ident(i) => &i.ident,\n            _ => unimplemented!(\n                \"Fast-path injection for Fold / VisitMut where pattern is not an ident\"\n            ),\n        };\n\n        let checker = &self.handler;\n\n        let fast_path = match self.mode {\n            Mode::Fold => parse_quote!(\n                if !swc_ecma_transforms_base::perf::should_work::<#checker, _>(&#arg) {\n                    return #arg;\n                }\n            ),\n            Mode::VisitMut => parse_quote!(\n                if !swc_ecma_transforms_base::perf::should_work::<#checker, _>(&*#arg) {\n                    return;\n                }\n            ),\n        };","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/crates/swc_ecma_transforms_macros/src/fast.rs#L88-L124","documentation":"`#[fast_path]` injects an early `should_work` bail into each method of a Fold/VisitMut impl. To reference the node in the generated check, the macro needs the method's node argument bound by a plain identifier pattern; any other pattern (`_`, `ref n`, destructuring) on a non-empty method body hits `unimplemented!(\"Fast-path injection ... not an ident\")` at macro expansion time.","triggerScenarios":"Annotate an impl with `#[fast_path]` where a method binds its node argument without an ident, e.g. `fn visit_mut_expr(&mut self, _: &mut Expr) { /* non-empty */ }`.","commonSituations":"Hand-written or generated visitors that discard argument names; cleanup passes replacing unused idents with `_`; refactoring visitor methods after the attribute was added.","solutions":["Name the argument (`n: &mut Expr`) — the injected check references it","Keep the method body empty; empty-bodied methods are skipped by the macro","Drop `#[fast_path]` from that impl if renaming is unacceptable"],"exampleFix":"// before\n#[fast_path]\nimpl VisitMut for V {\n    fn visit_mut_expr(&mut self, _: &mut Expr) { /* work */ }\n}\n\n// after\n#[fast_path]\nimpl VisitMut for V {\n    fn visit_mut_expr(&mut self, n: &mut Expr) { /* work */ }\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["In `#[fast_path]`-annotated impls, always bind the node argument with a plain ident (`n: &mut Expr`)","Avoid lint passes that rename unused visitor args to `_` inside fast_path impls"],"tags":["macro","fast-path","visitor","compile-time"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}