rust-lang / rust-lang/rust-analyzer

False String/str mismatch in diesel-async query with four joins

Open
#23,396 0 comments 0 reactions 0 assignees View on GitHub

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: 0.3.3049-standalone (682a84e95b 2026-09-13)

rustc version: 1.95.0 (59807616e 2026-04-14)

editor or extension: CLI (rust-analyzer diagnostics .)

relevant settings: Default

cargo check --locked succeeds. rust-analyzer diagnostics . reports E0282 on the query and E0308 (expected String, found str) at Ok(value). The value should be String, as specified by .first::<String>(conn).

code snippet to reproduce:

Cargo.toml:

[package]
name = "diesel-ra-inference-repro"
version = "0.1.0"
edition = "2024"

[dependencies]
diesel = { version = "=2.3.13", default-features = false, features = ["mysql_backend"] }
diesel-async = { version = "=0.9.2", default-features = false, features = ["mysql"] }

src/lib.rs:

use diesel::prelude::*;
use diesel_async::{AsyncMysqlConnection, RunQueryDsl};

diesel::table! { a (id) { id -> Integer, name -> Text, } }
diesel::table! { b (id) { id -> Integer, } }
diesel::table! { c (id) { id -> Integer, } }
diesel::table! { d (id) { id -> Integer, } }
diesel::table! { e (id) { id -> Integer, } }
diesel::allow_tables_to_appear_in_same_query!(a, b, c, d, e);

pub async fn query(conn: &mut AsyncMysqlConnection) -> QueryResult<String> {
    let value = a::table
        .inner_join(b::table.on(a::id.eq(b::id)))
        .inner_join(c::table.on(a::id.eq(c::id)))
        .inner_join(d::table.on(a::id.eq(d::id)))
        .inner_join(e::table.on(a::id.eq(e::id)))
        .select(a::name)
        .first::<String>(conn)
        .await?;
    let _: &str = &value;
    Ok(value)
}

Removing the last join eliminates both diagnostics. Adding : String to let value removes E0308 but leaves E0282.

Related: #22402.

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 Cargo.toml and src/lib.rs reproduction, then run cargo check --locked and rust-analyzer diagnostics . to compare the results. Investigate the diagnostics around the four-join query and the first::(conn) call; done means the valid query no longer produces E0282 or the false String/str mismatch.

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
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.