{"record":{"id":"e44a79968f1b6a13","repo":"astral-sh/ruff","slug":"expected-last-expression-to-be-some-match","errorCode":null,"errorMessage":"expected last expression to be `Some(match (..) { .. })`","messagePattern":"expected last expression to be `Some\\(match \\(\\.\\.\\) (.+?)\\)`","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/ruff_macros/src/map_codes.rs","lineNumber":53,"sourceCode":"    /// 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())\n    else {\n        return Err(Error::new(\n            last_stmt.span(),\n            \"expected last expression to be `Some(match (..) { .. })`\",\n        ));\n    };\n\n    let mut rules = Vec::new();\n    for arm in arms {\n        if matches!(arm.pat, Pat::Wild(..)) {\n            break;\n        }","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_macros/src/map_codes.rs#L35-L71","documentation":"A syn compile error from the map_codes proc macro: the function's final expression is not a Some(match (..) { .. }) call as expected. The macro extracts rule-code pairs from that exact shape, so any other tail expression is rejected at compile time.","triggerScenarios":"Thrown at crates/ruff_macros/src/map_codes.rs:53 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the function ends with Some(match (...) { ... }) over rule pairs","Move auxiliary code before the final Some(match ...) expression"],"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"}