diesel-rs/diesel · error
expected a integer literal expression, but got something…
Error message
expected a integer literal expression, but got something else
What it means
After extracting a literal expression from an enum variant value attribute, diesel_derives further requires it to be an integer literal (`syn::Lit::Int`). A literal of another kind (string, bool, float) reaching this check produces this error at enum_.rs:197.
Solutions
- Use an integer literal for the variant value (e.g. `Active = 1`).
- If the value is fractional, decide on an integer representation (scale it) — floats are not accepted.
- If you intended a string mapping, use serde-style attributes instead, not the diesel numeric-value attribute.
Example fix
// before
enum Role { Admin = "admin", }
// after
enum Role { Admin = 1, } Defensive patterns
Strategy: validation
Validate before calling
// Discriminant literals must be integers. // let ok = matches!(lit_str.trim(), s if s.parse::<i128>().is_ok());
Prevention
- Avoid quoting numeric variant values (`Foo = "1"` fails).
- Do not use float literals as discriminants.
- Search for non-integer literals after `=` in diesel-derived enums before building.
When it happens
Trigger: Writing a non-integer literal as an enum variant's numeric value, e.g. `Foo = "one"` or `Foo = 1.5`, in a derive that parses explicit discriminant values.
Common situations: String literals accidentally used for variant values; float discriminants; porting enums from languages that allow string tags; typos where quotes wrapped the number.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- no `#[diesel(sql_type = ...)]` attribute provided
- all fields of tuple structs must be annotated with…
- `embed` and `treat_none_as_default_value` are mutually…
- `#[diesel(embed)]` cannot be combined with…
- this derive can only be used on non-unit structs
AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07).
Data as JSON: /api/errors/090034efca423750.
Report an issue: GitHub.
Appendix: source
Thrown at diesel_derives/src/enum_.rs:197
}) => {
if let syn::Expr::Lit(l) = &**expr {
(-1, l)
} else {
return Err(syn::Error::new(
v.span(),
"expected a literal expression, but got something else",
));
}
}
_ => {
return Err(syn::Error::new(
v.span(),
"expected a literal expression, but got something else",
));
}
};
let syn::Lit::Int(i) = &l.lit else {
return Err(syn::Error::new(
l.span(),
"expected a integer literal expression, but got something else",
));
};
Ok(f * i.base10_parse::<i128>()?)
})
.transpose()?
.unwrap_or(idx as i128);
let rust_name = v.ident.clone();
let attrs = diesel_attribute_parser::parse_attributes::<
diesel_attribute_parser::FieldAttr,
>(&v.attrs)?;
let rename_attr = attrs.iter().find_map(|a| {
if let diesel_attribute_parser::FieldAttr::Rename(_, r) = &a.item {
Some(r.value())
} else {
None
}View on GitHub (pinned to 6fa6ed01b2)