swc-project/swc · error
Unknown visitor type: {:?}
Error message
Unknown visitor type: {:?} What it means
`#[parallel]` generates parallel visit helpers by inspecting the implemented trait path: only `Fold` and `VisitMut` are recognized (`p.is_ident("Fold")` / `VisitMut`); any other trait panics with `unimplemented!("Unknown visitor type: ...")`. An inherent impl with no trait panics even earlier on `trait_.as_ref().unwrap()`.
Source
Thrown at crates/swc_ecma_transforms_macros/src/parallel.rs:16
#![allow(non_snake_case)]
use proc_macro2::{Span, TokenStream};
use syn::{parse_quote, Expr, Ident, ImplItem, ImplItemFn, ItemImpl, Meta, Type};
use crate::common::Mode;
pub fn expand(attr: TokenStream, mut item: ItemImpl) -> ItemImpl {
let mode = {
let p = &item.trait_.as_ref().unwrap().1;
if p.is_ident("Fold") {
Mode::Fold
} else if p.is_ident("VisitMut") {
Mode::VisitMut
} else {
unimplemented!("Unknown visitor type: {:?}", p)
}
};
let meta = if attr.is_empty() {
None
} else {
Some(syn::parse2::<Meta>(attr).expect("failed to parse meta"))
};
let explode = meta
.as_ref()
.map(|v| v.path().is_ident("explode"))
.unwrap_or(false);
item.items.push(ImplItem::Fn(make_par_visit_method(
mode,
"module_items",
explode,
)));
item.itemsView on GitHub (pinned to d7d7434666)
Solutions
- Remove `#[parallel]` from impl blocks of traits other than Fold/VisitMut
- Keep the attribute strictly on the visitor impl blocks it was designed for
Example fix
// before
#[parallel]
impl MyPass for Visitor { ... }
// after
impl MyPass for Visitor { ... } Defensive patterns
Strategy: validation
Prevention
- Apply `#[parallel]` only to `impl Fold` / `impl VisitMut` blocks
- When refactoring a visitor into another trait, delete the attribute in the same commit
When it happens
Trigger: Apply `#[parallel]` to `impl MyTrait for X { ... }` or to an inherent `impl X { ... }` block.
Common situations: Attribute applied too broadly via copied boilerplate or editor macro expansion; refactoring a visitor impl into another trait without removing the attribute.
Related errors
- Fast-path injection for Fold / VisitMut where pattern is not
- generic parameter other than type
- Box() -> T or Box without a type parameter
- Unknown suffix `{}`
- union
AI-assisted analysis of swc-project/swc@d7d7434666 (2026-08-16).
Data as JSON: /api/errors/12320d91354c58da.
Report an issue: GitHub.