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

only `mysql_backend`, `mariadb_backend`, `postgres_backend`…

Error message

only `mysql_backend`, `mariadb_backend`, `postgres_backend` and `sqlite` are supported features, but got `{feature}`

What it means

When a `cfg_attr(feature = "foo", ...)` is attached to `#[sql_function]`, diesel only recognizes the features `mysql_backend`, `mariadb_backend`, `postgres_backend`, and `sqlite`. Any other feature name is rejected with this error listing the supported set.

Solutions

  1. Use one of `mysql_backend`, `mariadb_backend`, `postgres_backend`, or `sqlite` as the feature name
  2. Fix typos (e.g. `postgres` → `postgres_backend`)
  3. Gate non-backend features with a regular `#[cfg_attr(feature = "...", ...)]` on the item instead of inside `#[sql_function]`

Example fix

// before
#[sql_function(cfg_attr(feature = "postgres", ...))]
// after
#[sql_function(cfg_attr(feature = "postgres_backend", ...))]
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED_FEATURES: [&str; 4] = ["mysql_backend", "mariadb_backend", "postgres_backend", "sqlite"];
fn is_supported_backend_feature(f: &str) -> bool { SUPPORTED_FEATURES.contains(&f) }

Type guard

fn is_supported_backend_feature(f: &str) -> bool {
    matches!(f, "mysql_backend" | "mariadb_backend" | "postgres_backend" | "sqlite")
}

Prevention

When it happens

Trigger: Writing `#[sql_function(cfg_attr(feature = "my-feature", ...))]` or any custom/misspelled feature name inside the macro's cfg_attr option.

Common situations: Using Cargo feature names of your own crate inside the proc-macro attribute; typos like `postgres` instead of `postgres_backend`; copying features from other macros.

Related errors


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

Appendix: source

Thrown at diesel_derives/src/sql_function.rs:1965

            let _ = input.parse::<Token![=]>()?;
            let feature = input.parse::<LitStr>()?;
            let feature_value = feature.value();
            let _ = input.parse::<Token![,]>()?;
            let wrap_macro = match feature_value.as_str() {
                "postgres_backend" => Some(syn::parse_quote!(
                    diesel::internal::sql_functions::expand_pg
                )),
                "sqlite" | "__sqlite_shared" => Some(syn::parse_quote!(
                    diesel::internal::sql_functions::expand_sqlite
                )),
                "mysql_backend" => Some(syn::parse_quote!(
                    diesel::internal::sql_functions::expand_mysql
                )),
                "mariadb_backend" => Some(syn::parse_quote!(
                    diesel::internal::sql_functions::expand_mariadb
                )),
                feature => {
                    return Err(syn::Error::new(
                        feature.span(),
                        format!(
                            "only `mysql_backend`, `mariadb_backend`, `postgres_backend` and `sqlite` \
                                 are supported features, but got `{feature}`"
                        ),
                    ));
                }
            };
            let name = input.parse::<Ident>()?;
            let inner;
            let _paren = parenthesized!(inner in input);
            let mut ret = SqlFunctionAttribute::parse_attr(name, &inner, attr, attribute_span)?;
            if let SqlFunctionAttribute::Window { wrap_macro: w, .. } = &mut ret.item {
                *w = wrap_macro;
            }
            Ok(ret)
        } else {
            let name_str = name.to_string();

View on GitHub (pinned to 6fa6ed01b2)