diesel-rs/diesel · error · syn::Error

unexpected option

Error message

unexpected option `{name_str}`

What it means

The `#[sql_function]` macro accepts only a fixed set of attribute options: `backends`, `dialect`, and `backend_bounds`. Any other option name inside the attribute parentheses triggers this error at the option's span.

Solutions

  1. Replace the option with one of `backends`, `dialect`, or `backend_bounds`
  2. Fix typos (e.g. `backend_bounds` not `backend_bound`)
  3. Remove the unsupported option and configure the behavior in code instead

Example fix

// before
#[sql_function(unknown = true)]
fn my_fn(x: Integer) -> Text;
// after
#[sql_function(backend_bounds(...))]
fn my_fn(x: Integer) -> Text;
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED_OPTIONS: [&str; 3] = ["backends", "dialect", "backend_bounds"];
fn is_valid_sql_function_option(name: &str) -> bool { ALLOWED_OPTIONS.contains(&name) }

Type guard

fn is_valid_sql_function_option(name: &str) -> bool {
    matches!(name, "backends" | "dialect" | "backend_bounds")
}

Prevention

When it happens

Trigger: Writing `#[sql_function(foo = ...)]` or `#[sql_function(unknown_option)]` with any name not in {backends, dialect, backend_bounds}, e.g. a misspelled `backend_bound` or an option from another macro.

Common situations: Typos in option names; carrying over options from other derive macros; guessing at macro capabilities not supported by the installed diesel version.

Related errors


AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07). Data as JSON: /api/errors/be99c4901335a83b. Report an issue: GitHub.

Appendix: source

Thrown at diesel_derives/src/sql_function.rs:1845

                    out.push_sql(")");
                    Ok(())
                }
            }
        }
    }
}

impl Parse for BackendRestriction {
    fn parse(input: ParseStream) -> Result<Self> {
        let name: syn::Ident = input.parse()?;
        let name_str = name.to_string();
        let content;
        parenthesized!(content in input);
        match &*name_str {
            "backends" => Self::parse_backends(&content, name),
            "dialect" => Self::parse_sql_dialect(&content, name),
            "backend_bounds" => Self::parse_backend_bounds(&content, name),
            _ => Err(syn::Error::new(
                name.span(),
                format!("unexpected option `{name_str}`"),
            )),
        }
    }
}

#[derive(Debug, Clone)]
enum SqlFunctionAttribute {
    Aggregate {
        ident: Ident,
    },
    Window {
        ident: Ident,
        restrictions: BackendRestriction,
        require_order: Option<bool>,
        wrap_macro: Option<Path>,
    },

View on GitHub (pinned to 6fa6ed01b2)