{"record":{"id":"b817bb6e4ee364d4","repo":"swc-project/swc","slug":"var-type-should-be-one-of-ident-expr-pat-got","errorCode":null,"errorMessage":"Var type should be one of: Ident, Expr, Pat; got {:?}","messagePattern":"Var type should be one of: Ident, Expr, Pat; got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_quote_macros/src/ctxt.rs","lineNumber":115,"sourceCode":"                path:\n                    syn::Path {\n                        leading_colon: None,\n                        segments,\n                    },\n            })) => {\n                let segment = segments.first().unwrap();\n                match segment.ident.to_string().as_str() {\n                    \"Ident\" => VarPos::Ident,\n                    \"Expr\" => VarPos::Expr,\n                    \"Pat\" => VarPos::Pat,\n                    \"Str\" => VarPos::Str,\n                    \"AssignTarget\" => VarPos::AssignTarget,\n                    _ => panic!(\"Invalid type: {:?}\", segment.ident),\n                }\n            }\n            None => VarPos::Ident,\n            _ => {\n                panic!(\n                    \"Var type should be one of: Ident, Expr, Pat; got {:?}\",\n                    var.ty\n                )\n            }\n        };\n\n        let var_ident = syn::Ident::new(&format!(\"quote_var_{ident}\"), ident.span());\n\n        let old = init_map.entry(pos).or_default().insert(\n            ident_str.clone(),\n            VarData {\n                pos,\n                is_counting: true,\n                clone: Default::default(),\n                ident: var_ident.clone(),\n            },\n        );\n","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_quote_macros/src/ctxt.rs#L97-L133","documentation":"The quote! macro type annotation must be a bare single-segment type path. If the annotation is a reference (&Expr), generic (Vec<Expr>), tuple, fully-qualified path, or any non-path type, the VarPos extraction fails and panics with 'Var type should be one of: Ident, Expr, Pat; got {:?}' showing the full syn::Type.","triggerScenarios":"Writing quote!(x as &Expr), quote!(x as Option<Expr>), or quote!(x as syn::Ident) inside a macro built on swc_ecma_quote_macros.","commonSituations":"Rust developers naturally writing reference or generic types when hand-rolling code generation, porting from other quote implementations (syn's quote! accepts arbitrary expressions), IDE autocompleting qualified paths.","solutions":["Use a bare path: Expr, Ident, Pat, Str, or AssignTarget without &, Option<>, or module prefixes","Pass owned values; the macro clones/counts interpolations itself","If you need a String interpolation, use the Str annotation instead of &str"],"exampleFix":"// before\nquote!(x as &Expr; x;);\n\n// after\nquote!(x as Expr; x;);","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write annotations as bare single-segment paths; never &T, Option<T>, or qualified paths","Do not assume syn-style quote! rules carry over to swc_ecma_quote_macros","Keep a cheat-sheet comment listing the five supported annotations near your macro code"],"tags":["proc-macro","quote","compile-time","annotation","type-syntax"],"backgroundTag":"invalid-macro-type-annotation","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}