Description
This code example is a simplified extraction of part of the hierarchy that I'm working on for https://github.com/sgrif/yaqb. It's still a bit contrived, but I think it really gets the point across about how unhelpful/nonsensical the resulting error message is.
The type structure goes like this: AsExpression
represents a type which can be converted to an Expression
which would return a given type. Expression
represents... well, an expression. AsExpression
gets a blanket impl for any type which implements Expression
. Column
represents a concrete column (which in the real code has other things associated to it). Ultimately the column has a type, and can be used as an expression of that type. Any type that implements Column
gets a blanket impl for Expression
.
In main
, we're trying to compare a column representing an i32
, to a str
. This is incorrect, and should fail to compile. However, the error message we get out of this is:
error: the trait
Column
is not implemented for the type&str
[E0277]
In the context of a SQL database, and what Column
means, this is a nonsense error, and would not be helpful to the user in seeing why their code is failing to compile. Rust is just being super clever and realizing that the blanket impls would apply if we just implement that instead. I'd like to propose changing the error message to something with a bit more information, such as:
error: the trait
AsExpression<i32>
is not implemented for the type&str
[E0277]A blanket implementation of
AsExpression
, located at <file_path>:<line_number> could apply ifColumn
were implemented for the type&str