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

async/await: expected type for<'r> std::ops::FnMut<(&'r std::task::Waker,)> #58639

Closed
kpp opened this Issue Feb 22, 2019 · 4 comments

Comments

Projects
None yet
4 participants
@kpp
Copy link
Contributor

kpp commented Feb 22, 2019

MRE:

futures-preview = =0.3.0-alpha.13
rustc -vV = 1.34.0-nightly (146aa60f3 2019-02-18) x86_64-unknown-linux-gnu LLVM 8.0

use futures::stream::Stream;
use core::pin::Pin;

pub async fn next<St>(stream: &mut St) -> Option<St::Item>
    where St: Stream + Unpin,
{
    use futures::future::poll_fn;
    let poll_next = |waker| Pin::new(&mut *stream).poll_next(waker);
    let future_next = poll_fn(poll_next);
    await!(future_next)
}

error[E0308]: mismatched types
  --> src/stream.rs:11:5
   |
11 |     await!(future_next)
   |     ^^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected type `for<'r> std::ops::FnMut<(&'r std::task::Waker,)>`
              found type `std::ops::FnMut<(&std::task::Waker,)>`
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.

Local fix:

- let poll_next = |waker| Pin::new(&mut *stream).poll_next(waker);
+ let poll_next = |waker: &_| Pin::new(&mut *stream).poll_next(waker);

Is it a bug?

@talchas

This comment has been minimized.

Copy link

talchas commented Feb 26, 2019

This is typical closure inference not inferring a for<'a> when being assigned to a variable rather than being directly passed to a function.

@kpp

This comment has been minimized.

Copy link
Contributor Author

kpp commented Feb 26, 2019

You are right. This one worked:

-    let poll_next = |waker: &_| Pin::new(&mut *stream).poll_next(waker);
-    let future_next = poll_fn(poll_next);
+    let future_next = poll_fn(|waker| Pin::new(&mut *stream).poll_next(waker));

Still is it a bug or a normal behavior?

@talchas

This comment has been minimized.

Copy link

talchas commented Feb 26, 2019

I'd say it's at most "feature request", and I'm sure there's an issue in here since around 1.0 for it :P

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Mar 5, 2019

Er, I'm going to close this issue, since it's (at least at present) expected behavior, and it's also not particularly related to async-await.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.