From d65d87a7abafaa7404d3976a737ec005f24dc128 Mon Sep 17 00:00:00 2001 From: Jacob Kiesel Date: Thu, 15 Sep 2022 17:05:31 -0600 Subject: [PATCH] fix randomization problems by rearranging modules --- futures-macro/src/select.rs | 2 +- futures-macro/src/stream_select.rs | 2 +- futures-util/src/async_await/mod.rs | 6 ------ futures-util/src/future/select_ok.rs | 4 +++- futures-util/src/future/try_select.rs | 10 ++++++---- futures-util/src/lib.rs | 6 ++++++ futures-util/src/{async_await => }/random.rs | 0 7 files changed, 17 insertions(+), 13 deletions(-) rename futures-util/src/{async_await => }/random.rs (100%) diff --git a/futures-macro/src/select.rs b/futures-macro/src/select.rs index 4cd8c7bc6f..9862de8005 100644 --- a/futures-macro/src/select.rs +++ b/futures-macro/src/select.rs @@ -279,7 +279,7 @@ fn select_inner(input: TokenStream, random: bool) -> TokenStream { let shuffle = if random { quote! { - __futures_crate::async_await::shuffle(&mut __select_arr); + __futures_crate::shuffle(&mut __select_arr); } } else { quote!() diff --git a/futures-macro/src/stream_select.rs b/futures-macro/src/stream_select.rs index 9927b53073..7571a565b2 100644 --- a/futures-macro/src/stream_select.rs +++ b/futures-macro/src/stream_select.rs @@ -56,7 +56,7 @@ pub(crate) fn stream_select(input: TokenStream) -> Result(_: &T) {} diff --git a/futures-util/src/future/select_ok.rs b/futures-util/src/future/select_ok.rs index 00349614f2..3d6fa67cc1 100644 --- a/futures-util/src/future/select_ok.rs +++ b/futures-util/src/future/select_ok.rs @@ -59,7 +59,9 @@ impl Future for SelectOk { fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let Self { inner } = &mut *self; #[cfg(feature = "std")] - crate::shuffle(inner); + { + crate::shuffle(inner); + } // loop until we've either exhausted all errors, a success was hit, or nothing is ready loop { let item = inner.iter_mut().enumerate().find_map(|(i, f)| match f.try_poll_unpin(cx) { diff --git a/futures-util/src/future/try_select.rs b/futures-util/src/future/try_select.rs index f2811bf364..a24525bbdc 100644 --- a/futures-util/src/future/try_select.rs +++ b/futures-util/src/future/try_select.rs @@ -90,10 +90,12 @@ where } #[cfg(feature = "std")] - if crate::gen_index(2) == 0 { - poll_wrap!(a, b, Either::Left, Either::Right) - } else { - poll_wrap!(b, a, Either::Right, Either::Left) + { + if crate::gen_index(2) == 0 { + poll_wrap!(a, b, Either::Left, Either::Right) + } else { + poll_wrap!(b, a, Either::Right, Either::Left) + } } #[cfg(not(feature = "std"))] diff --git a/futures-util/src/lib.rs b/futures-util/src/lib.rs index e00faf4775..210e38fb12 100644 --- a/futures-util/src/lib.rs +++ b/futures-util/src/lib.rs @@ -37,6 +37,12 @@ mod async_await; #[doc(hidden)] pub use self::async_await::*; +#[cfg(feature = "std")] +mod random; +#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/64762 +#[cfg(feature = "std")] +pub use self::random::*; + // Not public API. #[cfg(feature = "async-await")] #[doc(hidden)] diff --git a/futures-util/src/async_await/random.rs b/futures-util/src/random.rs similarity index 100% rename from futures-util/src/async_await/random.rs rename to futures-util/src/random.rs