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

, the correct format is `#[variadic(last_arguments = 3)]`…

Error message

{e}, the correct format is `#[variadic(last_arguments = 3)]` or `#[variadic(last_arguments = 3, skip_zero_argument_variant = true)]`

What it means

Wrapping error from the `#[sql_function]` macro: the inner parse of the `#[variadic(...)]` attribute failed, and diesel augments the inner message with the correct format hint `#[variadic(last_arguments = 3)]` or `#[variadic(last_arguments = 3, skip_zero_argument_variant = true)]`. It fires when the keyword-style variadic attribute does not match the expected `key = value` grammar.

Solutions

  1. Rewrite the attribute to exactly `#[variadic(last_arguments = N)]` or `#[variadic(last_arguments = N, skip_zero_argument_variant = true)]`
  2. Ensure `last_arguments` is a bare integer literal and `skip_zero_argument_variant` is `true`/`false`
  3. Read the inner `{e}` message in the compiler output — it pinpoints which token was wrong

Example fix

// before
#[variadic(last_arguments: 2)]
// after
#[variadic(last_arguments = 2)]
Defensive patterns

Strategy: validation

Validate before calling

fn validate_variadic_kw(inner: &str) -> Result<(), String> {
    let ok = inner.trim().starts_with("last_arguments =")
        && inner.split(',').map(str::trim).skip(1).all(|p| p.starts_with("skip_zero_argument_variant ="));
    if ok { Ok(()) } else { Err(format!("use #[variadic(last_arguments = 3)] or #[variadic(last_arguments = 3, skip_zero_argument_variant = true)]: got {}", inner)) }
}

Prevention

When it happens

Trigger: Calling `#[sql_function]` with a `#[variadic(last_arguments = ...)]` attribute whose inner tokens fail to parse (wrong key, missing `=`, missing integer literal, malformed boolean).

Common situations: Omitting the `=` sign, passing a non-integer for `last_arguments`, using strings instead of literals, or applying the attribute syntax from a different macro.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at diesel_derives/src/sql_function.rs:1441

                            let _: Token![,] = input.parse()?;
                            let key: Ident = input.parse()?;
                            if key != "skip_zero_argument_variant" {
                                return Err(
                                    syn::Error::new(
                                        key.span(), "expect `skip_zero_argument_variant`"
                                    )
                                );
                            }
                            let _eq: Token![=] = input.parse()?;
                            input.parse()?
                        } else {
                            LitBool::new(false, Span::call_site())
                        };
                        Ok((count, skip_zero))
                    }
                })
                .map_err(|e| {
                    syn::Error::new(
                        e.span(),
                        format!(
                            "{e}, the correct format is `#[variadic(last_arguments = 3)]` or `#[variadic(last_arguments = 3, skip_zero_argument_variant = true)]`"
                        ),
                    )
                })?;
            Ok(AttributeSpanWrapper {
                item: SqlFunctionAttribute::Variadic {
                    ident: path
                        .require_ident()
                        .map_err(|e| {
                            syn::Error::new(
                                e.span(),
                                format!("{e}, the correct format is `#[variadic(3)]`"),
                            )
                        })?
                        .clone(),
                    count: count.clone(),

View on GitHub (pinned to 6fa6ed01b2)