{"record":{"id":"fb5c3379db018b1c","repo":"astral-sh/ruff","slug":"expected-body-to-end-in-an-expression","errorCode":null,"errorMessage":"expected body to end in an expression","messagePattern":"expected body to end in an expression","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/ruff_macros/src/map_codes.rs","lineNumber":41,"sourceCode":"    code: Option<LinterCode>,\n    /// The path to the struct implementing the rule, e.g.\n    /// `rules::pycodestyle::rules::logical_lines::NoIndentedBlock`\n    path: Path,\n    /// The rule attributes, e.g. for feature gates\n    attrs: Vec<Attribute>,\n}\n\n#[derive(Clone)]\nstruct LinterCode {\n    /// The linter associated with the rule, e.g., `Pycodestyle`.\n    linter: Ident,\n    /// The code associated with the rule, e.g., `\"E112\"`.\n    code: LitStr,\n}\n\npub(crate) fn map_codes(func: &ItemFn) -> syn::Result<TokenStream> {\n    let Some(last_stmt) = func.block.stmts.last() else {\n        return Err(Error::new(\n            func.block.span(),\n            \"expected body to end in an expression\",\n        ));\n    };\n    let Stmt::Expr(\n        Expr::Call(ExprCall {\n            args: some_args, ..\n        }),\n        _,\n    ) = last_stmt\n    else {\n        return Err(Error::new(\n            last_stmt.span(),\n            \"expected last expression to be `Some(match (..) { .. })`\",\n        ));\n    };\n    let mut some_args = some_args.into_iter();\n    let (Some(Expr::Match(ExprMatch { arms, .. })), None) = (some_args.next(), some_args.next())","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_macros/src/map_codes.rs#L23-L59","documentation":"A syn compile error from the map_codes proc macro: the annotated function's body does not end in an expression statement. The macro parses the final Some(match (..) { .. }) expression to build the rule-code table, so a body ending otherwise cannot be processed.","triggerScenarios":"Thrown at crates/ruff_macros/src/map_codes.rs:41 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make the last statement of the function the Some(match ...) expression","Restructure the mapper function so it returns the match expression directly"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}