Skip to content

[ide-diagnostics] unused-variables false-positive #20254

@jhgg

Description

@jhgg

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 (f73ce3c 2025-07-17)

rustc version: rustc 1.89.0-nightly (99e7c15 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 {}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions