Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rxdiscovery opened this issue May 10, 2024 · 1 comment
Labels
C-bug Category: bug

Comments

@rxdiscovery
Copy link

rxdiscovery commented May 10, 2024

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..

@weiznich
Copy link
Contributor

Likely a duplicate of #14607

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants