rust-lang / rust-lang/rust

Can't convert async closure to a function pointer

Open
#149,339 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-async-closures C-bug T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=d54c26bc3a2ed018b18251d24faf4cce

pub fn f<F>(_f: fn() -> F) {}

pub fn g() {
    f(async || {});
}

I expected to see this happen: successfully compile with F being the future type returned by the async closure.

Instead, this happened:

error[E0308]: mismatched types
 --> src/lib.rs:4:7
  |
4 |     f(async || {});
  |     - ^^^^^^^^^^^ expected fn pointer, found `{async closure@lib.rs:4:7}`
  |     |
  |     arguments to this function are incorrect
  |
  = note: expected fn pointer `fn() -> _`
                found closure `{async closure@src/lib.rs:4:7: 4:15}`
Meta

rustc --version --verbose:

1.93.0-nightly

(2025-11-24 c871d09d1cc32a649f4c)

@rustbot label +A-async-closures

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 with the linked Rust Playground reproduction and compare the async closure argument with the declared fn() -> F parameter. Investigate why the closure is rejected as a function pointer, then confirm the intended behavior with a focused compiler test; done means the reported example compiles with the expected future type or produces the correct, documented diagnostic.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.