{"record":{"id":"5cb7fbb9a43a8109","repo":"diesel-rs/diesel","slug":"cannot-find-argument-corresponding-to-the-generic","errorCode":null,"errorMessage":"cannot find argument corresponding to the generic","messagePattern":"cannot find argument corresponding to the generic","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"diesel_derives/src/sql_function.rs","lineNumber":632,"sourceCode":"        } else {\n            let auto_derived_types = type_args\n                .iter()\n                .map(|type_arg| {\n                    for arg in &args {\n                        let Type::Path(path) = &arg.ty else {\n                            continue;\n                        };\n\n                        let Some(path_ident) = path.path.get_ident() else {\n                            continue;\n                        };\n\n                        if path_ident == type_arg {\n                            return Ok(arg.name.clone());\n                        }\n                    }\n\n                    Err(syn::Error::new(\n                        type_arg.span(),\n                        \"cannot find argument corresponding to the generic\",\n                    ))\n                })\n                .collect::<Result<Vec<_>>>()?;\n\n            let arg_names_iter: Vec<_> = args.iter().map(|arg| arg.name.clone()).collect();\n\n            let return_type_module_name =\n                Ident::new(&format!(\"__{fn_name}_return_type\"), fn_name.span());\n\n            let doc =\n                format!(\"Return type of the [`{fn_name}()`](fn@super::{fn_name}) SQL function.\");\n            let return_type_helper_module = quote! {\n                #[allow(non_camel_case_types, non_snake_case, unused_imports)]\n                #[doc(inline)]\n                mod #return_type_module_name {\n                    #[doc = #doc]","sourceCodeStart":614,"sourceCodeEnd":650,"githubUrl":"https://github.com/diesel-rs/diesel/blob/6fa6ed01b24b24248ab2a611698d0a7c6a2e9120/diesel_derives/src/sql_function.rs#L614-L650","documentation":"When expanding a variadic SQL function, diesel maps each generic type parameter to the function argument that uses it. In `expand_nonvariadic`, if a generic parameter appears in the signature but no argument with that exact type is found, the macro cannot wire the generic into the generated code and errors at the type argument's span.","triggerScenarios":"Declaring a `#[sql_function]` whose generic parameter is not used directly as a plain argument type (e.g. wrapped in `Option<T>`, renamed, or the generic has no corresponding argument at all) while using `#[variadic]` expansion.","commonSituations":"Writing generic SQL function definitions where a type parameter appears only inside another type constructor, or removing/renaming an argument without removing its generic.","solutions":["Make every generic type parameter correspond to exactly one function argument written as the bare generic name.","Remove generics that have no corresponding argument.","For wrapped types (e.g. `Nullable<T>`), check how diesel's existing sql_function definitions model them and follow that pattern."],"exampleFix":"// before\n#[sql_function]\nfn coalesce<T: SqlType>(x: Nullable<T>); // T has no bare argument\n\n// after\n#[sql_function]\nfn coalesce<T: SqlType + SingleValue>(x: Nullable<T>, y: T); // T maps to argument y","handlingStrategy":"validation","validationCode":"// Every generic <T: SqlType> must appear as a bare argument type\n// fn f<T: SqlType>(x: T)  -- OK\n// fn f<T: SqlType>(x: Nullable<T>) -- generic T has no matching bare argument","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write each generic type parameter as a standalone argument type in variadic sql_function definitions.","Mirror the generic structure of existing sql_function definitions in diesel's source when wrapping types.","Remove unused generics when editing signatures."],"tags":["rust","proc-macro","diesel","generics","sql-function"],"backgroundTag":"missing-required-argument","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"}