{"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/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_macros/src/fast.rs#L88-L124","documentation":"Compile-time panic from the #[fast_path] proc macro (swc_ecma_transforms_macros). When injecting the should_work fast-path check into a Fold/VisitMut impl method, the macro must reference the node argument by name in generated code (e.g. should_work::<C,_>(&arg)), so the parameter has to be a simple identifier binding. If the annotated method declares the node parameter with any other pattern (wildcard, tuple, ref-pattern), macro expansion aborts with unimplemented!.","triggerScenarios":"Applying #[fast_path] to an impl Fold/VisitMut block whose method (typically fold_ident/visit_mut_ident) uses `fn visit_mut_ident(&mut self, _: &mut Ident)`, a tuple pattern, or a ref/destructuring pattern instead of a plain `n: &mut Ident` binding.","commonSituations":"Writing a custom swc visitor crate and reformatting or auto-completing method signatures until the parameter becomes `_` or a non-ident pattern; copying a #[fast_path] example into code that uses wildcard parameter names.","solutions":["Change the node parameter to a plain identifier binding, e.g. `fn visit_mut_ident(&mut self, n: &mut Ident)`","Never use `_`, tuple, or ref patterns for the node parameter of methods in a #[fast_path]-annotated impl","If the signature must stay as-is, remove the #[fast_path] attribute from that impl"],"exampleFix":"// before\n#[fast_path]\nimpl VisitMut for MyVisitor {\n    fn visit_mut_ident(&mut self, _: &mut Ident) { /* ... */ }\n}\n\n// after\n#[fast_path]\nimpl VisitMut for MyVisitor {\n    fn visit_mut_ident(&mut self, n: &mut Ident) { /* ... */ }\n}","handlingStrategy":"validation","validationCode":"// Before shipping, lint the annotated impl: every method parameter\n// in a #[fast_path] impl must be a plain ident binding.\n// Quick manual check (no runtime API exists — this is compile time):\n// rg -n '#[fast_path]' -A 8 | grep -E 'fn .+\\(&mut self, (_|\\(|&)'\n// Any hit is a candidate for this panic.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never name visitor node parameters `_`; always bind them (n: &mut Ident)","Keep #[fast_path] impls formatted exactly like the upstream examples","Run cargo check immediately after adding proc-macro attributes so macro panics surface at build time, not in CI later"],"tags":["proc-macro","swc","rust","compile-time","visitor"],"backgroundTag":"proc-macro-unsupported-input","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}