rust-lang/rust · error · syn::Error
expected an empty enum
Error message
expected an empty enum
What it means
Thrown by `expect_empty_enum` (enums.rs:159), called by both `#[function_enum]` and `#[base_name_enum]`, when the annotated enum already has variants. Both macros populate the enum themselves from the global operation list, so the source enum must be empty.
Source
Thrown at library/compiler-builtins/crates/libm-macros/src/enums.rs:159
#item
impl #item_name {
/// The stringified version of this base name.
pub const fn as_str(self) -> &'static str {
match self {
#( #as_str_arms ),*
}
}
}
};
Ok(res)
}
/// Verify that an enum is empty, otherwise return an error
fn expect_empty_enum(item: &ItemEnum) -> syn::Result<()> {
if !item.variants.is_empty() {
Err(syn::Error::new(
item.variants.span(),
"expected an empty enum",
))
} else {
Ok(())
}
}
View on GitHub (pinned to 7088e4b63a)
Solutions
- Declare the enum with no variants: `enum Func {}`.
- Remove any manually-added variants; the macro generates them.
Example fix
// before
#[function_enum(BaseName)]
enum Func {
Foo,
}
// after
#[function_enum(BaseName)]
enum Func {} Defensive patterns
Strategy: validation
Prevention
- Both function_enum and base_name_enum require an empty enum; variants are generated.
- Never hand-write variants into a macro-annotated enum.
When it happens
Trigger: Annotating an enum that already declares variants, e.g. `enum Func { Foo, Bar }`.
Common situations: Adding a placeholder variant during development; merging an existing enum under the macro; misunderstanding that the macro generates the variants.
Related errors
- expected one attribute
- expected an identifier
- unexpected token after identifier
- no attributes expected
- unrecognized function name `{mentioned}`
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/c31663e3bd83b9c4.
Report an issue: GitHub.