{"record":{"id":"c508e3830c52c7f6","repo":"diesel-rs/diesel","slug":"invalid-variadic-argument-count-not-enough-functi","errorCode":null,"errorMessage":"invalid variadic argument count: not enough function arguments","messagePattern":"invalid variadic argument count: not enough function arguments","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"diesel_derives/src/sql_function.rs","lineNumber":189,"sourceCode":"    mut input: SqlFunctionDecl,\n    legacy_helper_type_and_module: bool,\n    generate_return_type_helpers: bool,\n    variadic_argument_count: usize,\n    variant_no: usize,\n    variadic_span: Span,\n) -> syn::Result<ExpandedSqlFunction> {\n    add_variadic_doc_comments(&mut input.attributes, &input.fn_name.to_string());\n\n    let sql_name = parse_sql_name_attr(&mut input);\n\n    input.fn_name = format_ident!(\"{}_{}\", input.fn_name, variant_no);\n\n    let nonvariadic_args_count = input\n        .args\n        .len()\n        .checked_sub(variadic_argument_count)\n        .ok_or_else(|| {\n            syn::Error::new(\n                variadic_span,\n                \"invalid variadic argument count: not enough function arguments\",\n            )\n        })?;\n\n    let mut variadic_generic_indexes = vec![];\n    let mut arguments_with_generic_types = vec![];\n    for (arg_idx, arg) in input.args.iter().skip(nonvariadic_args_count).enumerate() {\n        // If argument is of type that definitely cannot be a generic then we skip it.\n        let Type::Path(ty_path) = arg.ty.clone() else {\n            continue;\n        };\n        let Ok(ty_ident) = ty_path.path.require_ident() else {\n            continue;\n        };\n\n        let idx = input.generics.params.iter().position(|param| match param {\n            GenericParam::Type(type_param) => type_param.ident == *ty_ident,","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/diesel-rs/diesel/blob/6fa6ed01b24b24248ab2a611698d0a7c6a2e9120/diesel_derives/src/sql_function.rs#L171-L207","documentation":"The `#[sql_function]` / `sql_function!` macro computes how many non-variadic arguments remain by subtracting the variadic argument count from the total declared arguments. If the declared argument count is smaller than the variadic count, the subtraction underflows and this error is raised in `expand_variadic`.","triggerScenarios":"Declaring a SQL function with fewer total arguments than the number given to `#[variadic(N)]` (or `last_arguments = N`), e.g. `#[variadic(3)]` on a function with only 2 arguments.","commonSituations":"Copy-pasting a variadic function definition and removing arguments without adjusting the variadic count; miscounting which trailing arguments the variadic covers.","solutions":["Ensure the total number of function arguments is greater than or equal to the variadic argument count.","Reduce the `#[variadic(n)]` count to match the actual trailing arguments it should cover.","Add the missing non-variadic arguments to the function signature."],"exampleFix":"// before\n#[sql_function]\n#[variadic(3)]\nfn concat_ws(sep: VarChar); // only 1 arg, variadic needs 3\n\n// after\n#[sql_function]\n#[variadic(3)]\nfn concat_ws(sep: VarChar, a: VarChar, b: VarChar, c: VarChar); // 1 + 3 args","handlingStrategy":"validation","validationCode":"// Verify before compiling: total args must be >= variadic count\n// #[variadic(N)] requires len(args) >= N\nconst TOTAL_ARGS: usize = 4;\nconst VARIADIC_COUNT: usize = 3;\nassert!(TOTAL_ARGS >= VARIADIC_COUNT);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Count arguments and the variadic value together whenever you edit a variadic sql_function.","Remember the variadic count covers only the trailing arguments; leave at least the non-variadic ones in place.","Re-run cargo check after refactoring function signatures."],"tags":["rust","proc-macro","diesel","compile-time","sql-function"],"backgroundTag":"invalid-argument-value","analyzedSha":"6fa6ed01b24b24248ab2a611698d0a7c6a2e9120","analyzedAt":"2026-09-07T01:50:13.074Z","contentChangedAt":"2026-09-07T01:50:13.074Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}