rust-lang/rust · error · syn::Error
unexpected token after identifier
Error message
unexpected token after identifier
What it means
Thrown by `#[function_enum]` (enums.rs:29) when more than one token follows the base-name identifier. The macro accepts exactly one attribute token; any extra tokens (commas, extra idents, generics) are rejected.
Source
Thrown at library/compiler-builtins/crates/libm-macros/src/enums.rs:29
pub fn function_enum(
mut item: ItemEnum,
attributes: pm2::TokenStream,
) -> syn::Result<pm2::TokenStream> {
expect_empty_enum(&item)?;
let attr_span = attributes.span();
let mut attr = attributes.into_iter();
// Attribute should be the identifier of the `BaseName` enum.
let Some(tt) = attr.next() else {
return Err(syn::Error::new(attr_span, "expected one attribute"));
};
let pm2::TokenTree::Ident(base_enum) = tt else {
return Err(syn::Error::new(tt.span(), "expected an identifier"));
};
if let Some(tt) = attr.next() {
return Err(syn::Error::new(
tt.span(),
"unexpected token after identifier",
));
}
let enum_name = &item.ident;
let mut as_str_arms = Vec::new();
let mut from_str_arms = Vec::new();
let mut base_arms = Vec::new();
for func in ALL_OPERATIONS.iter() {
let fn_name = func.name;
let ident = Ident::new(&fn_name.to_upper_camel_case(), Span::call_site());
let bname_ident = Ident::new(&base_name(fn_name).to_upper_camel_case(), Span::call_site());
// Match arm for `fn as_str(self)` matcher
as_str_arms.push(quote! { Self::#ident => #fn_name });
from_str_arms.push(quote! { #fn_name => Self::#ident });View on GitHub (pinned to 7088e4b63a)
Solutions
- Provide only the single base-name identifier.
- Remove any trailing punctuation or extra arguments.
Example fix
// before
#[function_enum(BaseName, Extra)]
enum Func {}
// after
#[function_enum(BaseName)]
enum Func {} Defensive patterns
Strategy: validation
Prevention
- function_enum takes exactly one identifier attribute — no lists, no generics.
- Keep the attribute minimal.
When it happens
Trigger: Writing `#[function_enum(BaseName, Extra)]`, `#[function_enum(BaseName<>)]`, or any form with tokens after the identifier.
Common situations: Assuming the macro accepts a list; copy-pasting leftover tokens from another attribute.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- expected one attribute
- expected an identifier
- no attributes expected
- expected an empty enum
- unrecognized function name `{mentioned}`
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/c6e93893806e5c5d.
Report an issue: GitHub.