{"record":{"id":"0b1fc399f52c306c","repo":"tracel-ai/burn","slug":"only-struct-can-be-derived","errorCode":null,"errorMessage":"Only struct can be derived","messagePattern":"Only struct can be derived","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-derive/src/module/codegen_struct.rs","lineNumber":340,"sourceCode":"    generics: &mut ModuleGenerics,\n) -> syn::Result<Vec<ModuleField>> {\n    let mut fields = Vec::new();\n    let mut module_generics = HashSet::new();\n    let mut skip_generics = HashSet::new();\n\n    match &ast.data {\n        syn::Data::Struct(struct_data) => {\n            for field in struct_data.fields.iter() {\n                let field_type = parse_module_field_type(field, generics)?;\n                if field_type.is_module {\n                    module_generics.extend(field_type.generic_idents.iter().cloned());\n                } else if matches!(field_type.attr, Some(ModuleFieldAttribute::Skip)) {\n                    skip_generics.extend(field_type.generic_idents.iter().cloned());\n                }\n                fields.push(ModuleField::new(field.clone(), field_type));\n            }\n        }\n        syn::Data::Enum(_) => panic!(\"Only struct can be derived\"),\n        syn::Data::Union(_) => panic!(\"Only struct can be derived\"),\n    };\n\n    for ident in module_generics.intersection(&skip_generics) {\n        if let Some(param) = ast.generics.params.iter().find_map(|p| match p {\n            syn::GenericParam::Type(tp) if tp.ident == *ident => Some(tp),\n            _ => None,\n        }) {\n            return Err(syn::Error::new(\n                param.ident.span(),\n                format!(\n                    \"Generic type `{ident}` should not be used on both a module field and a skipped field. \\\n                     Consider removing `#[module(skip)]` or using a different type for one of the fields.\",\n                ),\n            ));\n        }\n    }\n","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-derive/src/module/codegen_struct.rs#L322-L358","documentation":"Derive-macro input guard in the Module codegen: `parse_module_fields` only handles struct ASTs, so applying the Module derive to an enum or union reaches the non-struct arm and fails at compile time. The offending input is the non-struct item carrying the derive attribute.","triggerScenarios":"Thrown at crates/burn-derive/src/module/codegen_struct.rs:340 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Apply the Module derive only to structs; model alternatives with nested module structs or an enum of separate module types.","Remove the derive from the enum and implement `Module` manually if enum-like behavior is needed.","Wrap each variant's data in its own struct and dispatch outside the derive system."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}