Skip to content

impl AsyncFn where AsyncFnMut is required leads to confusing internal_implementation_detail::AsyncFnKindHelper<i8> constraint requirement #140292

Closed
@dvdsk

Description

@dvdsk

Code

struct Test;

impl Test {
    async fn an_async_fn(&mut self) {
        todo!()
    }

    pub async fn uses_takes_asyncfn(&mut self) {
        takes_asyncfn(Box::new(async || self.an_async_fn().await));
    }
}

async fn takes_asyncfn(_: impl AsyncFn()) {
    todo!()
}

Current output

error[E0277]: the trait bound `i16: ops::async_function::internal_implementation_detail::AsyncFnKindHelper<i8>` is not satisfied in `{async closure@src/lib.rs:9:32: 9:40}`
  --> src/lib.rs:9:23
   |
9  |         takes_asyncfn(Box::new(async || self.an_async_fn().await));
   |         ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
   |         |
   |         required by a bound introduced by this call
   |
   = help: within `{async closure@src/lib.rs:9:32: 9:40}`, the trait `ops::async_function::internal_implementation_detail::AsyncFnKindHelper<i8>` is not implemented for `i16`
   = note: required for `Box<{async closure@src/lib.rs:9:32: 9:40}>` to implement `AsyncFn()`
note: required by a bound in `takes_asyncfn`
  --> src/lib.rs:13:32
   |
13 | async fn takes_asyncfn(_: impl AsyncFn()) {
   |                                ^^^^^^^^^ required by this bound in `takes_asyncfn`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to 1 previous error

Desired output

error[E0596]: cannot borrow `*self` as mutable, as it is a captured variable in a `Fn` closure
  --> crates/adapter/src/list.rs:38:49
   |
38 |         let coordinator_table = get_entire_list(async |start_index| {
   |                                 --------------- ^^^^^^^^^^^^^^^^^^^
   |                                 |               |
   |                                 |               cannot borrow as mutable
   |                                 |               in this closure
   |                                 expects `Fn` instead of `FnMut`

Rationale and extra context

No response

Other cases

Rust Version

rustc 1.88.0-nightly (d7ea436a0 2025-04-24)
binary: rustc
commit-hash: d7ea436a02d5de4033fcf7fd4eb8ed965d0f574c
commit-date: 2025-04-24
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Anything else?

Very similar to #137905 (which has been resolved)

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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