rust-lang/rust · error · syn::Error
missing expected field `{name}`
Error message
missing expected field `{name}` What it means
The only mandatory top-level field of for_each_function! is `callback`, the name of the macro to invoke once per function (parse.rs:76, 226-236). expect_field() returns this error (via `?`) when `callback` is absent; all other fields are optional (.ok()).
Source
Thrown at library/compiler-builtins/crates/libm-macros/src/parse.rs:229
Ok(res)
}
fn expect_empty_attrs(attrs: &[Attribute]) -> syn::Result<()> {
if attrs.is_empty() {
return Ok(());
}
let e = syn::Error::new(
attrs.first().unwrap().span(),
"no attributes allowed in this position",
);
Err(e)
}
/// Extract a named field from a map, raising an error if it doesn't exist.
fn expect_field(v: &mut Vec<Mapping>, name: &str) -> syn::Result<Expr> {
let pos = v.iter().position(|v| v.name == name).ok_or_else(|| {
syn::Error::new(
Span::call_site(),
format!("missing expected field `{name}`"),
)
})?;
Ok(v.remove(pos).expr)
}
/// Coerce an expression into a simple identifier.
fn expect_ident(expr: Expr) -> syn::Result<Ident> {
syn::parse2(expr.into_token_stream())
}
/// Coerce an expression into a simple keyword.
fn expect_litbool(expr: Expr) -> syn::Result<LitBool> {
syn::parse2(expr.into_token_stream())
}
View on GitHub (pinned to 7088e4b63a)
Solutions
- Add a `callback: your_macro_name` field to the invocation.
Example fix
// before
libm_macros::for_each_function! {
emit_types: all,
}
// after
libm_macros::for_each_function! {
callback: my_callback,
emit_types: all,
} Defensive patterns
Strategy: validation
Prevention
- Every for_each_function! block must start with a callback: field.
- Use a snippet/template that already includes the callback line.
When it happens
Trigger: Omitting `callback: ...` from the invocation entirely.
Common situations: Starting to write a macro invocation and forgetting the callback macro reference; deleting the line accidentally.
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/fadfba762c422a0a.
Report an issue: GitHub.