rust-lang / rust-lang/rust-analyzer
Shadowed variable is highlighted in cfg'ed out code even though it is not used there
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: 0.3.2533-standalone
rustc version: rustc 1.88.0 (6b00bc388 2025-06-23)
editor or extension: Code OSS (like vscode)
relevant settings: None
code snippet to reproduce:
pub fn f() {
if let Some(var) = Some(123) {
let var = var + 1;
#[cfg(debug_assertions)]
dbg!(var);
#[cfg(not(debug_assertions))]
let _ = var;
}
}
When the cursor is on any uses of var others are highlighted, but the use that is cfg'ed out (debug_assertions is on) highlights and is highlighted by the shadowed var, not the new let var = ... later on.
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 snippet in the issue and trace rust-analyzer's semantic highlighting and cfg handling for the shadowed var. Reproduce the highlighting with debug_assertions enabled, then verify that the cfg-disabled use no longer affects or receives the wrong binding highlight.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100