Skip to content

Commit b5a76c7

Browse files
committed
add test for #2068
1 parent dd968a8 commit b5a76c7

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/run-pass/issue-miri-2068.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#![feature(pin_macro)]
2+
3+
use core::future::Future;
4+
use core::pin::Pin;
5+
use core::task::{Context, Poll};
6+
7+
use std::sync::Arc;
8+
9+
struct NopWaker;
10+
11+
impl std::task::Wake for NopWaker {
12+
fn wake(self: Arc<Self>) {}
13+
}
14+
15+
pub fn fuzzing_block_on<O, F: Future<Output = O>>(fut: F) -> O {
16+
let mut fut = std::pin::pin!(fut);
17+
let waker = std::task::Waker::from(Arc::new(NopWaker));
18+
let mut context = std::task::Context::from_waker(&waker);
19+
loop {
20+
match fut.as_mut().poll(&mut context) {
21+
Poll::Ready(v) => return v,
22+
Poll::Pending => {}
23+
}
24+
}
25+
}
26+
27+
pub struct LastFuture<S> {
28+
last: S,
29+
}
30+
31+
impl<S> Future for LastFuture<S>
32+
where
33+
Self: Unpin,
34+
S: Unpin + Copy,
35+
{
36+
type Output = S;
37+
38+
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
39+
return Poll::Ready(self.last);
40+
}
41+
}
42+
43+
fn main() {
44+
fuzzing_block_on(async {
45+
LastFuture { last: &0u32 }.await;
46+
LastFuture { last: Option::<u32>::None }.await;
47+
});
48+
}

0 commit comments

Comments
 (0)