forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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#83667 - estebank:cool-bears-hot-tip, r=lcnr
Suggest box/pin/arc ing receiver on method calls _Extracted from https://fasterthanli.me/articles/pin-and-suffering_
- Loading branch information
Showing
20 changed files
with
179 additions
and
161 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
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
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,47 @@ | ||
use std::{ | ||
future::Future, | ||
pin::Pin, | ||
task::{Context, Poll}, | ||
}; | ||
|
||
struct Sleep; | ||
|
||
impl Future for Sleep { | ||
type Output = (); | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
Poll::Ready(()) | ||
} | ||
} | ||
|
||
impl Drop for Sleep { | ||
fn drop(&mut self) {} | ||
} | ||
|
||
fn sleep() -> Sleep { | ||
Sleep | ||
} | ||
|
||
|
||
struct MyFuture { | ||
sleep: Sleep, | ||
} | ||
|
||
impl MyFuture { | ||
fn new() -> Self { | ||
Self { | ||
sleep: sleep(), | ||
} | ||
} | ||
} | ||
|
||
impl Future for MyFuture { | ||
type Output = (); | ||
|
||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
self.sleep.poll(cx) | ||
//~^ ERROR no method named `poll` found for struct `Sleep` in the current scope | ||
} | ||
} | ||
|
||
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,22 @@ | ||
error[E0599]: no method named `poll` found for struct `Sleep` in the current scope | ||
--> $DIR/pin-needed-to-poll.rs:42:20 | ||
| | ||
LL | struct Sleep; | ||
| ------------- method `poll` not found for this | ||
... | ||
LL | self.sleep.poll(cx) | ||
| ^^^^ method not found in `Sleep` | ||
| | ||
::: $SRC_DIR/core/src/future/future.rs:LL:COL | ||
| | ||
LL | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>; | ||
| ---- the method is available for `Pin<&mut Sleep>` here | ||
| | ||
help: consider wrapping the receiver expression with the appropriate type | ||
| | ||
LL | Pin::new(&mut self.sleep).poll(cx) | ||
| ^^^^^^^^^^^^^ ^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0599`. |
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
Oops, something went wrong.