Long type name emitted if the type name is part of a suggestion
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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 https://github.com/rust-lang/rust/pull/135965
- E0308 "this expression" type https://github.com/rust-lang/rust/pull/135949
- E0277 message https://github.com/rust-lang/rust/pull/136328
- E0382 "move occurs because binding has type" https://github.com/rust-lang/rust/pull/136018
- "missing type for
constitem" (not really addressable unless we suggest incomplete code) - E0369 https://github.com/rust-lang/rust/pull/136315
- E0609 https://github.com/rust-lang/rust/pull/137201
- E0618 https://github.com/rust-lang/rust/pull/137201
- E0529 https://github.com/rust-lang/rust/pull/137201
- E0614 https://github.com/rust-lang/rust/pull/137201
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the E0282 suggestion handling described in this issue and the referenced rust-lang/rust#135965 pull request. Reproduce the Diesel example on the stated Rust version, then verify that the suggestion uses DB, _ rather than emitting the full query type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100