swc-project/swc · error
Box() -> T or Box without a type parameter
Error message
Box() -> T or Box without a type parameter
What it means
The same `extract_generic` path in the quote macros: when the wrapper segment has path arguments that are not `AngleBracketed` — parenthesized `Fn() -> T` style — or the first argument is not a type, the macro panics with `unimplemented!("Box() -> T or Box without a type parameter")`. Only `Box<T>` / `Option<T>` with angle brackets are understood.
Source
Thrown at crates/swc_ecma_quote_macros/src/ret_type.rs:94
.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
- Always spell the wrapper as `Box<T>` or `Option<T>` with angle brackets
- When generating quote! calls from a meta-macro, emit only the two supported shapes
- Check the macro-generated tokens (e.g. with cargo-expand) to find where the malformed type comes from
Example fix
// before
let node = quote!("a" as Option() -> Expr);
// after
let node = quote!("a" as Option<Expr>); Defensive patterns
Strategy: validation
Prevention
- Always write the wrapper with angle brackets: `Box<Expr>`, `Option<Pat>`
- Treat 'unknown quote type' errors as a signal to recheck the `as` type spelling before they become panics
When it happens
Trigger: Write `quote!("..." as Option() -> Expr)` or any wrapper spelled with parenthesized path arguments. A bare `as Box` without `<T>` is not this panic — it fails later as 'Unknown quote type'.
Common situations: Almost unreachable with well-formed Rust types; appears when quote! calls are generated by another macro and the token splicing produces a malformed type.
Related errors
- generic parameter other than type
- 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/c8908ef5027b65bb.
Report an issue: GitHub.