diesel-rs/diesel · error · syn::Error
unsupported binary operator for auto_type
Error message
unsupported binary operator for auto_type: {binary_expression.op:?} What it means
auto_type does not implement type inference for this binary operator. The offending input is the operator used in the expression; supported operators are limited to comparison and arithmetic forms with known result types.
Solutions
- Rewrite the expression using a supported operator
- Add an explicit type annotation for the result
- Move the operation into a custom expression wrapper
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at dsl_auto_type/src/auto_type/expression_type_inference.rs:342 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/ef662cfc06121f33.
Report an issue: GitHub.
Appendix: source
Thrown at dsl_auto_type/src/auto_type/expression_type_inference.rs:342
| syn::BinOp::Lt(_)
| syn::BinOp::Le(_)
| syn::BinOp::Ne(_)
| syn::BinOp::Ge(_)
| syn::BinOp::Gt(_) => return Ok(parse_quote!(bool)),
syn::BinOp::AddAssign(_)
| syn::BinOp::SubAssign(_)
| syn::BinOp::MulAssign(_)
| syn::BinOp::DivAssign(_)
| syn::BinOp::RemAssign(_)
| syn::BinOp::BitXorAssign(_)
| syn::BinOp::BitAndAssign(_)
| syn::BinOp::BitOrAssign(_)
| syn::BinOp::ShlAssign(_)
| syn::BinOp::ShrAssign(_) => return Ok(parse_quote!(())),
_ => {
// This is here because the `BinOp` enum is marked as #[non_exhaustive],
// but in effect we really support all the variants
return Err(syn::Error::new(
op_span,
format_args!(
"unsupported binary operator for auto_type: {:?}",
binary_expression.op
),
));
}
};
let trait_name_ident = syn::Ident::new(trait_name, op_span);
let left_type = self.infer_expression_type(&binary_expression.left, None);
let right_type = self.infer_expression_type(&binary_expression.right, None);
parse_quote!(<#left_type as ::core::ops::#trait_name_ident<#right_type>>::Output)
}
(_, None) => {
return Err(syn::Error::new(
expr.span(),
"unsupported expression for auto_type, please provide a type hint",
));View on GitHub (pinned to 6fa6ed01b2)