bevyengine/bevy · error · syn::Error

Unnamed fields are not supported here

Error message

Unnamed fields are not supported here

What it means

Emitted by bevy_macro_utils::shape::require_named when a Bevy derive that requires named fields is applied to a tuple struct or unit struct. Currently used by the Specializer derive in bevy_render's macros, which generates code that accesses fields by name, so unnamed fields cannot be supported.

Source

Thrown at crates/bevy_macro_utils/src/shape.rs:29

    match data {
        Data::Struct(data_struct) => Ok(&data_struct.fields),
        Data::Enum(DataEnum { enum_token, .. }) => Err(Error::new(
            enum_token.span(),
            format!("#[{meta}] only supports structs, not enums"),
        )),
        Data::Union(DataUnion { union_token, .. }) => Err(Error::new(
            union_token.span(),
            format!("#[{meta}] only supports structs, not unions"),
        )),
    }
}

/// Return an error if `Fields` is not `Fields::Named`
pub fn require_named<'a>(fields: &'a Fields) -> Result<&'a Punctuated<Field, Comma>, Error> {
    if let Fields::Named(fields) = fields {
        Ok(&fields.named)
    } else {
        Err(Error::new(
            fields.span(),
            "Unnamed fields are not supported here",
        ))
    }
}

View on GitHub (pinned to 396ca72708)

Solutions

  1. Give the struct named fields: `struct MySpec { value: u32 }`.
  2. If the type is only a marker with no data, keep it a named-field struct with no fields or add a placeholder named field.

Example fix

// before
#[derive(Specializer)]
struct KeyDesc(u32, u32);

// after
#[derive(Specializer)]
struct KeyDesc {
    key: u32,
    base_instance: u32,
}
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Writing `#[derive(Specializer)] struct MySpec(u32);` or a unit struct `struct Marker;` — any Fields::Unnamed/Fields::Unit input reaches require_named and returns the error with a span over the parenthesized field list.

Common situations: Refactoring a Specializer struct from named fields to a tuple struct; writing a new specialization key type by mirroring a tuple-struct component elsewhere in the codebase.

Related errors


AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20). Data as JSON: /api/errors/0073902cf5ee6afd. Report an issue: GitHub.