Repository: diesel-rs/diesel
File: diesel_derives/src/sql_function.rs (Rust)

Code before:
                    let Type::Path(path) = &arg.ty else {
                        continue;
                    };

                    let Some(path_ident) = path.path.get_ident() else {
                        continue;
                    };

                    if path_ident == type_arg {
                        return Ok(arg.name.clone());
                    }
                }

                Err(syn::Error::new(
                    type_arg.span(),
                    "cannot find argument corresponding to the generic",
                ))
            })
            .collect::<Result<Vec<_>>>()?;

        let arg_names_iter: Vec<_> = args.iter().map(|arg| arg.name.clone()).collect();

        let return_type_module_name =
            Ident::new(&format!("__{}_return_type", fn_name), fn_name.span());

        let doc = format!("Return type of [`{fn_name}()`](super::{fn_name}()).");
        let return_type_helper_module = quote! {
            #[allow(non_camel_case_types, non_snake_case, unused_imports)]
            #[doc(hidden)]
            mod #return_type_module_name {
                #[doc = #doc]
                pub type #fn_name<
                    #(#arg_names_iter,)*
                > = super::#fn_name<
                    #( <#auto_derived_types as diesel::expression::Expression>::SqlType, )*
                    #(#arg_names_iter,)*
                >;
            }
        };

        let module_path = parse_quote!(
            #return_type_module_name
        );

        (Some(return_type_helper_module), Some(module_path))
    };

    let tokens = quote! {
        #(#attributes)*
        #[allow(non_camel_case_types)]
        pub #fn_token #fn_name #impl_generics (#(#args_iter,)*)

Review comment (suggestion):
This link currently seems to link back on itself. We might want to try using a link disambiguator (e.g. `fn@super::{fn_name}()`) like described here: https://doc.rust-lang.org/rustdoc/write-documentation/linking-to-items-by-name.html#namespaces-and-disambiguators

Also it might be worth to slightly tweak the wording here to 

```suggestion
        let doc = format!("Return type of the [`{fn_name}()`](fn@super::{fn_name}()) SQL function.");
```


Code after:
        let auto_derived_types = type_args
            .iter()
            .map(|type_arg| {
                for arg in args {
                    let Type::Path(path) = &arg.ty else {
                        continue;
                    };

                    let Some(path_ident) = path.path.get_ident() else {
                        continue;
                    };

                    if path_ident == type_arg {
                        return Ok(arg.name.clone());
                    }
                }

                Err(syn::Error::new(
                    type_arg.span(),
                    "cannot find argument corresponding to the generic",
                ))
            })
            .collect::<Result<Vec<_>>>()?;

        let arg_names_iter: Vec<_> = args.iter().map(|arg| arg.name.clone()).collect();

        let return_type_module_name =
            Ident::new(&format!("__{}_return_type", fn_name), fn_name.span());

        let doc = format!("Return type of the [`{fn_name}()`](fn@super::{fn_name}) SQL function.");
        let return_type_helper_module = quote! {
            #[allow(non_camel_case_types, non_snake_case, unused_imports)]
            #[doc(inline)]
            mod #return_type_module_name {
                #[doc = #doc]
                pub type #fn_name<
                    #(#arg_names_iter,)*
                > = super::#fn_name<
                    #( <#auto_derived_types as diesel::expression::Expression>::SqlType, )*
                    #(#arg_names_iter,)*
                >;
            }
        };

        let module_path = parse_quote!(
            #return_type_module_name
        );

        (Some(return_type_helper_module), Some(module_path))
    };