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

Expected `Option<_>` as type.

Error message

Expected `Option<_>`  as type.

What it means

A syn compile error from the ConfigurationOptions derive when handling an option-group field: the field's type path is not Option<...>, which the macro requires so it can emit a record_set call with the group's inner type.

Source

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

    match &field.ty {
        Type::Path(TypePath {
            path: Path { segments, .. },
            ..
        }) => match segments.first() {
            Some(PathSegment {
                ident: type_ident,
                arguments:
                    PathArguments::AngleBracketed(AngleBracketedGenericArguments { args, .. }),
            }) if type_ident == "Option" => {
                let path = &args[0];
                let kebab_name = LitStr::new(&ident.to_string().replace('_', "-"), ident.span());

                Ok(quote_spanned!(
                    ident.span() => (visit.record_set(#kebab_name, ruff_options_metadata::OptionSet::of::<#path>()))
                ))
            }
            _ => Err(syn::Error::new(
                ident.span(),
                "Expected `Option<_>`  as type.",
            )),
        },
        _ => Err(syn::Error::new(ident.span(), "Expected type.")),
    }
}

/// Parse a `doc` attribute into it a string literal.
fn parse_doc(doc: &Attribute) -> syn::Result<String> {
    match &doc.meta {
        syn::Meta::NameValue(syn::MetaNameValue {
            value:
                syn::Expr::Lit(ExprLit {
                    lit: Lit::Str(lit_str),
                    ..
                }),
            ..

View on GitHub (pinned to 26f38c119c)

Solutions

  1. Wrap the option group in Option<_>
  2. Annotate the field differently or exclude it from the derive
Defensive patterns

Strategy: validation

When it happens

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