rust-lang/rust · error · syn::Error
expected one attribute
Error message
expected one attribute
What it means
Thrown by the `#[function_enum]` attribute macro (enums.rs:21) when it is invoked with no attribute argument. The macro requires exactly one attribute — the identifier of the companion `BaseName` enum — so an empty attribute list is rejected.
Source
Thrown at library/compiler-builtins/crates/libm-macros/src/enums.rs:21
use proc_macro2::{Ident, Span};
use quote::quote;
use syn::spanned::Spanned;
use syn::{Fields, ItemEnum, Variant};
use crate::{ALL_OPERATIONS, base_name};
/// Implement `#[function_enum]`, see documentation in `lib.rs`.
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();
View on GitHub (pinned to 7088e4b63a)
Solutions
- Add the BaseName enum identifier as the single attribute: `#[function_enum(BaseName)]`.
- Ensure the named enum is itself annotated with `#[base_name_enum]`.
Example fix
// before
#[function_enum]
enum Func {}
// after
#[function_enum(BaseName)]
enum Func {} Defensive patterns
Strategy: validation
Prevention
- function_enum always requires exactly one identifier attribute naming the BaseName enum.
- Keep the attribute and the BaseName enum definition consistent.
When it happens
Trigger: Writing `#[function_enum]` or `#[function_enum()]` on an enum without providing the `BaseName` enum identifier as the attribute.
Common situations: Copy-pasting the macro from docs and dropping the attribute; renaming the macro invocation while refactoring.
Related errors
- expected an identifier
- unexpected token after 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/8f903157f4bfaabb.
Report an issue: GitHub.