{"record":{"id":"664e35c2a72cc72b","repo":"cube-js/cube","slug":"nativebridgestatic-can-only-be-derived-for-structs","errorCode":null,"errorMessage":"NativeBridgeStatic can only be derived for structs","messagePattern":"NativeBridgeStatic can only be derived for structs","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"rust/cube/cubesqlplanner/nativebridge/src/lib.rs","lineNumber":906,"sourceCode":"        impl #struct_ident {\n            pub fn static_fields_meta() -> &'static [cubenativeutils::wrappers::bridge_meta::BridgeFieldMeta] {\n                static FIELDS: &[cubenativeutils::wrappers::bridge_meta::BridgeFieldMeta] = &[\n                    #( #entries ),*\n                ];\n                FIELDS\n            }\n        }\n    };\n    TokenStream::from(expanded)\n}\n\nfn collect_static_field_meta_entries(\n    input: &DeriveInput,\n) -> syn::Result<Vec<proc_macro2::TokenStream>> {\n    let data = match &input.data {\n        Data::Struct(d) => d,\n        _ => {\n            return Err(syn::Error::new(\n                input.span(),\n                \"NativeBridgeStatic can only be derived for structs\",\n            ))\n        }\n    };\n    let fields = match &data.fields {\n        Fields::Named(named) => &named.named,\n        _ => {\n            return Err(syn::Error::new(\n                input.span(),\n                \"NativeBridgeStatic requires a struct with named fields\",\n            ))\n        }\n    };\n\n    let mut entries = Vec::new();\n    for field in fields {\n        let ident = field.ident.as_ref().unwrap();","sourceCodeStart":888,"sourceCodeEnd":924,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/rust/cube/cubesqlplanner/nativebridge/src/lib.rs#L888-L924","documentation":"The `NativeBridgeStatic` derive macro only supports struct inputs. `collect_static_field_meta_entries` matches on `Data::Struct` and, for enums or unions, emits this compile-time error because it needs named fields to generate the static metadata (field names/types) for the bridge.","triggerScenarios":"Applying `#[derive(NativeBridgeStatic)]` to an `enum` or a `union` instead of a `struct`.","commonSituations":"Refactoring a struct into an enum while keeping the derive; copy-pasting the derive attribute onto an enum variant container; misunderstanding that the derive is struct-only.","solutions":["Convert the enum/union to a struct, or remove the `NativeBridgeStatic` derive from it.","If you need enum support, wrap the enum in a struct field or handle it with a different derive/macro.","Check which item the derive is attached to — the error span points at the offending input."],"exampleFix":"// before\n#[derive(NativeBridgeStatic)]\nenum Config { A, B }\n// after\n#[derive(NativeBridgeStatic)]\nstruct Config { a: u32, b: String }","handlingStrategy":"validation","validationCode":"// Before adding the derive, confirm the target is a struct:\n// grep -B2 'derive(NativeBridgeStatic)' src/**.rs  -> each item must be 'struct X { ... }'\nfn is_struct_item(decl: &str) -> bool { decl.trim_start().starts_with(\"struct \") }","typeGuard":"fn derive_target_is_struct(item_kind: &str) -> bool { item_kind == \"struct\" }","tryCatchPattern":null,"preventionTips":["Only attach `#[derive(NativeBridgeStatic)]` to structs with named fields.","When converting a struct to an enum, remove or replace the derive.","Document the struct-only constraint next to the derive usage in your codebase."],"tags":["rust","proc-macro","derive","compile-time"],"backgroundTag":"unsupported-derive-target","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}