{"record":{"id":"5e62c54e4cf80dc5","repo":"bevyengine/bevy","slug":"key-default-is-the-only-key-override-type-allo","errorCode":null,"errorMessage":"#[key(default)] is the only key override type allowed with #[specialize(all)]","messagePattern":"#\\[key\\(default\\)\\] is the only key override type allowed with #\\[specialize\\(all\\)\\]","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/bevy_render/macros/src/specializer.rs","lineNumber":161,"sourceCode":"\n        let mut use_key_field = true;\n        let mut key = Key::Index(key_index);\n        for attr in &field.attrs {\n            match &attr.meta {\n                Meta::List(MetaList { path, tokens, .. }) if path.is_ident(&KEY_ATTR_IDENT) => {\n                    let owned_tokens = tokens.clone().into();\n                    let Ok(parsed_key) = syn::parse::<Key>(owned_tokens) else {\n                        return Err(syn::Error::new(\n                            attr.span(),\n                            \"Invalid key override attribute\",\n                        ));\n                    };\n                    key = parsed_key;\n                    if matches!(\n                        (&key, &targets),\n                        (Key::Custom(_), SpecializeImplTargets::All)\n                    ) {\n                        return Err(syn::Error::new(\n                            attr.span(),\n                            \"#[key(default)] is the only key override type allowed with #[specialize(all)]\",\n                        ));\n                    }\n                    use_key_field = false;\n                }\n                _ => {}\n            }\n        }\n\n        if use_key_field {\n            used_count += 1;\n            single_index = index;\n        }\n\n        field_info.push(FieldInfo {\n            ty: field_ty,\n            member: field_member,","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_render/macros/src/specializer.rs#L143-L179","documentation":"When `#[derive(Specializer)]` is combined with `#[specialize(all)]`, the macro generates impls for every target using default keys only; it cannot evaluate custom per-field key expressions in that mode. A field carrying a custom `#[key(<expr>)]` therefore aborts compilation with this message at the attribute's span.","triggerScenarios":"`#[specialize(all)]` on the derived type plus any field with `#[key(<expression>)]` (anything other than `#[key(default)]`).","commonSituations":"Switching a Specializer from explicit targets to `all` (e.g. to cover RenderPipeline and compute pipelines at once) and forgetting to relax existing custom key overrides.","solutions":["Change the custom key to `#[key(default)]`","Or replace `#[specialize(all)]` with explicit targets, e.g. `#[specialize(RenderPipeline)]` or a comma-separated list, which do allow custom keys","Re-check every field of the struct after changing the specialize mode"],"exampleFix":"// before\n#[derive(Specializer)]\n#[specialize(all)]\nstruct Pipe {\n    #[key(PipelineKey::Forward)]\n    mode: Mode,\n}\n\n// after\n#[derive(Specializer)]\n#[specialize(all)]\nstruct Pipe {\n    #[key(default)]\n    mode: Mode,\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide the specialize mode first, then pick matching key overrides","With #[specialize(all)], audit that every #[key(...)] is exactly `default`","Switch to explicit targets when custom keys are required"],"tags":["bevy","specializer","proc-macro","compile-time","attribute-conflict"],"backgroundTag":"incompatible-macro-attributes","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}