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

expect `last_arguments`

Error message

expect `last_arguments`

What it means

The named form of the variadic attribute requires the key `last_arguments` (e.g. `#[variadic(last_arguments = 2)]`). If the first token inside `#[variadic(..)]` is an identifier but it is not exactly `last_arguments`, `parse_attribute` raises this error at the key's span.

Solutions

  1. Rename the key to exactly `last_arguments`.
  2. Or use the positional form `#[variadic(2)]` instead of the named form.
  3. Check the diesel version: the key-value syntax (`last_arguments`, optional skip-zero flag) is version-specific.

Example fix

// before
#[sql_function]
#[variadic(last_args = 2)]
fn json_build_object();

// after
#[sql_function]
#[variadic(last_arguments = 2)]
fn json_build_object();
Defensive patterns

Strategy: validation

Validate before calling

// Named form requires the exact key:
// #[variadic(last_arguments = 2)]
let key = "last_arguments";
assert_eq!(key, "last_arguments");

Prevention

When it happens

Trigger: Writing `#[variadic(last_arg = 2)]`, `#[variadic(count = 2)]`, or any other key name inside `#[variadic(..)]` on a `#[sql_function]` item.

Common situations: Guessing the key name instead of consulting docs; abbreviating `last_arguments`; copying a variant from an older diesel version with different syntax.

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/6f85992c8a689274. Report an issue: GitHub.

Appendix: source

Thrown at diesel_derives/src/sql_function.rs:1418

        }),
        syn::Meta::List(syn::MetaList {
            path,
            delimiter: syn::MacroDelimiter::Paren(_),
            tokens: _,
        }) if path.is_ident("variadic") => {
            let (count, flag) = attr
                .parse_args_with(|input: syn::parse::ParseStream| {
                    if input.peek(LitInt){
                        let count = input.parse::<LitInt>()?;
                        if !input.is_empty(){
                            return Err(syn::Error::new(input.span(), "unexpected token after positional `#[variadic(..)]`"));
                        }
                        Ok((count, LitBool::new(false, Span::call_site())))
                    }
                    else {
                        let key: Ident = input.parse()?;
                        if key != "last_arguments" {
                            return Err(syn::Error::new(key.span(), "expect `last_arguments`"));
                        }
                        let _eq: Token![=] = input.parse()?;
                        let count: LitInt = input.parse()?;
                        let skip_zero: LitBool = if input.peek(Token![,]) {
                            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())
                        };

View on GitHub (pinned to 6fa6ed01b2)