{"record":{"id":"766e9f03d1c5b5e0","repo":"diesel-rs/diesel","slug":"function-return-type-should-be-explicitly-specifie","errorCode":null,"errorMessage":"Function return type should be explicitly specified as `-> _` for auto_type","messagePattern":"Function return type should be explicitly specified as `-> _` for auto_type","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"dsl_auto_type/src/auto_type/mod.rs","lineNumber":168,"sourceCode":"            // Add local variables from the function body, and finally infer the type\n            local_variables_map.infer_block_expression_type(\n                return_expression,\n                Some(&return_type),\n                &input_function.block,\n                &mut errors,\n            )\n        }\n        _ => {\n            // This error message is not strictly correct: we also support\n            // partially-specified return types that involve `_`, but for simplicity we just\n            // put the overwhelmingly most common case in this error message\n            return Err(syn::Error::new(\n                input_function.sig.output.span(),\n                \"Function return type should be explicitly specified as `-> _` for auto_type\",\n            )\n            .into());\n        }\n    };\n\n    let type_alias = match type_alias {\n        Some(type_alias) => {\n            // We're generating a type alias so we need to extract the necessary lifetimes and\n            // generic type parameters for that type alias\n            let type_alias_generics = referenced_generics::extract_referenced_generics(\n                &return_type,\n                &input_function.sig.generics,\n                &mut errors,\n            );\n\n            let vis = &input_function.vis;\n            input_function.sig.output = parse_quote!(-> #type_alias #type_alias_generics);\n            quote! {\n                #[allow(non_camel_case_types)]\n                #vis type #type_alias #type_alias_generics = #return_type;\n            }\n        }","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/diesel-rs/diesel/blob/6fa6ed01b24b24248ab2a611698d0a7c6a2e9120/dsl_auto_type/src/auto_type/mod.rs#L150-L186","documentation":"The function's return type must be written as `-> _` (or be a partially specified type containing `_`) so auto_type can substitute the inferred type. Any other explicit return type (e.g. `-> i32`, `-> Vec<T>`) cannot be handled and expansion fails; the message names the common case `-> _`, though `_`-containing types are also accepted.","triggerScenarios":"`#[auto_type] fn f() -> i32 { ... }` or any concrete/complex return type not containing `_` on an auto_type function.","commonSituations":"Adding #[auto_type] to an existing fully-typed function to obtain the type alias; leftover explicit return types after introducing the macro; confusion about whether `_` is legal in return position (it is, and required here).","solutions":["Change the return type to `-> _` and let the macro infer it.","If you need a partially specified type, use `_` inside it where the macro should infer (e.g. `-> Vec<_>`), which is also accepted.","Remove #[auto_type] if you want to keep the explicit return type."],"exampleFix":"// before\n#[auto_type]\nfn f() -> i32 { 1 }\n// after\n#[auto_type]\nfn f() -> _ { 1 }","handlingStrategy":"validation","validationCode":"fn ret_is_infer(sig: &syn::Signature) -> bool {\n    matches!(&sig.output, syn::ReturnType::Default) || ty_contains_infer(&sig.output)\n} // require `-> _` (or `-> ...<_>`) before applying #[auto_type]","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write `-> _` when adopting #[auto_type].","Keep explicit return types on functions that don't need the alias."],"tags":["rust","proc-macro","return-type","compile-time"],"backgroundTag":"invalid-argument-format","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"}