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

Confusing error message on error [E0599] #66289

Closed
Razican opened this issue Nov 11, 2019 · 2 comments
Closed

Confusing error message on error [E0599] #66289

Razican opened this issue Nov 11, 2019 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Razican
Copy link
Contributor

Razican commented Nov 11, 2019

Hi!
I was doing some work with async_std when I got a confusing error message. With this minimal code:

use async_std::{stream::Stream, task::Poll};

pub fn test_poll_next<F, T>(first: F) -> Poll<Option<T>>
where
    F: Stream<Item = T>,
{
    first.poll_next()
}

I got this error:

error[E0599]: no method named `poll_next` found for type `F` in the current scope
 --> src/lib.rs:7:11
  |
7 |     first.poll_next()
  |           ^^^^^^^^^ method not found in `F`
  |
  = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following traits define an item `poll_next`, perhaps you need to restrict type parameter `F` with one of them:
  |
3 | pub fn test_poll_next<F: futures_core::stream::Stream, T>(first: F) -> Poll<Option<T>>
  |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 | pub fn test_poll_next<F: futures_core::stream::Stream, T>(first: F) -> Poll<Option<T>>
  |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

If I follow the suggestion, import futures_core and so on, I get the following error message:

error[E0599]: no method named `poll_next` found for type `F` in the current scope
 --> src/lib.rs:7:11
  |
7 |     first.poll_next()
  |           ^^^^^^^^^ method not found in `F`
  |
  = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following traits define an item `poll_next`, perhaps you need to restrict type parameter `F` with one of them:
  |
3 | pub fn test_poll_next<F: futures_core::stream::Stream + futures_core::stream::Stream, T>(first: F) -> Poll<Option<T>>
  |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 | pub fn test_poll_next<F: futures_core::stream::Stream + futures_core::stream::Stream, T>(first: F) -> Poll<Option<T>>
  |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Which seems to be redundant. So, this seems not to be the issue I'm facing. What is really happening here?

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 11, 2019
@TimoFreiberg
Copy link
Contributor

The error message is not that helpful, but the problem is that poll_next takes a Pin<&mut Self>, not a Self.

Adding the unstable feature and changing the function signature to

fn test_poll_next<F,T>(first: Pin<&mut F>) -> Poll<Option<T>> 
where
    F: Stream<Item = T>
{
    first.poll_next()
}

, I get the following error:

error[E0061]: this function takes 1 parameter but 0 parameters were supplied
  --> src/main.rs:11:11
   |
11 |     first.poll_next()
   |           ^^^^^^^^^ expected 1 parameter

error: aborting due to previous error

For more information about this error, try `rustc --explain E0061`.
error: could not compile `test-66289`.

To learn more, run the command again with --verbose.

Which makes sense as poll_next also takes a &mut Context argument.

@estebank estebank added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Nov 14, 2019
@nagisa
Copy link
Member

nagisa commented Feb 18, 2020

Duplicate of #65149

@nagisa nagisa marked this as a duplicate of #65149 Feb 18, 2020
@nagisa nagisa closed this as completed Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants