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

unrecognized meta expression `{s}`

Error message

unrecognized meta expression `{s}`

What it means

Inside `extra` and `fn_extra` expressions the MacroReplace visitor recognizes two magic identifiers, `MACRO_FN_NAME` and `MACRO_FN_NAME_NORMALIZED`, substituting the per-invocation function name (lib.rs:457-473). Any other identifier whose text starts with `MACRO` is treated as a misspelled magic token and rejected.

Source

Thrown at library/compiler-builtins/crates/libm-macros/src/lib.rs:467

    fn finish(self) -> syn::Result<()> {
        match self.error {
            Some(e) => Err(e),
            None => Ok(()),
        }
    }

    fn visit_ident_inner(&mut self, i: &mut Ident) {
        let s = i.to_string();
        if !s.starts_with("MACRO") || self.error.is_some() {
            return;
        }

        match s.as_str() {
            "MACRO_FN_NAME" => *i = Ident::new(self.fn_name, i.span()),
            "MACRO_FN_NAME_NORMALIZED" => *i = Ident::new(&self.norm_name, i.span()),
            _ => {
                self.error = Some(syn::Error::new(
                    i.span(),
                    format!("unrecognized meta expression `{s}`"),
                ));
            }
        }
    }
}

impl VisitMut for MacroReplace {
    fn visit_ident_mut(&mut self, i: &mut Ident) {
        self.visit_ident_inner(i);
        syn::visit_mut::visit_ident_mut(self, i);
    }
}

/// Return the unsuffixed version of a function name; e.g. `abs` and `absf` both return `abs`,
/// `lgamma_r` and `lgammaf_r` both return `lgamma_r`.
fn base_name(name: &str) -> &str {

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Use only MACRO_FN_NAME or MACRO_FN_NAME_NORMALIZED.
  2. If the identifier is meant to be an ordinary variable, rename it so it does not begin with MACRO.

Example fix

// before
extra: [MACRO_RET_TYPE],
// after
extra: [MACRO_FN_NAME],
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Writing `MACRO_FN_TYPE`, `MACRO_CRET`, or any `MACRO_...` identifier other than the two supported ones inside an `extra` or `fn_extra` expression.

Common situations: Guessing at additional magic identifiers; typoing `MACRO_FN_NAME`; copy-paste from a different macro system.

Related errors


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