1
0
Fork 0
firefox/third_party/rust/futures/tests/future_join.rs
Daniel Baumann 5e9a113729
Adding upstream version 140.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-25 09:37:52 +02:00

32 lines
797 B
Rust

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
}
})
}