rust-lang / rust-lang/rust-analyzer

stale diagnostic after panic

Open
#18,732 6 comments 2 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

Very weird - basic code reporting a Syntax error, but it runs fine via Cargo run :)

rust-analyzer version: rust-analyzer version: 0.3.2220-standalone (27e824fad4 2024-12-15) [c:\Users\robertc.vscode\extensions\rust-lang.rust-analyzer-0.3.2220-win32-x64\server\rust-analyzer.exe]

rustc version: rustc 1.83.0 (90b35a623 2024-11-26)

editor or extension: VSCode Version 0.3.2220

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

rustup show
$ rustup show
Default host: x86_64-pc-windows-msvc
rustup home:  C:\Users\robertc\.rustup

...

installed targets for active toolchain
--------------------------------------

x86_64-pc-windows-msvc
x86_64-unknown-linux-gnu

active toolchain
----------------

stable-x86_64-pc-windows-msvc (default)
rustc 1.83.0 (90b35a623 2024-11-26)

code snippet to reproduce:

use std::collections::HashMap;

use crate::eval::Value;

pub struct Environment {
    values: HashMap<String, Value>,
}

impl Environment {
    pub fn new() -> Self {
        Self {
            values: HashMap::new(),
        }
    }

    pub fn define(&mut self, name: String, value: Value) {
        self.values.insert(name, value);
    }

    pub fn get(&self, name: &str) -> Result<Value, Box<dyn std::error::Error>> {
        self.values
            .get(name)
            .cloned()
            .ok_or_else(|| format!("Undefined variable {name}").into())
    }
}

Reports these problems:

[{
	"resource": "/c:/Users/robertc/Documents/src/codecrafters-interpreter-rust/src/environment.rs",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": {
		"value": "syntax-error",
		"target": {
			"$mid": 1,
			"path": "/stable/reference/",
			"scheme": "https",
			"authority": "doc.rust-lang.org"
		}
	},
	"severity": 8,
	"message": "Syntax Error: expected a block",
	"source": "rust-analyzer",
	"startLineNumber": 17,
	"startColumn": 16,
	"endLineNumber": 17,
	"endColumn": 16
}]

and

[{
	"resource": "/c:/Users/robertc/Documents/src/codecrafters-interpreter-rust/src/environment.rs",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": {
		"value": "E0308",
		"target": {
			"$mid": 1,
			"path": "/stable/error_codes/E0308.html",
			"scheme": "https",
			"authority": "doc.rust-lang.org"
		}
	},
	"severity": 8,
	"message": "expected String, found &str",
	"source": "rust-analyzer",
	"startLineNumber": 18,
	"startColumn": 28,
	"endLineNumber": 18,
	"endColumn": 32
}]

Image

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 report with the provided src/environment.rs snippet in rust-analyzer and compare its diagnostics with Cargo run. Investigate why the syntax and E0308 diagnostics remain after the reported panic or recovery point. Done means the stale diagnostics no longer appear for this reproduction, with a regression test added if the relevant test location is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.