{"record":{"id":"ed277823fbfe7bd4","repo":"swc-project/swc","slug":"failed-to-parse-input-as-a-deriveinput","errorCode":null,"errorMessage":"failed to parse input as a DeriveInput","messagePattern":"failed to parse input as a DeriveInput","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ast_node/src/lib.rs","lineNumber":99,"sourceCode":"/// enum Expr {\n///   #[tag(\"StringLiteral\")]\n///   #[tag(\"NumericLiteral\")]\n///   #[tag(\"BooleanLiteral\")]\n///   Lit(Lit),\n/// }\n/// ```\n///\n/// so the deserializer can decide which variant to use.\n///\n///\n/// `#[tag]` also supports wildcard like `#[tag(\"*\")]`. You can use this if\n/// there are two many variants.\n#[proc_macro_attribute]\npub fn ast_serde(\n    args: proc_macro::TokenStream,\n    input: proc_macro::TokenStream,\n) -> proc_macro::TokenStream {\n    let input: DeriveInput = parse(input).expect(\"failed to parse input as a DeriveInput\");\n\n    // we should use call_site\n    let mut item = TokenStream::new();\n    match input.data {\n        Data::Enum(..) => {\n            if !args.is_empty() {\n                panic!(\"#[ast_serde] on enum does not accept any argument\")\n            }\n\n            item.extend(quote!(\n                #[derive(::serde::Serialize, ::swc_common::DeserializeEnum)]\n                #[serde(untagged)]\n                #input\n            ));\n        }\n        _ => {\n            let args: Option<ast_node_macro::Args> = if args.is_empty() {\n                None","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/ast_node/src/lib.rs#L81-L117","documentation":"The #[ast_serde] proc-macro attribute received a token stream that syn could not parse as a DeriveInput. It fires at macro-expansion time when the attribute is applied to something that is not a struct, enum, or union definition (e.g. a fn, mod, or free statement), or when the item's tokens are otherwise malformed, so the macro cannot inspect the type's data to emit serde impls.","triggerScenarios":"Thrown at crates/ast_node/src/lib.rs:99 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Apply #[ast_serde] only to struct, enum, or union definitions","Check that the annotated item is complete and syntactically valid","If the item is generated by another macro, verify the generated tokens form a valid DeriveInput"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}