rust-lang / rust-lang/rust-analyzer
VSCode plugin does not suggest auto-import quick fix for enum-variant when `cargo check` does
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
I have a minimal-ish reproducible example:
enum Enum {
One,
Two,
}
fn main() {
let a = One;
}
Results in no available quick-fixes:
If there was a pub fn or pub struct named One in a pub module, a quick-fix to import it would appear
Expected behaviour: have a quick fix to add an import of the enum variant.
rust-analyzer version: 0.4.1590-standalone (d82451103 2023-07-16)
rustc version: rustc 1.71.0 (8ede3aae2 2023-07-12)
relevant settings: all other vscode extensions disabled, only default settings for rust-analyzer
I would also like to note that the plugin in general is very slow in suggesting quick-fixes, especially related to adding missing imports, but that is probably somewhat unrelated. In general I would expect the plugin to show a quick fix if it can show the import-help from cargo check.
This is extra confusing if it happens in an `impl Trait` with default trait impls, which has the wrong quick-fix available
mod Mod {
pub enum Enum {
One,
Two,
}
}
use Mod::Enum;
struct S();
impl A for S {
const OPT: &'static Enum = &One;
}
trait A {
const OPT: &'static Enum;
fn funky() {
println!("oh no");
}
}
Here cargo check reports the following:
error[E0425]: cannot find value `One` in this scope
--> src/main.rs:13:32
|
13 | const OPT: &'static Enum = One;
| ^^^ not found in this scope
|
help: consider importing this unit variant
|
8 + use crate::Enum::One;
|
For more information about this error, try `rustc --explain E0425`.
Which it appears the extension catches:
But the quick fix it suggests is only related to implementing the default trait member funky. Applying the quick fix will correctly add a copy of the original implementation of the trait member funky to the impl for S.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal Rust reproduction and compare the cargo check import suggestion with the VSCode plugin's available quick fixes. Trace how rust-analyzer handles the diagnostic and chooses fixes for the unresolved enum variant. Done means the enum-variant import quick fix is offered and the incorrect trait-member fix does not replace it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, vscode
- Domain
- developer-experience, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100