astral-sh/ruff · error · syn::Error

A new type index cannot have any fields.

Error message

A new type index cannot have any fields.

What it means

A syn compile error from the newtype_index macro: the annotated struct declares fields. Newtype indexes are zero-sized marker types wrapping an index elsewhere, so any field makes the generated index type invalid.

Source

Thrown at crates/ruff_macros/src/newtype_index.rs:7

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: _,

View on GitHub (pinned to 26f38c119c)

Solutions

  1. Remove all fields from the struct
  2. Use a regular struct type if fields are needed
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/ruff_macros/src/newtype_index.rs:7 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/1e84aa715c0e8b23. Report an issue: GitHub.