rust-lang/rust · error · syn::Error
`fn_extra` expects a match expression
Error message
`fn_extra` expects a match expression
What it means
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.
Source
Thrown at library/compiler-builtins/crates/libm-macros/src/parse.rs:158
callback: expect_ident(cb_expr)?,
emit_types,
skip,
skip_f16_f128,
skip_builtins,
only,
only_span,
attributes,
extra,
fn_extra,
fn_extra_span,
emit_types_span,
})
}
}
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);
}View on GitHub (pinned to 7088e4b63a)
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.
Example fix
// before
fn_extra: my_default(),
// after
fn_extra: match MACRO_FN_NAME {
_ => my_default(),
}, Defensive patterns
Strategy: validation
Prevention
- Always start fn_extra with the literal `match MACRO_FN_NAME {`.
- Remember fn_extra is match-based, unlike extra which takes a single expression.
When it happens
Trigger: Writing `fn_extra: some_func()`, `fn_extra: 42`, or `fn_extra: my_value` where the value is not a `match` expression.
Common situations: Forgetting the match MACRO_FN_NAME { ... } syntax; passing a function pointer or literal instead.
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/cb4ffa6c4af5e598.
Report an issue: GitHub.