Skip to content
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

Implementation of FnOnce is not general enough for Flatten iterator of futures outliving an .await point #98380

Open
Veetaha opened this issue Jun 22, 2022 · 1 comment
Labels
A-async-await Area: Async & Await A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue. WG-async Working group: Async & await

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Jun 22, 2022

I tried this code:

let _: &(dyn Future<Output = ()> + Send) = &async {
    let _drop_after_await = std::iter::empty()
        .map(|_: &()| [async {}])
        .flatten();

    async {}.await;
};

Playground link

I expected that the code should compile without errors.

However, it produces a compile error:

error: implementation of `FnOnce` is not general enough
  --> src/main.rs:4:48
   |
4  |       let _: &(dyn Future<Output = ()> + Send) = &async {
   |  ________________________________________________^
5  | |         let _drop_after_await = std::iter::empty()
6  | |             .map(|_: &()| [async {}])
7  | |             .flatten();
8  | |
9  | |         async {}.await;
10 | |     };
   | |_____^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'0 ()) -> [impl Future<Output = ()>; 1]` must implement `FnOnce<(&'1 (),)>`, for any two lifetimes `'0` and `'1`...
   = note: ...but it actually implements `FnOnce<(&(),)>`

The bug doesn't reproduce if we remove the Send requirement or .flatten() combinator 🤔.

Meta

rustc -V:

rustc 1.61.0 (fe5b13d68 2022-05-18)
@Veetaha Veetaha added the C-bug Category: This is a bug. label Jun 22, 2022
@fmease fmease added A-lifetimes Area: Lifetimes / regions T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-async-await Area: Async & Await T-types Relevant to the types team, which will review and decide on the PR/issue. A-trait-system Area: Trait system and removed needs-triage-legacy labels Jan 26, 2024
@traviscross
Copy link
Contributor

@rustbot labels +AsyncAwait-Triaged +WG-async

We reviewed this today in WG-async triage.

We believe this is a manifestation of what's being worked on and tracked in #110338.

@rustbot rustbot added AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. WG-async Working group: Async & await labels Feb 26, 2024
@fmease fmease added A-trait-system Area: Trait system and removed A-trait-system Area: Trait system labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue. WG-async Working group: Async & await
Projects
None yet
Development

No branches or pull requests

5 participants