rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.05k stars 1.56k forks source link

Auto find correct trait for missing functions for structs #17311

Closed kodmanyagha closed 2 weeks ago

kodmanyagha commented 3 months ago

Hi, I have an important question. We need import some traits for activating some functions. Let me explain the situation with an example. Let us look that code:

let result = sqlx::query("SELECT * FROM users").fetch_all(&pool).await?;
let result = result
    .iter()
    .enumerate()
    .map(|(index, row)| {
        // In here I'm getting error because I didn't import `sqlx::Row` crate on the top
        let id: i32 = row.get(0);
        id
    })
    .collect::<Vec<i32>>();

When I add use sqlx::Row; myself on the top than I can use get() function. So my question is that: why rust-analyzer doesn't suggest the correct trait. Isn't it possible finding the correct trait? Thanks.

davidbarsky commented 3 months ago

What version of rust-analyzer are you using? This should be working properly if you're using Monday's release.