rust-lang / rust-lang/rust-analyzer
[ide-diagnostics] unused-variables false-positive
Nobody has claimed this yet.
- 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
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 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