Skip to content

impl AsyncFn inference error leaks confusing internal_implementation_detail::AsyncFnKindHelper trait constraint requirement #137905

Closed
@parasyte

Description

@parasyte

Minimal repro:

pub fn repro(foo: impl Into<bool>) -> impl AsyncFn() {
    let inner_fn = async move || {
        let _ = foo.into();
    };
    inner_fn
}

Error message:

error[E0277]: the trait bound `i32: ops::async_function::internal_implementation_detail::AsyncFnKindHelper<i8>` is not satisfied
 --> src/lib.rs:1:39
  |
1 | pub fn repro(foo: impl Into<bool>) -> impl AsyncFn() {
  |                                       ^^^^^^^^^^^^^^ the trait `ops::async_function::internal_implementation_detail::AsyncFnKindHelper<i8>` is not implemented for `i32`

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1417c51240bb454a094b23c524191862

Changing the code to directly return the async closure instead of binding it to a variable produces a more reasonable (but still not ideal) error message:

error[E0507]: cannot move out of `foo` which is behind a shared reference
 --> src/lib.rs:2:5
  |
2 |     async move || {
  |     ^^^^^^^^^^^^^ `foo` is moved here
3 |         let _ = foo.into();
  |                 ---
  |                 |
  |                 variable moved due to use in coroutine
  |                 move occurs because `foo` has type `impl Into<bool>`, which does not implement the `Copy` trait
  |
help: if `impl Into<bool>` implemented `Clone`, you could clone the value
 --> src/lib.rs:1:19
  |
1 | pub fn repro(foo: impl Into<bool>) -> impl AsyncFn() {
  |                   ^^^^^^^^^^^^^^^ consider constraining this type parameter with `Clone`
2 |     async move || {
3 |         let _ = foo.into();
  |                 --- you could clone this value

This issue was originally reported on URLO: https://users.rust-lang.org/t/interesting-issue-with-new-async-closures-with-very-cryptic-error-message/126470

Meta

rustc --version --verbose:

rustc 1.85.0 (4d91de4e4 2025-02-17)
binary: rustc
commit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688
commit-date: 2025-02-17
host: x86_64-pc-windows-msvc
release: 1.85.0
LLVM version: 19.1.7

Metadata

Metadata

Labels

C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions