Skip to content

Diagnostics incorrectly states that async closure implements Fn. #148391

@theemathas

Description

@theemathas

Code

fn main() {
    let a = 0;
    async move || {
        require_static(&a);
    };
}

fn require_static(_: &'static i32) {}

Current output

error: lifetime may not live long enough
 --> src/main.rs:3:19
  |
3 |       async move || {
  |  _____-------------_^
  | |     |
  | |     lifetime `'1` represents this closure's body
4 | |         require_static(&a);
5 | |     };
  | |_____^ returning this value requires that `'1` must outlive `'static`
  |
  = note: closure implements `Fn`, so references to captured variables can't escape the closure

Desired output

Rationale and extra context

This async closure does not implement Fn.

Other cases

Rust Version

Reproducible on the playground with version 1.93.0-nightly (2025-11-01 bd3ac0330018c23b111b)

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-async-closures`async || {}`A-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions