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

Can only derive ConfigurationOptions from structs with named

Error message

Can only derive ConfigurationOptions from structs with named fields.

What it means

A syn compile error from the ConfigurationOptions derive macro: the annotated type is not a struct with named fields. The macro walks named fields to emit OptionsMetadata visiting code, so other shapes are rejected at compile time.

Source

Thrown at crates/ruff_macros/src/config.rs:98

                Some(quote!(
                    fn documentation() -> Option<&'static str> {
                        Some(&#doc)
                    }
                ))
            };

            Ok(quote! {
                #[automatically_derived]
                impl ruff_options_metadata::OptionsMetadata for #ident {
                    fn record(visit: &mut dyn ruff_options_metadata::Visit) {
                        #(#output);*
                    }

                    #documentation
                }
            })
        }
        _ => Err(syn::Error::new(
            ident.span(),
            "Can only derive ConfigurationOptions from structs with named fields.",
        )),
    }
}

/// For a field with type `Option<Foobar>` where `Foobar` itself is a struct
/// deriving `ConfigurationOptions`, create code that calls retrieves options
/// from that group: `Foobar::get_available_options()`
fn handle_option_group(field: &Field) -> syn::Result<proc_macro2::TokenStream> {
    let ident = field
        .ident
        .as_ref()
        .expect("Expected to handle named fields");

    match &field.ty {
        Type::Path(TypePath {
            path: Path { segments, .. },

View on GitHub (pinned to 26f38c119c)

Solutions

  1. Restructure the options type as a named-field struct
  2. Implement OptionsMetadata manually for this type
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/ruff_macros/src/config.rs:98 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/3a2215ae0db678a7. Report an issue: GitHub.