swc-project/swc · error
generic parameter other than type
Error message
generic parameter other than type
What it means
`quote!` from swc_ecma_quote_macros reads the type written after `as` (e.g. `quote!("a + b" as Box<Expr>)`) to decide how to parse and wrap the fragment. `extract_generic` only accepts an angle-bracketed argument list whose first argument is a plain type; any other generic-argument kind (lifetime or const argument) hits `unimplemented!("generic parameter other than type")` at compile time.
Source
Thrown at crates/swc_ecma_quote_macros/src/ret_type.rs:91
let mut parser = Parser::new_from(lexer);
op(&mut parser)
.map_err(|err| anyhow!("{err:?}"))
.with_context(|| format!("failed to parse input as `{}`", type_name::<T>()))
.map(|val| BoxWrapper(Box::new(val)))
}
fn extract_generic<'a>(name: &str, ty: &'a Type) -> Option<&'a Type> {
if let Type::Path(p) = ty {
let last = p.path.segments.last().unwrap();
if !last.arguments.is_empty() && last.ident == name {
match &last.arguments {
PathArguments::AngleBracketed(tps) => {
let arg = tps.args.first().unwrap();
match arg {
GenericArgument::Type(arg) => return Some(arg),
_ => unimplemented!("generic parameter other than type"),
}
}
_ => unimplemented!("Box() -> T or Box without a type parameter"),
}
}
}
None
}
View on GitHub (pinned to d7d7434666)
Solutions
- Use the supported forms: `as Box<Expr>` or `as Option<Expr>` with a plain type argument
- Wrap a parameterized inner type in a type alias so the outer argument stays a plain type
Example fix
// before
let node = quote!("self.field" as Box<'a>);
// after
let node = quote!("self.field" as Box<Expr>); Defensive patterns
Strategy: validation
Prevention
- Restrict quote! `as` types to `Box<T>` / `Option<T>` with a single plain type argument
- If another macro generates quote! calls, snapshot-test the emitted tokens with cargo-expand
When it happens
Trigger: Write a quote invocation whose wrapper type's first generic argument is not a type — e.g. `Box<'a>` or a const-generic parameter — instead of the supported `Box<T>` / `Option<T>` shapes.
Common situations: Writing custom visitor or matcher macros on top of swc's quote macros; refactors that move lifetimes into the wrapper position; meta-macros generating quote calls with spliced tokens.
Related errors
- Box() -> T or Box without a type parameter
- Fast-path injection for Fold / VisitMut where pattern is not
- Unknown visitor type: {:?}
- union
- {err:?}
AI-assisted analysis of swc-project/swc@d7d7434666 (2026-08-16).
Data as JSON: /api/errors/7485127efb4eed85.
Report an issue: GitHub.