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

  1. Always spell the wrapper as `Box<T>` or `Option<T>` with angle brackets
  2. When generating quote! calls from a meta-macro, emit only the two supported shapes
  3. 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

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


AI-assisted analysis of swc-project/swc@d7d7434666 (2026-08-16). Data as JSON: /api/errors/c8908ef5027b65bb. Report an issue: GitHub.