Add test for incorrect pinning suggestion

The following suggestion is incorrect, as it doesn't account for the binding:

```
error[E0599]: no method named `poll` found for type parameter `F` in the current scope
  --> $DIR/pin-needed-to-poll-3.rs:19:28
   |
LL | impl<F> Future for FutureWrapper<F>
   |      - method `poll` not found for this type parameter
...
LL |         let res = self.fut.poll(cx);
   |                            ^^^^ method not found in `F`
   |
help: consider pinning the expression
   |
LL ~         let res = let mut pinned = std::pin::pin!(self.fut);
LL ~         pinned.as_mut().poll(cx);
   |
```
This commit is contained in:
Esteban Küber 2024-05-28 20:05:01 +00:00
parent 8c4db851a7
commit 1a840e7732
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,25 @@
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);
//~^ ERROR no method named `poll` found for type parameter `F` in the current scope
res
}
}
fn main() {}

View File

@ -0,0 +1,18 @@
error[E0599]: no method named `poll` found for type parameter `F` in the current scope
--> $DIR/pin-needed-to-poll-3.rs:19:28
|
LL | impl<F> Future for FutureWrapper<F>
| - method `poll` not found for this type parameter
...
LL | let res = self.fut.poll(cx);
| ^^^^ method not found in `F`
|
help: consider pinning the expression
|
LL ~ let res = let mut pinned = std::pin::pin!(self.fut);
LL ~ pinned.as_mut().poll(cx);
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0599`.