rust-lang / rust-lang/rust-analyzer

Missing type inference with diesel

Open
#22,402 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-ty C-bug
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(())
}

Image

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));
Image

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.