diesel-rs/diesel · error
this derive can only be used on enums with exclusively…
Error message
this derive can only be used on enums with exclusively unit-variants
What it means
The enum derives in diesel (e.g. `SqliteEnum`-style unit-enum derives in `enum_.rs`) only support plain unit variants. If generics are declared on the enum, the parse step rejects it because generated discriminant/mapping code cannot handle type parameters.
Solutions
- Remove the generic parameters; enumerate concrete variants instead.
- Store the data separately and keep only a fieldless enum for the DB representation.
- Implement the target trait manually if generics are essential.
Example fix
// before
#[derive(...)]
enum Status<T> { Ok(T), Failed }
// after
#[derive(...)]
enum Status { Ok, Failed } Defensive patterns
Strategy: validation
Validate before calling
// Compile-time habit: keep DB enums generic-free
// fn assert_no_generics<T>() {} // not applicable — check the enum declaration instead:
// enum Status { A, B } // ok
// enum Status<T> { A, B } // rejected by the derive Prevention
- Never add generic params to enums used with diesel derives
- Move data out of DB enums into wrapper structs
- Manually implement the trait when generic enums are unavoidable
When it happens
Trigger: Deriving a diesel enum trait on `enum Foo<T> { A, B }` — an enum with any generic parameters.
Common situations: Making a value-carrying enum generic before mapping it to a database string; wrapping an enum in a generic container trait.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- expected a literal expression, but got something else
- `#[diesel(embed)]` cannot be combined with…
- at least one `sql_type` is needed for deriving…
- at least one `belongs_to` is needed for deriving…
- cannot find argument corresponding to the generic
AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07).
Data as JSON: /api/errors/eb6b1660868642e2.
Report an issue: GitHub.
Appendix: source
Thrown at diesel_derives/src/enum_.rs:143
sql_name,
} = self;
let span = *span;
quote::quote_spanned! {span=>
diesel::internal::derives::enum_::EnumVariant {
discriminant: #discriminant,
rust_name: stringify!(#rust_name),
sql_name: #sql_name,
}
}
}
}
impl syn::parse::Parse for DeriveEnumInput {
fn parse(input: syn::parse::ParseStream) -> Result<Self> {
let input = input.parse::<syn::DeriveInput>()?;
let input_span = input.span();
if !input.generics.params.is_empty() {
return Err(syn::Error::new(input.span(), ERROR_MESSAGE));
}
let enum_ = match input.data {
Data::Enum(data_enum) => data_enum,
_ => {
return Err(syn::Error::new(input.span(), ERROR_MESSAGE));
}
};
let attrs = diesel_attribute_parser::parse_attributes::<diesel_attribute_parser::StructAttr>(
&input.attrs,
)?;
let rename_all = attrs.iter().find_map(|a| {
if let diesel_attribute_parser::StructAttr::RenameAll(_, r) = &a.item {
Some(r)
} else {
None
}
});
View on GitHub (pinned to 6fa6ed01b2)