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 not general enough" with async and projection, fixed by wrapping with async move #110339

Open
Tracked by #110338
tmandry opened this issue Apr 14, 2023 · 0 comments
Labels
A-async-await Area: Async & Await A-coroutines Area: Coroutines AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. 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.

Comments

@tmandry
Copy link
Member

tmandry commented Apr 14, 2023

Another instance of #110338 (pretty similar to #71723 I guess). Code sample:

pub fn serve() -> impl Future<Output = ()> + Send {
    async move {
        let netstack = Foo;
        let stream = futures::stream::iter(vec![]);
        let work_items_fut =
            // async move {
                stream.for_each(|()| async {
                    let _ns = netstack.clone();
                })
            // .await }
        ;

        let mut _fut0 = MaybeDone::Future(work_items_fut);
        let mut _fut0 = unsafe { core::pin::Pin::new_unchecked(&mut _fut0) };
        _fut0.await
    }
}

playground

error: implementation of `std::marker::Send` is not general enough
  --> src/lib.rs:24:5
   |
24 | /     async move {
25 | |         let netstack = Foo;
26 | |         let stream = futures::stream::iter(vec![]);
27 | |         let work_items_fut =
...  |
38 | |         _fut0.await
39 | |     }
   | |_____^ implementation of `std::marker::Send` is not general enough
   |
   = note: `std::marker::Send` would have to be implemented for the type `&'0 Foo`, for any lifetime `'0`...
   = note: ...but `std::marker::Send` is actually implemented for the type `&'1 Foo`, for some specific lifetime `'1`

error[[E0308]](https://doc.rust-lang.org/stable/error_codes/E0308.html): mismatched types
  --> src/lib.rs:24:5
   |
24 | /     async move {
25 | |         let netstack = Foo;
26 | |         let stream = futures::stream::iter(vec![]);
27 | |         let work_items_fut =
...  |
38 | |         _fut0.await
39 | |     }
   | |_____^ one type is more general than the other
   |
   = note: expected `async` block `[async block@src/lib.rs:29:38: 31:18]`
              found `async` block `[async block@src/lib.rs:29:38: 31:18]`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to 2 previous errors

What's interesting about this one to me is that uncommenting the commented lines (wrapping in an async move) removes the error.

The projection type being in MaybeDone is load-bearing, so I suspect something like #92449 would have fixed this.

@tmandry tmandry added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-coroutines Area: Coroutines A-async-await Area: Async & Await T-types Relevant to the types team, which will review and decide on the PR/issue. labels Apr 14, 2023
@tmandry tmandry added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Apr 24, 2023
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-coroutines Area: Coroutines AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. 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.
Projects
None yet
Development

No branches or pull requests

1 participant