astral-sh/ruff · error · syn::Error
A new type index cannot be generic.
Error message
A new type index cannot be generic.
What it means
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.
Source
Thrown at crates/ruff_macros/src/newtype_index.rs:14
use quote::quote;
use syn::spanned::Spanned;
use syn::{Error, ItemStruct};
pub(super) fn generate_newtype_index(item: ItemStruct) -> syn::Result<proc_macro2::TokenStream> {
if !item.fields.is_empty() {
return Err(Error::new(
item.span(),
"A new type index cannot have any fields.",
));
}
if !item.generics.params.is_empty() {
return Err(Error::new(
item.span(),
"A new type index cannot be generic.",
));
}
let ItemStruct {
attrs,
vis,
struct_token,
ident,
generics: _,
fields: _,
semi_token,
} = item;
let debug_name = ident.to_string();
let semi_token = semi_token.unwrap_or_default();View on GitHub (pinned to 26f38c119c)
Solutions
- Remove generic parameters from the struct
- Generate a separate concrete newtype index per instantiation
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/ruff_macros/src/newtype_index.rs:14 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05).
Data as JSON: /api/errors/ebf1407d97cba544.
Report an issue: GitHub.