diesel-rs/diesel · error
expected valid identifier, found
Error message
expected valid identifier, found `{0}`. Diesel automatically renames invalid identifiers, perhaps you meant to write `{0}_`? What it means
A field name containing whitespace cannot be turned into a Rust identifier. The offending input is the field name with spaces; Diesel can rename other invalid identifiers, but whitespace is not supported.
Solutions
- Rename the column so it contains no whitespace
- Map the field explicitly to a valid Rust identifier
- Remove spaces or use a different database column name
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at diesel_attribute_parser/src/lib.rs:107 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07).
Data as JSON: /api/errors/0a50be97530b7615.
Report an issue: GitHub.
Appendix: source
Thrown at diesel_attribute_parser/src/lib.rs:107
pub fn span(&self) -> Span {
self.span
}
pub fn to_ident(&self) -> Result<Ident> {
match syn::parse_str::<Ident>(&format!("r#{}", self.field_name)) {
Ok(mut ident) => {
ident.set_span(self.span);
Ok(ident)
}
Err(_e) if self.field_name.contains(' ') => Err(syn::Error::new(
self.span(),
format!(
"expected valid identifier, found `{0}`. \
Diesel does not support column names with whitespaces yet",
self.field_name
),
)),
Err(_e) => Err(syn::Error::new(
self.span(),
format!(
"expected valid identifier, found `{0}`. \
Diesel automatically renames invalid identifiers, \
perhaps you meant to write `{0}_`?",
self.field_name
),
)),
}
}
}
impl ToTokens for SqlIdentifier {
fn to_tokens(&self, tokens: &mut TokenStream) {
if self.field_name.starts_with("r#") {
Ident::new_raw(&self.field_name[2..], self.span).to_tokens(tokens)
} else {
Ident::new(&self.field_name, self.span).to_tokens(tokens)View on GitHub (pinned to 6fa6ed01b2)