diesel-rs/diesel · error · syn::Error
unsupported literal for auto_type, please provide a type…
Error message
unsupported literal for auto_type, please provide a type hint
What it means
Compile-time error from dsl_auto_type's type inference. try_infer_expression_type can infer types for string/byte-string/byte/int/float literals and method calls, but for other literal kinds (e.g. char or bool literals) it has no inference rule and reports that the user must provide an explicit type hint. Fix: annotate the item with an explicit type (via the type hint option of dsl_auto_type) or restructure the expression.
Solutions
- Provide an explicit type hint for the literal
- Replace the literal with an expression whose type is known
- Use a typed helper such as `TypedNumeric` or an `AsExpression` wrapper
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at dsl_auto_type/src/auto_type/expression_type_inference.rs:252 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/22f62a1aab6deb3a.
Report an issue: GitHub.
Appendix: source
Thrown at dsl_auto_type/src/auto_type/expression_type_inference.rs:252
turbofish.as_ref(),
)?,
}])
.collect(),
leading_colon: None,
},
qself: None,
attrs: Vec::new(),
}),
(syn::Expr::Lit(syn::ExprLit { lit, .. }), None) => match lit {
syn::Lit::Str(_) => parse_quote_spanned!(lit.span()=> &'static str),
syn::Lit::ByteStr(_) => parse_quote_spanned!(lit.span()=> &'static [u8]),
syn::Lit::Byte(_) => parse_quote_spanned!(lit.span()=> u8),
syn::Lit::Char(_) => parse_quote_spanned!(lit.span()=> char),
syn::Lit::Int(lit_int) => literal_type(&lit_int.token())?,
syn::Lit::Float(lit_float) => literal_type(&lit_float.token())?,
syn::Lit::Bool(_) => parse_quote_spanned!(lit.span()=> bool),
_ => {
return Err(syn::Error::new(
lit.span(),
"unsupported literal for auto_type, please provide a type hint",
));
}
},
(syn::Expr::Block(syn::ExprBlock { block, .. }), type_hint) => {
match block.stmts.last() {
None
| Some(
syn::Stmt::Local(_) | syn::Stmt::Item(_) | syn::Stmt::Expr(_, Some(_)),
) => {
// Empty blocks, local variables (`let`) and other item definition as last
// statement, as well as expressions BUT with a semicolon, lead to the
// block having unit type.
match type_hint {
Some(type_hint) => {
// Prefer user-specified type hint to our own inference
type_hint.clone()View on GitHub (pinned to 6fa6ed01b2)