forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#125684 - estebank:pin-to-binding-suggestion, r=pnkfelix Account for existing bindings when suggesting `pin!()` When we encounter a situation where we'd suggest `pin!()`, we now account for that expression existing as part of an assignment and provide an appropriate suggestion: ``` 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 mut pinned = std::pin::pin!(self.fut); LL ~ let res = pinned.as_mut().poll(cx); | ``` Fix rust-lang#125661.
- Loading branch information
Showing
3 changed files
with
103 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 mut pinned = std::pin::pin!(self.fut); | ||
LL ~ let res = pinned.as_mut().poll(cx); | ||
| | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0599`. |