{"record":{"id":"2c1c3a81b86de016","repo":"diesel-rs/diesel","slug":"function-body-should-not-be-empty-for-auto-type","errorCode":null,"errorMessage":"function body should not be empty for auto_type","messagePattern":"function body should not be empty for auto_type","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"dsl_auto_type/src/auto_type/mod.rs","lineNumber":122,"sourceCode":"    let last_statement = input_function.block.stmts.last().ok_or_else(|| {\n        syn::Error::new(\n            input_function.span(),\n            \"function body should not be empty for auto_type\",\n        )\n    })?;\n    let mut errors = Vec::new();\n    let return_type = match input_function.sig.output {\n        syn::ReturnType::Type(_, return_type) => {\n            let return_expression = match last_statement {\n                syn::Stmt::Expr(expr, None) => expr,\n                syn::Stmt::Expr(\n                    syn::Expr::Return(syn::ExprReturn {\n                        expr: Some(expr), ..\n                    }),\n                    _,\n                ) => &**expr,\n                _ => {\n                    return Err(syn::Error::new(\n                        last_statement.span(),\n                        \"last statement should be an expression for auto_type\",\n                    )\n                    .into());\n                }\n            };\n\n            // Build a map of local variables, and get the function parameters in there\n            let mut local_variables_map = LocalVariablesMap {\n                inferrer_settings: &inferrer_settings,\n                inner: LocalVariablesMapInner {\n                    map: Default::default(),\n                    parent: None,\n                },\n            };\n            for const_generic in input_function.sig.generics.const_params() {\n                local_variables_map.process_const_generic(const_generic);\n            }","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/diesel-rs/diesel/blob/6fa6ed01b24b24248ab2a611698d0a7c6a2e9120/dsl_auto_type/src/auto_type/mod.rs#L104-L140","documentation":"#[auto_type] needs at least one statement in the function body: it inspects the last statement to determine the return type and build the type alias. An empty body (`fn f() -> _ {}`) leaves `block.stmts.last()` as None, so the macro errors with this message instead of silently generating nothing.","triggerScenarios":"`#[auto_type] fn f() -> _ {}` — a function whose block contains no statements at all.","commonSituations":"Scaffolding a stub function and adding #[auto_type] before writing the body; or commenting out the entire body while keeping the attribute during debugging.","solutions":["Add at least one expression statement / return expression to the function body.","Remove #[auto_type] from the empty stub until the body is implemented.","Give the function a concrete return type and drop the macro if it must remain empty."],"exampleFix":"// before\n#[auto_type]\nfn f() -> _ {}\n// after\n#[auto_type]\nfn f() -> _ { 0i32 }","handlingStrategy":"validation","validationCode":"fn ensure_nonempty(body: &[syn::Stmt]) -> Result<(), ()> { if body.is_empty() { Err(()) } else { Ok(()) } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't attach #[auto_type] to stub/TODO functions.","Implement the body before adding the attribute."],"tags":["rust","proc-macro","empty-body","compile-time"],"backgroundTag":"empty-required-field","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"}