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

Calling poll on an impl Future should suggest pinning. #108572

Closed
pnkfelix opened this issue Feb 28, 2023 · 4 comments
Closed

Calling poll on an impl Future should suggest pinning. #108572

pnkfelix opened this issue Feb 28, 2023 · 4 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pnkfelix
Copy link
Member

pnkfelix commented Feb 28, 2023

Code

use std::future::Future;
fn foo() -> impl Future<Output=()> {
    async { }
}

fn main() {
    let fut = foo();
    fut.poll()
}

Current output

error[E0599]: no method named `poll` found for opaque type `impl Future<Output = ()>` in the current scope
 --> src/main.rs:8:9
  |
8 |     fut.poll()
  |         ^^^^ method not found in `impl Future<Output = ()>`

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

Desired output

error[E0599]: no method named `poll` found for opaque type `impl Future<Output = ()>` in the current scope
 --> src/main.rs:8:9
  |
8 |     fut.poll()
  |         ^^^^ method not found in `impl Future<Output = ()>`

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

NOTE: Method `poll` found on `impl Future<Output = ()>` for `Pin<&mut Self>`. Please see documentation for `std::pin::Pin`.

Rationale and extra context

Someone who is just playing around based on the types and the rustdoc output is very likely to be confused by the current compiler error, because its easy to overlook the effect of Pin<&mut Self> as the receiver type for poll on std::future::Future. We can do a better job of gradually guiding the developer to the right solution, or at least push them towards the right solution space.

Other cases

No response

Anything else?

No response

@pnkfelix pnkfelix added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 28, 2023
@pnkfelix
Copy link
Member Author

Pointing the user at std::pin::Pin struck me as the most natural solution given the signature (i.e. Pin<&mut Self>), but we could also provide a more tailored answer that points users at the async-book or some other resource entirely.

My guess, however, is that this is a general problem one might encounter with generalized Self in the receiver, and so we should thinking about how to tackle that general problem as well.

@Ezrashaw
Copy link
Contributor

Ezrashaw commented Mar 2, 2023

Is there a preferred message for .poll() on impl Future? Should we redirect them to async docs and/or tell them to pin it?

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 7, 2023
…ture, r=petrochenkov

feat: impl better help for `.poll()` not found on `impl Future`

Partially address rust-lang#108572

I'd like to also address suggestions for generalized `Self` parameters as well. That'll be a separate PR.
JohnTitor added a commit to JohnTitor/rust that referenced this issue Mar 7, 2023
…ture, r=petrochenkov

feat: impl better help for `.poll()` not found on `impl Future`

Partially address rust-lang#108572

I'd like to also address suggestions for generalized `Self` parameters as well. That'll be a separate PR.
@Ezrashaw
Copy link
Contributor

Ezrashaw commented Mar 8, 2023

Note that the main part of this issue has been fixed. However, suggestions for generalized self parameters has not been fixed. I'll work on this at some point but if someone else wants to take it up then do so.

@Ezrashaw
Copy link
Contributor

@pnkfelix Turns out that suggestions for this have always been around; this issue can be closed.

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 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

3 participants