rust-lang/rust · error · syn::Error

unexpected fields

Error message

unexpected fields {map:?}

What it means

for_each_function! accepts a fixed set of top-level fields: callback, emit_types, skip, skip_f16_f128, skip_builtins, only, attributes, extra, fn_extra (parse.rs:74-91). from_fields() pulls each known field out; any remaining `key: value` mapping is leftover and rejected as unexpected.

Solutions

  1. Remove the unexpected field or correct its name to one of the nine accepted fields.
  2. Consult the macro doc comment (lib.rs:48-122) for the authoritative field list.

Example fix

// before
libm_macros::for_each_function! {
    calllback: cb,
    emit_types: all,
}
// after
libm_macros::for_each_function! {
    callback: cb,
    emit_types: all,
}
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Adding an unknown field such as `verbose: true` or misspelling a known field name (e.g. `callbacks:` instead of `callback:`).

Common situations: Typoing a field name; assuming a field exists that the macro does not support; stale field from an old macro version.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/26816748b64a5775. Report an issue: GitHub.

Appendix: source

Thrown at library/compiler-builtins/crates/libm-macros/src/parse.rs:87

    pub only_span: Option<Span>,
    pub fn_extra_span: Option<Span>,
}

impl StructuredInput {
    pub fn from_fields(input: Invocation) -> syn::Result<Self> {
        let mut map: Vec<_> = input.fields.into_iter().collect();
        let cb_expr = expect_field(&mut map, "callback")?;
        let emit_types_expr = expect_field(&mut map, "emit_types").ok();
        let skip_expr = expect_field(&mut map, "skip").ok();
        let skip_f16_f128 = expect_field(&mut map, "skip_f16_f128").ok();
        let skip_builtins = expect_field(&mut map, "skip_builtins").ok();
        let only_expr = expect_field(&mut map, "only").ok();
        let attr_expr = expect_field(&mut map, "attributes").ok();
        let extra = expect_field(&mut map, "extra").ok();
        let fn_extra = expect_field(&mut map, "fn_extra").ok();

        if !map.is_empty() {
            Err(syn::Error::new(
                map.first().unwrap().name.span(),
                format!("unexpected fields {map:?}"),
            ))?;
        }

        let emit_types_span = emit_types_expr.as_ref().map(|expr| expr.span());
        let emit_types = match emit_types_expr {
            Some(expr) => Parser::parse2(parse_ident_or_array, expr.into_token_stream())?,
            None => Vec::new(),
        };

        let skip = match skip_expr {
            Some(expr) => Parser::parse2(parse_ident_array, expr.into_token_stream())?,
            None => Vec::new(),
        };

        let skip_f16_f128 = match skip_f16_f128 {
            Some(expr) => expect_litbool(expr)?.value,

View on GitHub (pinned to 7088e4b63a)