Skip to content

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

Closed
@pnkfelix

Description

@pnkfelix

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions