Skip to content

chore: replace all internal usage of pin_mut #2941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
rust:
# This is the minimum Rust version supported by futures, futures-util, futures-task, futures-macro, futures-executor, futures-channel, futures-test.
# When updating this, the reminder to update the minimum required version in README.md and Cargo.toml.
- '1.63'
- '1.68'
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Add this to your `Cargo.toml`:
futures = "0.3"
```

The current `futures` requires Rust 1.63 or later.
The current `futures` requires Rust 1.68 or later.

### Feature `std`

Expand Down
2 changes: 1 addition & 1 deletion futures-channel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "futures-channel"
version = "0.4.0-alpha.0"
edition = "2018"
rust-version = "1.63"
rust-version = "1.68"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/futures-rs"
homepage = "https://rust-lang.github.io/futures-rs"
Expand Down
2 changes: 1 addition & 1 deletion futures-channel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Add this to your `Cargo.toml`:
futures-channel = "0.3"
```

The current `futures-channel` requires Rust 1.63 or later.
The current `futures-channel` requires Rust 1.68 or later.

## License

Expand Down
5 changes: 3 additions & 2 deletions futures-channel/tests/mpsc.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use futures::channel::{mpsc, oneshot};
use futures::executor::{block_on, block_on_stream};
use futures::future::{poll_fn, FutureExt};
use futures::pin_mut;
use futures::sink::{Sink, SinkExt};
use futures::stream::{Stream, StreamExt};
use futures::task::{Context, Poll};
use futures_test::task::{new_count_waker, noop_context};
use std::pin::pin;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
use std::thread;
Expand All @@ -30,7 +30,8 @@ fn send_recv_no_buffer() {
// Run on a task context
block_on(poll_fn(move |cx| {
let (tx, rx) = mpsc::channel::<i32>(0);
pin_mut!(tx, rx);
let mut tx = pin!(tx);
let mut rx = pin!(rx);

assert!(tx.as_mut().poll_flush(cx).is_ready());
assert!(tx.as_mut().poll_ready(cx).is_ready());
Expand Down
2 changes: 1 addition & 1 deletion futures-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "futures-executor"
version = "0.4.0-alpha.0"
edition = "2018"
rust-version = "1.63"
rust-version = "1.68"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/futures-rs"
homepage = "https://rust-lang.github.io/futures-rs"
Expand Down
2 changes: 1 addition & 1 deletion futures-executor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Add this to your `Cargo.toml`:
futures-executor = "0.3"
```

The current `futures-executor` requires Rust 1.63 or later.
The current `futures-executor` requires Rust 1.68 or later.

## License

Expand Down
6 changes: 3 additions & 3 deletions futures-executor/src/local_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use futures_core::stream::Stream;
use futures_core::task::{Context, Poll};
use futures_task::{waker_ref, ArcWake};
use futures_task::{FutureObj, LocalFutureObj, LocalSpawn, Spawn, SpawnError};
use futures_util::pin_mut;
use futures_util::stream::FuturesUnordered;
use futures_util::stream::StreamExt;
use std::cell::RefCell;
use std::ops::{Deref, DerefMut};
use std::pin::pin;
use std::rc::{Rc, Weak};
use std::sync::{
atomic::{AtomicBool, Ordering},
Expand Down Expand Up @@ -155,7 +155,7 @@ impl LocalPool {
/// one of the pool's run or poll methods. While the function is running,
/// however, all tasks in the pool will try to make progress.
pub fn run_until<F: Future>(&mut self, future: F) -> F::Output {
pin_mut!(future);
let mut future = pin!(future);

run_executor(|cx| {
{
Expand Down Expand Up @@ -312,7 +312,7 @@ impl Default for LocalPool {
///
/// Use a [`LocalPool`] if you need finer-grained control over spawned tasks.
pub fn block_on<F: Future>(f: F) -> F::Output {
pin_mut!(f);
let mut f = pin!(f);
run_executor(|cx| f.as_mut().poll(cx))
}

Expand Down
2 changes: 1 addition & 1 deletion futures-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "futures-macro"
version = "0.4.0-alpha.0"
edition = "2018"
rust-version = "1.63"
rust-version = "1.68"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/futures-rs"
homepage = "https://rust-lang.github.io/futures-rs"
Expand Down
2 changes: 1 addition & 1 deletion futures-task/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "futures-task"
version = "0.4.0-alpha.0"
edition = "2018"
rust-version = "1.63"
rust-version = "1.68"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/futures-rs"
homepage = "https://rust-lang.github.io/futures-rs"
Expand Down
2 changes: 1 addition & 1 deletion futures-task/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Add this to your `Cargo.toml`:
futures-task = "0.3"
```

The current `futures-task` requires Rust 1.63 or later.
The current `futures-task` requires Rust 1.68 or later.

## License

Expand Down
2 changes: 1 addition & 1 deletion futures-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "futures-test"
version = "0.4.0-alpha.0"
edition = "2018"
rust-version = "1.63"
rust-version = "1.68"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/futures-rs"
homepage = "https://rust-lang.github.io/futures-rs"
Expand Down
2 changes: 1 addition & 1 deletion futures-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Add this to your `Cargo.toml`:
futures-test = "0.3"
```

The current `futures-test` requires Rust 1.63 or later.
The current `futures-test` requires Rust 1.68 or later.

## License

Expand Down
2 changes: 1 addition & 1 deletion futures-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "futures-util"
version = "0.4.0-alpha.0"
edition = "2018"
rust-version = "1.63"
rust-version = "1.68"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/futures-rs"
homepage = "https://rust-lang.github.io/futures-rs"
Expand Down
2 changes: 1 addition & 1 deletion futures-util/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Add this to your `Cargo.toml`:
futures-util = "0.3"
```

The current `futures-util` requires Rust 1.63 or later.
The current `futures-util` requires Rust 1.68 or later.

## License

Expand Down
20 changes: 9 additions & 11 deletions futures-util/src/future/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
//! This module contains a number of functions for working with `Future`s,
//! including the `FutureExt` trait which adds methods to `Future` types.

use crate::fns::{inspect_fn, into_fn, ok_fn, InspectFn, IntoFn, OkFn};
use crate::future::{assert_future, Either};
use crate::stream::assert_stream;
#[cfg(feature = "alloc")]
use alloc::boxed::Box;
use core::convert::Infallible;
use core::pin::pin;
use core::pin::Pin;

use crate::fns::{inspect_fn, into_fn, ok_fn, InspectFn, IntoFn, OkFn};
use crate::future::{assert_future, Either};
use crate::pin_mut;
use crate::stream::assert_stream;
#[cfg(feature = "alloc")]
use futures_core::future::{BoxFuture, LocalBoxFuture};
use futures_core::{
Expand All @@ -27,7 +26,7 @@ mod fuse;
mod map;

delegate_all!(
/// Future for the [`flatten`](super::FutureExt::flatten) method.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split unrelated changes into separate PRs as they will be difficult to review.

/// Future for the [`flatten`](FutureExt::flatten) method.
Flatten<F>(
flatten::Flatten<F, <F as Future>::Output>
): Debug + Future + FusedFuture + New[|x: F| flatten::Flatten::new(x)]
Expand All @@ -45,7 +44,7 @@ delegate_all!(
pub use fuse::Fuse;

delegate_all!(
/// Future for the [`map`](super::FutureExt::map) method.
/// Future for the [`map`](FutureExt::map) method.
Map<Fut, F>(
map::Map<Fut, F>
): Debug + Future + FusedFuture + New[|x: Fut, f: F| map::Map::new(x, f)]
Expand Down Expand Up @@ -80,14 +79,14 @@ delegate_all!(
);

delegate_all!(
/// Future for the [`never_error`](super::FutureExt::never_error) combinator.
/// Future for the [`never_error`](FutureExt::never_error) combinator.
NeverError<Fut>(
Map<Fut, OkFn<Infallible>>
): Debug + Future + FusedFuture + New[|x: Fut| Map::new(x, ok_fn())]
);

delegate_all!(
/// Future for the [`unit_error`](super::FutureExt::unit_error) combinator.
/// Future for the [`unit_error`](FutureExt::unit_error) combinator.
UnitError<Fut>(
Map<Fut, OkFn<()>>
): Debug + Future + FusedFuture + New[|x: Fut| Map::new(x, ok_fn())]
Expand Down Expand Up @@ -592,8 +591,7 @@ pub trait FutureExt: Future {
let noop_waker = crate::task::noop_waker();
let mut cx = Context::from_waker(&noop_waker);

let this = self;
pin_mut!(this);
let this = pin!(self);
match this.poll(&mut cx) {
Poll::Ready(x) => Some(x),
_ => None,
Expand Down
2 changes: 1 addition & 1 deletion futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "futures"
version = "0.4.0-alpha.0"
edition = "2018"
rust-version = "1.63"
rust-version = "1.68"
license = "MIT OR Apache-2.0"
readme = "../README.md"
keywords = ["futures", "async", "future"]
Expand Down
32 changes: 15 additions & 17 deletions futures/tests/async_await_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ use futures::future::{self, poll_fn, FutureExt};
use futures::sink::SinkExt;
use futures::stream::StreamExt;
use futures::task::{Context, Poll};
use futures::{
join, pending, pin_mut, poll, select, select_biased, stream, stream_select, try_join,
};
use std::mem;
use futures::{join, pending, poll, select, select_biased, stream, stream_select, try_join};
use std::pin::pin;

#[test]
fn poll_and_pending() {
let pending_once = async { pending!() };
block_on(async {
pin_mut!(pending_once);
let mut pending_once = pin!(pending_once);
assert_eq!(Poll::Pending, poll!(&mut pending_once));
assert_eq!(Poll::Ready(()), poll!(&mut pending_once));
});
Expand All @@ -30,7 +28,7 @@ fn join() {
};

block_on(async {
pin_mut!(fut);
let mut fut = pin!(fut);
assert_eq!(Poll::Pending, poll!(&mut fut));
tx1.send(1).unwrap();
assert_eq!(Poll::Pending, poll!(&mut fut));
Expand Down Expand Up @@ -124,7 +122,7 @@ fn select_streams() {
},
// runs last
complete => break,
};
}
}
});
assert!(ran);
Expand Down Expand Up @@ -181,7 +179,7 @@ fn select_size() {
_ = ready => {},
}
};
assert_eq!(mem::size_of_val(&fut), 24);
assert_eq!(size_of_val(&fut), 24);

let fut = async {
let mut ready1 = future::ready(0i32);
Expand All @@ -191,7 +189,7 @@ fn select_size() {
_ = ready2 => {},
}
};
assert_eq!(mem::size_of_val(&fut), 40);
assert_eq!(size_of_val(&fut), 40);
}

#[test]
Expand All @@ -204,7 +202,7 @@ fn select_on_non_unpin_expressions() {
select! {
value_1 = make_non_unpin_fut().fuse() => select_res = value_1,
value_2 = make_non_unpin_fut().fuse() => select_res = value_2,
};
}
select_res
});
assert_eq!(res, 5);
Expand All @@ -221,7 +219,7 @@ fn select_on_non_unpin_expressions_with_default() {
value_1 = make_non_unpin_fut().fuse() => select_res = value_1,
value_2 = make_non_unpin_fut().fuse() => select_res = value_2,
default => select_res = 7,
};
}
select_res
});
assert_eq!(res, 5);
Expand All @@ -238,11 +236,11 @@ fn select_on_non_unpin_size() {
select! {
value_1 = make_non_unpin_fut().fuse() => select_res = value_1,
value_2 = make_non_unpin_fut().fuse() => select_res = value_2,
};
}
select_res
};

assert_eq!(32, mem::size_of_val(&fut));
assert_eq!(32, size_of_val(&fut));
}

