Skip to content

Mixed type parameter names shown if a type-def from a third party crate is used #81374

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
weiznich opened this issue Jan 25, 2021 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-confusing Diagnostics: Confusing error or lint that should be reworked. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@weiznich
Copy link
Contributor

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

@weiznich weiznich added the C-bug Category: This is a bug. label Jan 25, 2021
@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. labels Jan 25, 2021
@estebank estebank added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 26, 2021
@fmease fmease added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Dec 28, 2024
@fmease
Copy link
Member

fmease commented Dec 28, 2024

While there's no MCVE (I don't have time rn to build diesel & find one), I'm more than certain that this is #109905 which I fixed more than a year ago in #109957. No additional regression tests needed, closing as completed.

@fmease fmease closed this as completed Dec 28, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-confusing Diagnostics: Confusing error or lint that should be reworked. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants