Closed
Description
Code
When polling future from a wrapping future, the error message when forgetting to pin the wrapped future is wrong. Take this as an example (playground):
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
struct FutureWrapper<F> {
fut: F,
}
impl<F> Future for FutureWrapper<F>
where
F: Future,
{
type Output = F::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let res = self.fut.poll(cx);
res
}
}
Current output
The error is wrong because of the double let: let res = let mut pinned = std::pin::pin!(self.fut);
.
error[E0599]: no method named `poll` found for type parameter `F` in the current scope
--> src/lib.rs:18:28
|
11 | impl<F> Future for FutureWrapper<F>
| - method `poll` not found for this type parameter
...
18 | let res = self.fut.poll(cx);
| ^^^^ method not found in `F`
|
help: consider pinning the expression
|
18 ~ let res = let mut pinned = std::pin::pin!(self.fut);
19 ~ pinned.as_mut().poll(cx);
|
For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` (lib) due to 1 previous error
Desired output
error[E0599]: no method named `poll` found for type parameter `F` in the current scope
--> src/lib.rs:18:28
|
11 | impl<F> Future for FutureWrapper<F>
| - method `poll` not found for this type parameter
...
18 | let res = self.fut.poll(cx);
| ^^^^ method not found in `F`
|
help: consider pinning the expression
|
18 ~ let mut pinned = std::pin::pin!(self.fut);
19 ~ let res = pinned.as_mut().poll(cx);
|
For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` (lib) due to 1 previous error
Rationale and extra context
No response
Other cases
No response
Rust Version
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2
Anything else?
Credit to @skade for discovering the bug.