Skip to content

Inference of argument type of async closure is broken #127468

Closed
@kriomant

Description

@kriomant

Well, it is maybe not a regression technically, because I use unstable feature. However, I wouldn't like this to get into stable channel.

Code

I tried this code:

#![feature(async_closure)]

use std::future::Future;

pub struct A {}
impl A {
    fn method(&self) {}
}

pub fn call<B, F>(f: F)
    where F: FnOnce(A) -> B, B: Future<Output=()>
{
    f(A {});
}

pub fn test() {
    call(async move |a| {
        a.method();
    });
}

I expected to see this happen: I don't have to specify type of 'a' parameter as it may be inferred from call signature.

Instead, this happened:

error[E0282]: type annotations needed
  --> src/lib.rs:18:9
   |
18 |         a.method();
   |         ^ cannot infer type

I did compiler bisection, here is the result:

searched nightlies: from nightly-2023-03-17 to nightly-2024-06-12
regressed nightly: nightly-2024-02-07
searched commit range: https://github.com/rust-lang/rust/compare/f067fd6084d750f3797f54b71771c5dbc149726f...256b6fb19a2c018eaad4806d2369d1f6a71fc6ec
regressed commit: https://github.com/rust-lang/rust/commit/4a2fe4491ea616983a0cf0cbbd145a39768f4e7a

<details>
<summary>bisected with <a href='https://github.com/rust-lang/cargo-bisect-rustc'>cargo-bisect-rustc</a> v0.6.8</summary>


Host triple: x86_64-unknown-linux-gnu
Reproduce with:
```bash
cargo bisect-rustc --start 2023-03-17 --end 2024-06-12
```

Metadata

Metadata

Assignees

No one assigned

    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