swc-project/swc · error
Fast-path injection for Fold / VisitMut where pattern is not
Error message
Fast-path injection for Fold / VisitMut where pattern is not an ident
What it means
`#[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.
Source
Thrown at crates/swc_ecma_transforms_macros/src/fast.rs:106
let ty_arg = m
.sig
.inputs
.last()
.expect("method of Fold / VisitMut must accept two parameters");
let ty_arg = match ty_arg {
FnArg::Receiver(_) => unreachable!(),
FnArg::Typed(ty) => ty,
};
if m.sig.ident == "visit_mut_ident" || m.sig.ident == "fold_ident" {
return m;
}
if m.block.stmts.is_empty() {
return m;
}
let arg = match &*ty_arg.pat {
Pat::Ident(i) => &i.ident,
_ => unimplemented!(
"Fast-path injection for Fold / VisitMut where pattern is not an ident"
),
};
let checker = &self.handler;
let fast_path = match self.mode {
Mode::Fold => parse_quote!(
if !swc_ecma_transforms_base::perf::should_work::<#checker, _>(&#arg) {
return #arg;
}
),
Mode::VisitMut => parse_quote!(
if !swc_ecma_transforms_base::perf::should_work::<#checker, _>(&*#arg) {
return;
}
),
};View on GitHub (pinned to d7d7434666)
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
Example fix
// before
#[fast_path]
impl VisitMut for V {
fn visit_mut_expr(&mut self, _: &mut Expr) { /* work */ }
}
// after
#[fast_path]
impl VisitMut for V {
fn visit_mut_expr(&mut self, n: &mut Expr) { /* work */ }
} Defensive patterns
Strategy: validation
Prevention
- 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
When it happens
Trigger: 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 */ }`.
Common situations: Hand-written or generated visitors that discard argument names; cleanup passes replacing unused idents with `_`; refactoring visitor methods after the attribute was added.
Related errors
- Unknown visitor type: {:?}
- generic parameter other than type
- Box() -> T or Box without a type parameter
- union
- Unknown suffix `{}`
AI-assisted analysis of swc-project/swc@d7d7434666 (2026-08-16).
Data as JSON: /api/errors/b3cf02dd4e4ac6e8.
Report an issue: GitHub.