#[test]
Expand Down Expand Up @@ -364,14 +362,14 @@ fn join_size() {
let ready = future::ready(0i32);
join!(ready)
};
assert_eq!(mem::size_of_val(&fut), 24);
assert_eq!(size_of_val(&fut), 24);

let fut = async {
let ready1 = future::ready(0i32);
let ready2 = future::ready(0i32);
join!(ready1, ready2)
};
assert_eq!(mem::size_of_val(&fut), 40);
assert_eq!(size_of_val(&fut), 40);
}

#[cfg_attr(not(target_pointer_width = "64"), ignore)]
Expand All @@ -381,14 +379,14 @@ fn try_join_size() {
let ready = future::ready(Ok::<i32, i32>(0));
try_join!(ready)
};
assert_eq!(mem::size_of_val(&fut), 24);
assert_eq!(size_of_val(&fut), 24);

let fut = async {
let ready1 = future::ready(Ok::<i32, i32>(0));
let ready2 = future::ready(Ok::<i32, i32>(0));
try_join!(ready1, ready2)
};
assert_eq!(mem::size_of_val(&fut), 48);
assert_eq!(size_of_val(&fut), 48);
}

#[allow(clippy::let_underscore_future)]
Expand Down
4 changes: 2 additions & 2 deletions futures/tests/future_join_all.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use futures::executor::block_on;
use futures::future::{join_all, ready, Future, JoinAll};
use futures::pin_mut;
use std::fmt::Debug;
use std::pin::pin;

#[track_caller]
fn assert_done<T>(actual_fut: impl Future<Output = T>, expected: T)
where
T: PartialEq + Debug,
{
pin_mut!(actual_fut);
let actual_fut = pin!(actual_fut);
let output = block_on(actual_fut);
assert_eq!(output, expected);
}
Expand Down
Loading