swc-project/swc · error
generic parameter other than type
Error message
generic parameter other than type
What it means
The quote!/quote_module! proc-macro helper extract_generic only supports generic arguments that are types; when the named generic (e.g. Box<T>) has an angle-bracketed argument that is a lifetime or const, it aborts. This is a compile-time failure of code using swc_ecma_quote_macros with a non-type generic parameter in its expected return type.
Solutions
- Pass a plain type parameter, e.g. Box<Expr>, to the quote macro's expected type
- Extend extract_generic to handle lifetime/const generic arguments
- Restructure the macro invocation so the generic argument is a type
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/swc_ecma_quote_macros/src/ret_type.rs:91 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/7485127efb4eed85.
Report an issue: GitHub.
Appendix: 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 5176682b65)