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

extract_generic requires the named generic (Box) in the quote macro's expected return type to carry exactly one type parameter; a bare `Box` or empty angle brackets provide no argument to extract, so the macro aborts at compile time.

Solutions

  1. Write the return type with an explicit type parameter, e.g. Box<Expr>
  2. Return None from extract_generic and emit a friendly compile_error! at the call site
  3. Reject the malformed type earlier in parse_input_type with a clearer message
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/swc_ecma_quote_macros/src/ret_type.rs:94 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/c8908ef5027b65bb. Report an issue: GitHub.

Appendix: 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 5176682b65)