1 | use futures::executor::block_on; |
2 | use futures::future::Future; |
3 | use std::task::Poll; |
4 | |
5 | /// This tests verifies (through miri) that self-referencing |
6 | /// futures are not invalidated when joining them. |
7 | #[test] |
8 | fn futures_join_macro_self_referential() { |
9 | block_on(async { futures::join!(yield_now(), trouble()) }); |
10 | } |
11 | |
12 | async fn trouble() { |
13 | let lucky_number = 42; |
14 | let problematic_variable = &lucky_number; |
15 | |
16 | yield_now().await; |
17 | |
18 | // problematic dereference |
19 | let _ = { *problematic_variable }; |
20 | } |
21 | |
22 | fn yield_now() -> impl Future<Output = ()> { |
23 | let mut yielded = false; |
24 | std::future::poll_fn(move |cx| { |
25 | if core::mem::replace(&mut yielded, true) { |
26 | Poll::Ready(()) |
27 | } else { |
28 | cx.waker().wake_by_ref(); |
29 | Poll::Pending |
30 | } |
31 | }) |
32 | } |
33 | |