{"record":{"id":"6faf3854258daa9c","repo":"rust-lang/rust","slug":"only-allowed-to-match-on-macro-fn-name","errorCode":null,"errorMessage":"only allowed to match on `MACRO_FN_NAME`","messagePattern":"only allowed to match on `MACRO_FN_NAME`","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"library/compiler-builtins/crates/libm-macros/src/parse.rs","lineNumber":174,"sourceCode":"fn 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    }\n\n    let mut res = BTreeMap::new();\n\n    for arm in arms {\n        let Arm {\n            attrs,\n            pat,\n            guard,\n            fat_arrow_token: _,\n            body,\n            comma: _,\n        } = arm;\n\n        expect_empty_attrs(&attrs)?;\n\n        let keys = match pat {","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/library/compiler-builtins/crates/libm-macros/src/parse.rs#L156-L192","documentation":"The scrutinee of the fn_extra match must be exactly the magic identifier `MACRO_FN_NAME`, which the macro rewrites per invocation (parse.rs:172-176). Matching on any other identifier is rejected because the dispatch would have no per-function meaning.","triggerScenarios":"Writing `fn_extra: match foo { ... }`, `match MACRO_FN_NAME_NORMALIZED { ... }`, or any scrutinee other than MACRO_FN_NAME.","commonSituations":"Using a real variable as scrutinee; choosing the normalized magic token by mistake.","solutions":["Change the match scrutinee to exactly `MACRO_FN_NAME`."],"exampleFix":"// before\nfn_extra: match MACRO_FN_NAME_NORMALIZED {\n    _ => |x| x,\n},\n// after\nfn_extra: match MACRO_FN_NAME {\n    _ => |x| x,\n},","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["The fn_extra scrutinee is fixed: always `match MACRO_FN_NAME`.","Use MACRO_FN_NAME_NORMALIZED only inside arm bodies, never as the scrutinee."],"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"}