Skip to content

Long type name emitted if the type name is part of a suggestion #135919

@weiznich

Description

@weiznich

Code

use diesel::prelude::*; //diesel = { version = "2.2.6", default-features = false, features = ["postgres"] }

diesel::table! {
    foo (id) {
        id -> Int4,
        name -> Text,
    }
}

fn main() {
    diesel::debug_query(
        &foo::table
            .filter(foo::id.eq(42))
            .order(foo::name.desc())
            .limit(10)
            .offset(42),
    );
}

Current output

error[E0282]: type annotations needed
  --> src/main.rs:11:5
   |
11 |     diesel::debug_query(
   |     ^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `DB` declared on the function `debug_query`
   |
help: consider specifying the generic arguments
   |
11 |     diesel::debug_query::<DB, SelectStatement<FromClause<table>, query_builder::select_clause::DefaultSelectClause<FromClause<table>>, query_builder::distinct_clause::NoDistinctClause, query_builder::where_clause::WhereClause<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<columns::id, diesel::expression::bound::Bound<Integer, i32>>>>, query_builder::order_clause::OrderClause<diesel::expression::operators::Desc<columns::name>>, LimitOffsetClause<LimitClause<diesel::expression::bound::Bound<BigInt, i64>>, OffsetClause<diesel::expression::bound::Bound<BigInt, i64>>>>>(
   |                        ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Desired output

error[E0282]: type annotations needed
  --> src/main.rs:11:5
   |
11 |     diesel::debug_query(
   |     ^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `DB` declared on the function `debug_query`
   |
help: consider specifying the generic arguments
   |
11 |     diesel::debug_query::<DB, _>(
   |                           ++ 

Rationale and extra context

Emitting the query type there is not helpful for the users as it is long, makes the error message harder to read and ultimately is not even required to fix the code snippet. Fixing the code snippet only requires to specify the DB generic type there. Ideally rustc would be able to suggest possible types for DB there, given the existing constraint on debug_query. In the example above that's even only satisfied by one type (diesel::pg::Pg).

Other cases

If you change the exact query that you pass to debug_query the output changes. You can make the query more complex and therefore get a much more complex and longer query type in the compiler output.

Rust Version

rustc 1.86.0-nightly (649b995a9 2025-01-22)
binary: rustc
commit-hash: 649b995a9febd658b2570160703dff6fdc038ab2
commit-date: 2025-01-22
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Anything else?

cc @estebank as they expressed interested in such cases

List of cases

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions