{"record":{"id":"ebf1407d97cba544","repo":"astral-sh/ruff","slug":"a-new-type-index-cannot-be-generic","errorCode":null,"errorMessage":"A new type index cannot be generic.","messagePattern":"A new type index cannot be generic\\.","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/ruff_macros/src/newtype_index.rs","lineNumber":14,"sourceCode":"use quote::quote;\nuse syn::spanned::Spanned;\nuse syn::{Error, ItemStruct};\n\npub(super) fn generate_newtype_index(item: ItemStruct) -> syn::Result<proc_macro2::TokenStream> {\n    if !item.fields.is_empty() {\n        return Err(Error::new(\n            item.span(),\n            \"A new type index cannot have any fields.\",\n        ));\n    }\n\n    if !item.generics.params.is_empty() {\n        return Err(Error::new(\n            item.span(),\n            \"A new type index cannot be generic.\",\n        ));\n    }\n\n    let ItemStruct {\n        attrs,\n        vis,\n        struct_token,\n        ident,\n        generics: _,\n        fields: _,\n        semi_token,\n    } = item;\n\n    let debug_name = ident.to_string();\n\n    let semi_token = semi_token.unwrap_or_default();","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_macros/src/newtype_index.rs#L1-L32","documentation":"Compile-time validation error from the newtype_index derive macro. A #[derive(newtype_index)] (or newtype_index proc macro) is meant to wrap a unit struct used as a salsa-style interned index; a generic type parameter would make the generated index trait impls ambiguous, so generate_newtype_index checks item.generics.params and fails the expansion with this error at the struct's span when any generic parameters are declared. It is a macro-authoring constraint violation, not a runtime error; remove the generic parameters from the struct definition.","triggerScenarios":"Thrown at crates/ruff_macros/src/newtype_index.rs:14 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove generic parameters from the struct","Generate a separate concrete newtype index per instantiation"],"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"}