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.
Auto merge of rust-lang#105328 - matthiaskrgr:rollup-qnfksmq, r=matth…
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#104912 (PartialEq: PERs are homogeneous) - rust-lang#104952 (Streamline the user experience for `x.py setup`) - rust-lang#104953 (Ensure required submodules at the same time as updating existing submodules) - rust-lang#105180 (Use proper HirId for async track_caller attribute check) - rust-lang#105222 (std update libc version and freebsd image build dependencies) - rust-lang#105223 (suggest parenthesis around ExprWithBlock BinOp ExprWithBlock) - rust-lang#105230 (Skip recording resolution for duplicated generic params.) - rust-lang#105301 (update Miri) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
5 changed files
with
117 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
cef44f53034eac46be3a0e3eec7b2b3d4ef5140b | ||
203c8765ea33c65d888febe0e8219c4bb11b0d89 |
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
17 changes: 0 additions & 17 deletions
17
tests/fail/stacked_borrows/notunpin_dereferenceable_fakeread.rs
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
tests/fail/stacked_borrows/notunpin_dereferenceable_fakeread.stderr
This file was deleted.
Oops, something went wrong.
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,102 @@ | ||
#![feature(pin_macro)] | ||
|
||
use std::future::*; | ||
use std::marker::PhantomPinned; | ||
use std::pin::*; | ||
use std::ptr; | ||
use std::task::*; | ||
|
||
struct Delay { | ||
delay: usize, | ||
} | ||
|
||
impl Delay { | ||
fn new(delay: usize) -> Self { | ||
Delay { delay } | ||
} | ||
} | ||
|
||
impl Future for Delay { | ||
type Output = (); | ||
fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> { | ||
if self.delay > 0 { | ||
self.delay -= 1; | ||
Poll::Pending | ||
} else { | ||
Poll::Ready(()) | ||
} | ||
} | ||
} | ||
|
||
async fn do_stuff() { | ||
(&mut Delay::new(1)).await; | ||
} | ||
|
||
// Same thing implemented by hand | ||
struct DoStuff { | ||
state: usize, | ||
delay: Delay, | ||
delay_ref: *mut Delay, | ||
_marker: PhantomPinned, | ||
} | ||
|
||
impl DoStuff { | ||
fn new() -> Self { | ||
DoStuff { | ||
state: 0, | ||
delay: Delay::new(1), | ||
delay_ref: ptr::null_mut(), | ||
_marker: PhantomPinned, | ||
} | ||
} | ||
} | ||
|
||
impl Future for DoStuff { | ||
type Output = (); | ||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> { | ||
unsafe { | ||
let this = self.get_unchecked_mut(); | ||
match this.state { | ||
0 => { | ||
// Set up self-ref. | ||
this.delay_ref = &mut this.delay; | ||
// Move to next state. | ||
this.state = 1; | ||
Poll::Pending | ||
} | ||
1 => { | ||
let delay = &mut *this.delay_ref; | ||
Pin::new_unchecked(delay).poll(cx) | ||
} | ||
_ => unreachable!(), | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn run_fut<T>(fut: impl Future<Output = T>) -> T { | ||
use std::sync::Arc; | ||
|
||
struct MyWaker; | ||
impl Wake for MyWaker { | ||
fn wake(self: Arc<Self>) { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
let waker = Waker::from(Arc::new(MyWaker)); | ||
let mut context = Context::from_waker(&waker); | ||
|
||
let mut pinned = pin!(fut); | ||
loop { | ||
match pinned.as_mut().poll(&mut context) { | ||
Poll::Pending => continue, | ||
Poll::Ready(v) => return v, | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
run_fut(do_stuff()); | ||
run_fut(DoStuff::new()); | ||
} |