rust-lang / rust-lang/rust-analyzer
Missing type inference with diesel
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: rust-analyzer 0.3.2904-standalone
rustc version: rustc 1.93.0 (254b59607 2026-01-19)
editor or extension: Emacs (but also seen in other editiors)
relevant settings: None
repository link (if public, optional): (eg. rust-analyzer)
code snippet to reproduce:
use diesel::prelude::*; // diesel = { version = "2.3.9", default-features = false, features = ["sqlite"] }
mod schema {
diesel::table! {
races (id) {
id -> Binary,
competition_id -> Binary,
}
}
diesel::table! {
categories (id) {
id -> Binary,
start_id -> Binary,
}
}
diesel::table! {
participants (id) {
id -> Binary,
category_id -> Binary,
}
}
diesel::table! {
starts (id) {
id -> Binary,
race_id -> Binary,
}
}
diesel::joinable!(categories -> starts (start_id));
diesel::joinable!(participants -> categories (category_id));
diesel::joinable!(starts -> races (race_id));
diesel::allow_tables_to_appear_in_same_query!(categories, participants, races, starts,);
}
use schema::*;
fn _test(conn: &mut SqliteConnection, competition_id: &[u8]) -> QueryResult<()> {
let _participants = participants::table
.inner_join(categories::table.inner_join(starts::table.inner_join(races::table)))
.filter(races::competition_id.eq(competition_id))
.select(races::id)
.load::<Vec<u8>>(conn)?;
Ok(())
}
It seems like rust-analyzer still struggles to infer the correct type for the nested join. The relevant code compiles with rustc and also with the new trait solver, so something still seems to be not 100% correct on rust-analyzers side.
What is rather interesting is that the following join produces correct type information:
let b = participants::table.inner_join(categories::table.inner_join(starts::table));
Note that this just skips the third nested join, so there seems to be no fundamental problem with the type inference here. Maybe there is just a different limit for some sort of search depth compared to running the trait solver in rustc?
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 with the minimal Diesel reproducer in the issue and compare rust-analyzer's type information for the three-level nested join with the shorter join that works. Check the behavior against rustc and its new trait solver; done means rust-analyzer infers the correct types for the full nested join without regressing the working case.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100