Open
Description
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
- E0282 suggestion In "specify type" suggestion, skip type params that are already known #135965
- E0308 "this expression" type Use short type string in E0308 secondary span label #135949
- E0277 message Rework "long type names" printing logic #136328
- E0382 "move occurs because binding has type" Use short ty string for move errors #136018
- "missing type for
const
item" (not really addressable unless we suggest incomplete code) - E0369 Use short ty string for binop and unop errors #136315
- E0609 Teach structured errors to display short
Ty<'_>
#137201 - E0618 Teach structured errors to display short
Ty<'_>
#137201 - E0529 Teach structured errors to display short
Ty<'_>
#137201 - E0614 Teach structured errors to display short
Ty<'_>
#137201