rust-lang/rust · error · syn::Error
only allowed to match on `MACRO_FN_NAME`
Error message
only allowed to match on `MACRO_FN_NAME`
What it means
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.
Source
Thrown at library/compiler-builtins/crates/libm-macros/src/parse.rs:174
fn extract_fn_extra_field(expr: Expr) -> syn::Result<BTreeMap<Ident, Expr>> {
let Expr::Match(mexpr) = expr else {
let e = syn::Error::new(expr.span(), "`fn_extra` expects a match expression");
return Err(e);
};
let ExprMatch {
attrs,
match_token: _,
expr,
brace_token: _,
arms,
} = mexpr;
expect_empty_attrs(&attrs)?;
let match_on = expect_ident(*expr)?;
if match_on != "MACRO_FN_NAME" {
let e = syn::Error::new(match_on.span(), "only allowed to match on `MACRO_FN_NAME`");
return Err(e);
}
let mut res = BTreeMap::new();
for arm in arms {
let Arm {
attrs,
pat,
guard,
fat_arrow_token: _,
body,
comma: _,
} = arm;
expect_empty_attrs(&attrs)?;
let keys = match pat {View on GitHub (pinned to 7088e4b63a)
Solutions
- Change the match scrutinee to exactly `MACRO_FN_NAME`.
Example fix
// before
fn_extra: match MACRO_FN_NAME_NORMALIZED {
_ => |x| x,
},
// after
fn_extra: match MACRO_FN_NAME {
_ => |x| x,
}, Defensive patterns
Strategy: validation
Prevention
- The fn_extra scrutinee is fixed: always `match MACRO_FN_NAME`.
- Use MACRO_FN_NAME_NORMALIZED only inside arm bodies, never as the scrutinee.
When it happens
Trigger: Writing `fn_extra: match foo { ... }`, `match MACRO_FN_NAME_NORMALIZED { ... }`, or any scrutinee other than MACRO_FN_NAME.
Common situations: Using a real variable as scrutinee; choosing the normalized magic token by mistake.
Related errors
- unrecognized type identifier `{ty_name}`
- if `all` is specified, no other type identifiers may be give
- `fn_extra`: no default `_` pattern specified and the followi
- unrecognized meta expression `{s}`
- unexpected fields {map:?}
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/6faf3854258daa9c.
Report an issue: GitHub.