{"record":{"id":"c8908ef5027b65bb","repo":"swc-project/swc","slug":"box-t-or-box-without-a-type-parameter","errorCode":null,"errorMessage":"Box() -> T or Box without a type parameter","messagePattern":"Box\\(\\) -> T or Box without a type parameter","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_quote_macros/src/ret_type.rs","lineNumber":94,"sourceCode":"        .with_context(|| format!(\"failed to parse input as `{}`\", type_name::<T>()))\n        .map(|val| BoxWrapper(Box::new(val)))\n}\n\nfn extract_generic<'a>(name: &str, ty: &'a Type) -> Option<&'a Type> {\n    if let Type::Path(p) = ty {\n        let last = p.path.segments.last().unwrap();\n\n        if !last.arguments.is_empty() && last.ident == name {\n            match &last.arguments {\n                PathArguments::AngleBracketed(tps) => {\n                    let arg = tps.args.first().unwrap();\n\n                    match arg {\n                        GenericArgument::Type(arg) => return Some(arg),\n                        _ => unimplemented!(\"generic parameter other than type\"),\n                    }\n                }\n                _ => unimplemented!(\"Box() -> T or Box without a type parameter\"),\n            }\n        }\n    }\n\n    None\n}\n","sourceCodeStart":76,"sourceCodeEnd":101,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/crates/swc_ecma_quote_macros/src/ret_type.rs#L76-L101","documentation":"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.","triggerScenarios":"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'.","commonSituations":"Almost unreachable with well-formed Rust types; appears when quote! calls are generated by another macro and the token splicing produces a malformed type.","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"],"exampleFix":"// before\nlet node = quote!(\"a\" as Option() -> Expr);\n\n// after\nlet node = quote!(\"a\" as Option<Expr>);","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["macro","quote","compile-time","generics"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}