Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dvdsk opened this issue Apr 25, 2025 · 0 comments · Fixed by #140318
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dvdsk
Copy link
Contributor

dvdsk commented Apr 25, 2025

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)

@dvdsk dvdsk added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 25, 2025
@traviscross traviscross added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue C-bug Category: This is a bug. labels Apr 25, 2025
@compiler-errors compiler-errors self-assigned this Apr 26, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 26, 2025
…fn-kind-err, r=fee1-dead

Simply try to unpeel AsyncFnKindHelper goal in `emit_specialized_closure_kind_error`

Tweak the handling of `AsyncFnKindHelper` goals in `emit_specialized_closure_kind_error` to not be so special-casey, and just try to unpeel one or two layers of obligation causes to get to their underlying `AsyncFn*` goal.

Fixes rust-lang#140292
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 26, 2025
…fn-kind-err, r=fee1-dead

Simply try to unpeel AsyncFnKindHelper goal in `emit_specialized_closure_kind_error`

Tweak the handling of `AsyncFnKindHelper` goals in `emit_specialized_closure_kind_error` to not be so special-casey, and just try to unpeel one or two layers of obligation causes to get to their underlying `AsyncFn*` goal.

Fixes rust-lang#140292
@bors bors closed this as completed in 443358d Apr 26, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 26, 2025
Rollup merge of rust-lang#140318 - compiler-errors:specialized-async-fn-kind-err, r=fee1-dead

Simply try to unpeel AsyncFnKindHelper goal in `emit_specialized_closure_kind_error`

Tweak the handling of `AsyncFnKindHelper` goals in `emit_specialized_closure_kind_error` to not be so special-casey, and just try to unpeel one or two layers of obligation causes to get to their underlying `AsyncFn*` goal.

Fixes rust-lang#140292
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
3 participants