summaryrefslogtreecommitdiffstats
path: root/third_party/rust/futures/tests/future_join.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/futures/tests/future_join.rs')
-rw-r--r--third_party/rust/futures/tests/future_join.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/third_party/rust/futures/tests/future_join.rs b/third_party/rust/futures/tests/future_join.rs
new file mode 100644
index 0000000000..f5df9d7775
--- /dev/null
+++ b/third_party/rust/futures/tests/future_join.rs
@@ -0,0 +1,32 @@
+use futures::executor::block_on;
+use futures::future::Future;
+use std::task::Poll;
+
+/// This tests verifies (through miri) that self-referencing
+/// futures are not invalidated when joining them.
+#[test]
+fn futures_join_macro_self_referential() {
+ block_on(async { futures::join!(yield_now(), trouble()) });
+}
+
+async fn trouble() {
+ let lucky_number = 42;
+ let problematic_variable = &lucky_number;
+
+ yield_now().await;
+
+ // problematic dereference
+ let _ = { *problematic_variable };
+}
+
+fn yield_now() -> impl Future<Output = ()> {
+ let mut yielded = false;
+ std::future::poll_fn(move |cx| {
+ if core::mem::replace(&mut yielded, true) {
+ Poll::Ready(())
+ } else {
+ cx.waker().wake_by_ref();
+ Poll::Pending
+ }
+ })
+}