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

Expected `Option<_>` or `Vec<_>` as type.

Error message

Expected `Option<_>` or `Vec<_>` as type.

What it means

A syn compile error from CombineOptions::handle_field: the field's type is a path whose first segment is neither Option nor Vec. The derive only knows how to merge Optional (or-with) and Vec (concat) fields, so any other generic path is rejected at compile time.

Source

Thrown at crates/ruff_macros/src/combine_options.rs:55

}

fn handle_field(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, .. },
            ..
        }) => match segments.first() {
            Some(PathSegment {
                ident: type_ident, ..
            }) if type_ident == "Option" => Ok(quote_spanned!(
                ident.span() => #ident: self.#ident.or(other.#ident)
            )),
            _ => Err(syn::Error::new(
                ident.span(),
                "Expected `Option<_>` or `Vec<_>` as type.",
            )),
        },
        _ => Err(syn::Error::new(ident.span(), "Expected type.")),
    }
}

View on GitHub (pinned to 26f38c119c)

Solutions

  1. Change the field type to Option<_> or Vec<_>
  2. Implement the option's combine logic manually instead of deriving
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/ruff_macros/src/combine_options.rs:55 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/96556ee42dd53b3d. Report an issue: GitHub.