Closed
Description
I tried this code:
use diesel::prelude::*;
let conn = PgConnection::establish("…").unwrap();
let t = diesel::dsl::sql_query("…").load(&conn);
I expected to see an error message pointing out that I need to specify the type of t
because of the definition of load()
is generic. This could either point at t
saying that it needs to know the type of this variable or the generic parameter for load
saying that the user could specify that there as .load::<SomeTypeHere>()
.
Instead, I got a "confusing" error message telling me something about two different type parameters (T
and U
):
error[E0282]: type annotations needed for `std::result::Result<Vec<T>, diesel::result::Error>`
--> src/main.rs:8:41
|
8 | let t = diesel::dsl::sql_query("…").load(&conn);
| - ^^^^ cannot infer type for type parameter `U` declared on the associated function `load`
| |
| consider giving `t` the explicit type `std::result::Result<Vec<T>, diesel::result::Error>`, where the type parameter `U` is specified
The corresponding code in diesel roughly looks like:
type QueryResult<T> = Result<T, …>;
struct SqlQuery {…}
fn sql_query(q: &str) -> SqlQuery {}
trait LoadQuery<Conn, U> {
fn internal_load(self, conn: &Conn) -> QueryResult<Vec<U>>;
}
impl<Conn, U> for SqlQuery where // does not matter
{}
trait RunQueryDsl<Conn> {
fn load<U>(self, conn: &Conn) -> QueryResult<Vec<U>>
where Self: LoadQuery<Conn, U>
{
Self::internal_load(conn)
}
}
impl<Conn, T> RunQueryDsl<Conn> for T {}
It seems like rustc is missing up the generic type T
from the typedef of QueryResult
with the concrete generic type U
from the load
implementation.
Meta
rustc --version --verbose
:
rustc 1.51.0-nightly (1d0d76f8d 2021-01-24)
binary: rustc
commit-hash: 1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8
commit-date: 2021-01-24
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly
LLVM version: 11.0.1
@rustbot modify labels: +D-confusing +A-diagnostics -C-Bug
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsCategory: This is a bug.Diagnostics: Confusing error or lint that should be reworked.Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleRelevant to the compiler team, which will review and decide on the PR/issue.