Skip to content

Commit 685ac62

Browse files
committed
fix randomization problems by rearranging modules
1 parent df6583d commit 685ac62

File tree

8 files changed

+25
-19
lines changed

8 files changed

+25
-19
lines changed

futures-macro/src/select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ fn select_inner(input: TokenStream, random: bool) -> TokenStream {
279279

280280
let shuffle = if random {
281281
quote! {
282-
__futures_crate::async_await::shuffle(&mut __select_arr);
282+
__futures_crate::shuffle(&mut __select_arr);
283283
}
284284
} else {
285285
quote!()

futures-macro/src/stream_select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub(crate) fn stream_select(input: TokenStream) -> Result<TokenStream, syn::Erro
5656
let mut any_pending = false;
5757
{
5858
let mut stream_array = [#(#field_idents.as_mut().map(|f| StreamEnum::#generic_idents(f)).unwrap_or(StreamEnum::None)),*];
59-
__futures_crate::async_await::shuffle(&mut stream_array);
59+
__futures_crate::shuffle(&mut stream_array);
6060

6161
for mut s in stream_array {
6262
if let StreamEnum::None = s {

futures-util/src/async_await/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ mod stream_select_mod;
3737
#[cfg(feature = "async-await-macro")]
3838
pub use self::stream_select_mod::*;
3939

40-
#[cfg(feature = "std")]
41-
mod random;
42-
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/64762
43-
#[cfg(feature = "std")]
44-
pub use self::random::*;
45-
4640
#[doc(hidden)]
4741
#[inline(always)]
4842
pub fn assert_unpin<T: Unpin>(_: &T) {}

futures-util/src/future/select.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,14 @@ where
113113
}
114114

115115
#[cfg(feature = "std")]
116-
if crate::gen_index(2) == 0 {
117-
poll_wrap!(a, b, Either::Left);
118-
poll_wrap!(b, a, Either::Right);
119-
} else {
120-
poll_wrap!(b, a, Either::Right);
121-
poll_wrap!(a, b, Either::Left);
116+
{
117+
if crate::gen_index(2) == 0 {
118+
poll_wrap!(a, b, Either::Left);
119+
poll_wrap!(b, a, Either::Right);
120+
} else {
121+
poll_wrap!(b, a, Either::Right);
122+
poll_wrap!(a, b, Either::Left);
123+
}
122124
}
123125

124126
#[cfg(not(feature = "std"))]

futures-util/src/future/select_ok.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ impl<Fut: TryFuture + Unpin> Future for SelectOk<Fut> {
5959
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
6060
let Self { inner } = &mut *self;
6161
#[cfg(feature = "std")]
62-
crate::shuffle(inner);
62+
{
63+
crate::shuffle(inner);
64+
}
6365
// loop until we've either exhausted all errors, a success was hit, or nothing is ready
6466
loop {
6567
let item = inner.iter_mut().enumerate().find_map(|(i, f)| match f.try_poll_unpin(cx) {

futures-util/src/future/try_select.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ where
9090
}
9191

9292
#[cfg(feature = "std")]
93-
if crate::gen_index(2) == 0 {
94-
poll_wrap!(a, b, Either::Left, Either::Right)
95-
} else {
96-
poll_wrap!(b, a, Either::Right, Either::Left)
93+
{
94+
if crate::gen_index(2) == 0 {
95+
poll_wrap!(a, b, Either::Left, Either::Right)
96+
} else {
97+
poll_wrap!(b, a, Either::Right, Either::Left)
98+
}
9799
}
98100

99101
#[cfg(not(feature = "std"))]

futures-util/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ mod async_await;
3737
#[doc(hidden)]
3838
pub use self::async_await::*;
3939

40+
#[cfg(feature = "std")]
41+
mod random;
42+
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/64762
43+
#[cfg(feature = "std")]
44+
pub use self::random::*;
45+
4046
// Not public API.
4147
#[cfg(feature = "async-await")]
4248
#[doc(hidden)]
File renamed without changes.

0 commit comments

Comments
 (0)