rust-lang / rust-lang/rust-analyzer

Rust-analyzer fails to autocomplete Match with diesel errors (Enum) [ video demo ]

Open
#17,215 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

Hello,

I noticed that Rust-analyzer fails to autocomplete Match with diesel errors, it can't determine the Enum of diesel::result::Error.

I've included the code that reproduces the error, as well as a video showing the error and how to fix it temporarily.


rust-analyzer version:
rust-analyzer version: 0.3.1950-standalone

rustc version:
rustc 1.78.0 (9b00956e5 2024-04-29)

editor or extension:
VSCode : Version: 1.88.1
rust-analyzer extension : v0.3.1950

video

you'll notice on the video that quick-fixes no longer works (I'll have to use some tricks to make it work)

[ sorry if the mouse is not visible on the video, probably a bug in the ubuntu recorder ]

Screencast from 2024-05-10 21-06-58.webm

code snippet to reproduce :

main.rs

mod schema;
use diesel::{prelude::*, sql_query};
use diesel::{Queryable, Selectable};
use diesel_async::pooled_connection::bb8::Pool;
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
use diesel_async::RunQueryDsl;
use serde::{Deserialize, Serialize};

#[derive(
    Serialize,
    Deserialize,
    Queryable,
    Selectable,
    Insertable,
    Identifiable,
    QueryableByName,
    AsChangeset,
)]
#[diesel(table_name = crate::schema::te_test_tst, primary_key(tst_id))]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct TestEntity {
    #[diesel(column_name = "tst_id")]
    pub id: i64,
    #[diesel(column_name = "tst_fname")]
    pub fname: Option<String>,
}

#[tokio::main]
async fn main() {
    println!("Hello, world!");

    let database_url = "postgres://xxxxxxxxxxxxxxxxxxxxxxxxxxxx";

    // create a new connection pool with the default config
    let config = AsyncDieselConnectionManager::<diesel_async::AsyncPgConnection>::new(database_url);
    let pool = Pool::builder().build(config).await.unwrap();

    // checkout a connection from the pool
    let mut connection = pool.get().await.unwrap();

    let results = match sql_query("SELECT * FROM table_test")
        .get_results::<TestEntity>(&mut connection)
        .await
    {
        Ok(r) => r,
        Err(e) => match e {}, //<------- !!!
    };
}

schema.rs

// @generated automatically by Diesel CLI.

diesel::table! {
    te_test_tst (tst_id) {
        tst_id -> Int8,
        #[max_length = 120]
        tst_fname -> Nullable<Varchar>,
    }
}

diesel::allow_tables_to_appear_in_same_query!(te_test_tst,);

Cargo.toml :

[package]
name = "diesel_test"
version = "0.1.0"
edition = "2021"

[dependencies]
diesel = { version = "2.1.6" }
diesel-async = { version = "0.4.1", features = ["postgres", "bb8"] }
serde = { version = "1.0.199", features = ["derive"] }
tokio = { version = "1.37.0", features = ["full"] }

I've also noticed that from time to time (not always, I get this error in the logs ) I don't know if it's related

2024-05-10T19:56:26.477624Z ERROR hir_ty::mir: Only tuple has tuple field
2024-05-10T19:56:26.477644Z ERROR hir_ty::mir: Only tuple has tuple field
2024-05-10T19:56:26.477653Z ERROR hir_ty::mir: Only tuple has tuple field
2024-05-10T19:56:26.479280Z ERROR hir_ty::mir: Only tuple has tuple field

I get this error only when I use diesel / diesel-async .

Thank you for your help..

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 by reproducing the autocomplete and quick-fix behavior from main.rs with the dependencies in Cargo.toml, using schema.rs as the generated Diesel schema. Compare the behavior around the Err(e) => match e arm and the reported hir_ty::mir logs. Done means rust-analyzer correctly determines diesel::result::Error variants for completion and quick-fixes in this reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.