{"record":{"id":"fcbb994373ed6732","repo":"astral-sh/ruff","slug":"cachekey-does-not-support-unions-only-structs-and","errorCode":null,"errorMessage":"CacheKey does not support unions. Only structs and enums are supported","messagePattern":"CacheKey does not support unions\\. Only structs and enums are supported","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/ruff_macros/src/cache_key.rs","lineNumber":92,"sourceCode":"                        continue;\n                    }\n                }\n\n                let field_attr = if let Some(ident) = &field.ident {\n                    quote!(self.#ident)\n                } else {\n                    let index = syn::Index::from(i);\n                    quote!(self.#index)\n                };\n\n                fields.push(quote!(#field_attr.cache_key(key);));\n            }\n\n            quote! {#(#fields)*}\n        }\n\n        Data::Union(_) => {\n            return Err(Error::new(\n                item.span(),\n                \"CacheKey does not support unions. Only structs and enums are supported\",\n            ));\n        }\n    };\n\n    let name = &item.ident;\n    let (impl_generics, ty_generics, where_clause) = &item.generics.split_for_impl();\n\n    Ok(quote!(\n        #[automatically_derived]\n        impl #impl_generics ruff_cache::CacheKey for #name #ty_generics #where_clause {\n            fn cache_key(&self, key: &mut ruff_cache::CacheKeyHasher) {\n                use std::hash::Hasher;\n                use ruff_cache::CacheKey;\n                #fields\n            }\n        }","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_macros/src/cache_key.rs#L74-L110","documentation":"A syn compile error from the CacheKey derive macro: the derive was applied to a union. The generated cache-key logic only knows how to walk structs and enums field by field, so unions are rejected at compile time.","triggerScenarios":"Thrown at crates/ruff_macros/src/cache_key.rs:92 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Implement CacheKey manually for the union","Change the type to a struct or enum so the derive applies"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}