Bad diagnostic on type mismatch for associated type requirements
Open
Nobody has claimed this yet.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
Code
use diesel::prelude::*; // 2.1.6 without any features
table! {
users {
id -> Integer,
name -> Text,
}
}
table! {
posts {
id -> Integer,
title -> Text,
user_id -> Integer,
}
}
fn main() {
let sub_query = posts::table.find(42).select(posts::user_id).single_value();
let user_query = users::table.filter(users::id.eq(sub_query));
}
Current output
error[E0271]: type mismatch resolving `<Grouped<Subselect<SelectStatement<FromClause<table>, SelectClause<user_id>, NoDistinctClause, WhereClause<Grouped<Eq<..., ...>>>, ..., ...>, ...>> as Expression>::SqlType == Integer`
--> src/main.rs:21:52
|
21 | let user_query = users::table.filter(users::id.eq(sub_query));
| ^^ expected `Nullable<Integer>`, found `Integer`
|
= note: expected struct `Nullable<diesel::sql_types::Integer>`
found struct `diesel::sql_types::Integer`
= note: required for `Grouped<Subselect<SelectStatement<FromClause<table>, SelectClause<user_id>, ..., ..., ..., ...>, ...>>` to implement `AsExpression<diesel::sql_types::Integer>`
= note: the full name for the type has been written to '/tmp/diesel_bad_diagnostic/target/debug/deps/diesel_bad_diagnostic-98b497cf8fd64c49.long-type-7298064120992293895.txt'
= note: consider using `--verbose` to print the full type name to the console
Desired output
error[E0271]: type mismatch resolving `<Grouped<Subselect<SelectStatement<FromClause<table>, SelectClause<user_id>, NoDistinctClause, WhereClause<Grouped<Eq<..., ...>>>, ..., ...>, ...>> as Expression>::SqlType == Integer`
--> src/main.rs:21:52
|
21 | let user_query = users::table.filter(users::id.eq(sub_query));
| ^^^^^^^^^ ^^^^^^^^
| `Integer` `Nullable<Integer>`
|
= note: expected struct `Nullable<diesel::sql_types::Integer>`
found struct `diesel::sql_types::Integer`
= note: required for `Grouped<Subselect<SelectStatement<FromClause<table>, SelectClause<user_id>, ..., ..., ..., ...>, ...>>` to implement `AsExpression<diesel::sql_types::Integer>`
= note: the full name for the type has been written to '/tmp/diesel_bad_diagnostic/target/debug/deps/diesel_bad_diagnostic-98b497cf8fd64c49.long-type-7298064120992293895.txt'
= note: consider using `--verbose` to print the full type name to the console
Rationale and extra context
It's currently not obviously clear which type is used for which part of the expression. For the presented case it would much easier for users to understand what's wrong if they could see which side of the expression has which type.
Other cases
No response
Rust Version
$ rustc +nightly --version --verbose
rustc 1.80.0-nightly (6e1d94708 2024-05-10)
binary: rustc
commit-hash: 6e1d94708a0a4a35ca7e46c6cac98adf62fe800e
commit-date: 2024-05-10
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4
Anything else?
No response
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
Reproduce the diagnostic using the Rust code shown in src/main.rs and the stated nightly compiler version, then compare the current and desired outputs. Done means the mismatch diagnostic clearly labels the two expression sides with Integer and Nullable as shown.
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
- 35/100