{"record":{"id":"cb4ffa6c4af5e598","repo":"rust-lang/rust","slug":"fn-extra-expects-a-match-expression","errorCode":null,"errorMessage":"`fn_extra` expects a match expression","messagePattern":"`fn_extra` expects a match expression","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"library/compiler-builtins/crates/libm-macros/src/parse.rs","lineNumber":158,"sourceCode":"            callback: expect_ident(cb_expr)?,\n            emit_types,\n            skip,\n            skip_f16_f128,\n            skip_builtins,\n            only,\n            only_span,\n            attributes,\n            extra,\n            fn_extra,\n            fn_extra_span,\n            emit_types_span,\n        })\n    }\n}\n\nfn extract_fn_extra_field(expr: Expr) -> syn::Result<BTreeMap<Ident, Expr>> {\n    let Expr::Match(mexpr) = expr else {\n        let e = syn::Error::new(expr.span(), \"`fn_extra` expects a match expression\");\n        return Err(e);\n    };\n\n    let ExprMatch {\n        attrs,\n        match_token: _,\n        expr,\n        brace_token: _,\n        arms,\n    } = mexpr;\n\n    expect_empty_attrs(&attrs)?;\n\n    let match_on = expect_ident(*expr)?;\n    if match_on != \"MACRO_FN_NAME\" {\n        let e = syn::Error::new(match_on.span(), \"only allowed to match on `MACRO_FN_NAME`\");\n        return Err(e);\n    }","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/library/compiler-builtins/crates/libm-macros/src/parse.rs#L140-L176","documentation":"The `fn_extra` field must be a `match` expression (parsed as syn::ExprMatch) so the macro can extract arms mapping function names to expressions (parse.rs:156-160). extract_fn_extra_field() rejects any non-match expression form.","triggerScenarios":"Writing `fn_extra: some_func()`, `fn_extra: 42`, or `fn_extra: my_value` where the value is not a `match` expression.","commonSituations":"Forgetting the match MACRO_FN_NAME { ... } syntax; passing a function pointer or literal instead.","solutions":["Wrap the value in `fn_extra: match MACRO_FN_NAME { _ => <value> }`.","If a single value applies to all functions, use the default arm form above."],"exampleFix":"// before\nfn_extra: my_default(),\n// after\nfn_extra: match MACRO_FN_NAME {\n    _ => my_default(),\n},","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always start fn_extra with the literal `match MACRO_FN_NAME {`.","Remember fn_extra is match-based, unlike extra which takes a single expression."],"tags":["rust","proc-macro","libm","compile-time","validation"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}