rust-lang / rust-lang/rust-analyzer

[ide-diagnostics] unused-variables false-positive

Open
#20,254 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-mir C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

In the provided code-snippet, store is diagnosed as an unused variable by rust-analyzer, but not by rustc.

rust-analyzer version: 0.4.2543-standalone (f73ce3c8a8 2025-07-17)

rustc version: rustc 1.89.0-nightly (99e7c15e8 2025-06-01)

editor or extension: VSCode

repository link (if public, optional): (eg. rust-analyzer)

code snippet to reproduce:

use std::any::Any;

fn main() {
    let store = make();
    //  ^^^^^ unused-variable
    bar(|| foo(store));
    // bar(|| drop(store)) // does not reproduce here.
    // foo(store) // does not reproduce here, either.
}

fn foo(_: Box<dyn Any>) {}
fn bar(_: impl FnOnce()) {}
fn make() -> Box<dyn Any> {
    loop {}
}

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 provided Rust snippet in rust-analyzer using the reported rust-analyzer, rustc, and VSCode versions. Trace why the closure call bar(|| foo(store)) produces an unused-variable diagnostic while the shown drop and direct-call variants do not; done means the false-positive is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.