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

Missing method errors using AsyncRead #1536

Closed
chmln opened this issue Apr 18, 2019 · 4 comments
Closed

Missing method errors using AsyncRead #1536

chmln opened this issue Apr 18, 2019 · 4 comments

Comments

@chmln
Copy link
Contributor

chmln commented Apr 18, 2019

This may not be the correct place to post this, but I am running into weird errors trying to use AsyncRead.

Here is a narrowed down snippet illustrating the error (also uploaded at https://github.com/chmln/fut-err):

use futures;

pub struct LineStream<T: futures::io::AsyncRead> {
    inner: T,
}

impl<T: futures::io::AsyncRead> LineStream<T> {
    pub fn new(inner: T) -> Self {
        inner.poll_read();
        Self { inner }
    }
}

Error:

error[E0599]: no method named `poll_read` found for type `T` in the current scope
 --> src/main.rs:9:15
  |
9 |         inner.poll_read();
  |               ^^^^^^^^^
  |
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `poll_read`, perhaps you need to implement it:
          candidate #1: `futures_io::if_std::AsyncRead`

error: aborting due to previous error

Based on the suggestion I've tried adding std and nightly feature flags but that did not help either.

Extra Info:

$ rustc +nightly --version
rustc 1.36.0-nightly (3c3d3c177 2019-04-17)
[dependencies]
futures-preview = { version = "0.3.0-alpha.14" }
@Nemo157
Copy link
Member

Nemo157 commented Apr 18, 2019

This is because poll_read takes self: Pin<&mut Self>, you need to explicitly wrap inner into a pinned reference (unlike &mut self etc. this is not done automatically by Rust):

core::pin::Pin::new(&mut inner).poll_read(unimplemented!(), unimplemented!());

This is a pretty terrible error message for forgetting that though, I'll make sure there's an upstream issue about improving the error message to mention the expected type.

@taiki-e
Copy link
Member

taiki-e commented Apr 18, 2019

This is a pretty terrible error message for forgetting that though, I'll make sure there's an upstream issue about improving the error message to mention the expected type.

rust-lang/rust#59269

EDIT: Oh, I was thinking about the compiler mentioning private modules, but it's really great to improve arbitrary self types' error message.

@Nemo157
Copy link
Member

Nemo157 commented Apr 18, 2019

Opened rust-lang/rust#60086

@chmln
Copy link
Contributor Author

chmln commented Apr 18, 2019

Thanks for clearing that up @Nemo157 👍

@chmln chmln closed this as completed Apr 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants