diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/tokio/src/future | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/tokio/src/future')
-rw-r--r-- | vendor/tokio/src/future/block_on.rs | 11 | ||||
-rw-r--r-- | vendor/tokio/src/future/maybe_done.rs | 8 | ||||
-rw-r--r-- | vendor/tokio/src/future/mod.rs | 5 | ||||
-rw-r--r-- | vendor/tokio/src/future/poll_fn.rs | 30 | ||||
-rw-r--r-- | vendor/tokio/src/future/ready.rs | 27 |
5 files changed, 38 insertions, 43 deletions
diff --git a/vendor/tokio/src/future/block_on.rs b/vendor/tokio/src/future/block_on.rs index 91f9cc005..2c2ab3736 100644 --- a/vendor/tokio/src/future/block_on.rs +++ b/vendor/tokio/src/future/block_on.rs @@ -1,15 +1,22 @@ use std::future::Future; cfg_rt! { + #[track_caller] pub(crate) fn block_on<F: Future>(f: F) -> F::Output { - let mut e = crate::runtime::enter::enter(false); + let mut e = crate::runtime::context::try_enter_blocking_region().expect( + "Cannot block the current thread from within a runtime. This \ + happens because a function attempted to block the current \ + thread while the thread is being used to drive asynchronous \ + tasks." + ); e.block_on(f).unwrap() } } cfg_not_rt! { + #[track_caller] pub(crate) fn block_on<F: Future>(f: F) -> F::Output { - let mut park = crate::park::thread::CachedParkThread::new(); + let mut park = crate::runtime::park::CachedParkThread::new(); park.block_on(f).unwrap() } } diff --git a/vendor/tokio/src/future/maybe_done.rs b/vendor/tokio/src/future/maybe_done.rs index 1e083ad7f..486efbe01 100644 --- a/vendor/tokio/src/future/maybe_done.rs +++ b/vendor/tokio/src/future/maybe_done.rs @@ -1,4 +1,4 @@ -//! Definition of the MaybeDone combinator +//! Definition of the MaybeDone combinator. use std::future::Future; use std::mem; @@ -8,9 +8,9 @@ use std::task::{Context, Poll}; /// A future that may have completed. #[derive(Debug)] pub enum MaybeDone<Fut: Future> { - /// A not-yet-completed future + /// A not-yet-completed future. Future(Fut), - /// The output of the completed future + /// The output of the completed future. Done(Fut::Output), /// The empty variant after the result of a [`MaybeDone`] has been /// taken using the [`take_output`](MaybeDone::take_output) method. @@ -20,7 +20,7 @@ pub enum MaybeDone<Fut: Future> { // Safe because we never generate `Pin<&mut Fut::Output>` impl<Fut: Future + Unpin> Unpin for MaybeDone<Fut> {} -/// Wraps a future into a `MaybeDone` +/// Wraps a future into a `MaybeDone`. pub fn maybe_done<Fut: Future>(future: Fut) -> MaybeDone<Fut> { MaybeDone::Future(future) } diff --git a/vendor/tokio/src/future/mod.rs b/vendor/tokio/src/future/mod.rs index 96483acd7..084ddc571 100644 --- a/vendor/tokio/src/future/mod.rs +++ b/vendor/tokio/src/future/mod.rs @@ -8,11 +8,6 @@ pub(crate) mod maybe_done; mod poll_fn; pub use poll_fn::poll_fn; -cfg_not_loom! { - mod ready; - pub(crate) use ready::{ok, Ready}; -} - cfg_process! { mod try_join; pub(crate) use try_join::try_join3; diff --git a/vendor/tokio/src/future/poll_fn.rs b/vendor/tokio/src/future/poll_fn.rs index 0169bd5fc..074d9438e 100644 --- a/vendor/tokio/src/future/poll_fn.rs +++ b/vendor/tokio/src/future/poll_fn.rs @@ -1,19 +1,29 @@ #![allow(dead_code)] -//! Definition of the `PollFn` adapter combinator +//! Definition of the `PollFn` adapter combinator. use std::fmt; use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; +// This struct is intentionally `!Unpin` when `F` is `!Unpin`. This is to +// mitigate the issue where rust puts noalias on mutable references to the +// `PollFn` type if it is `Unpin`. If the closure has ownership of a future, +// then this "leaks" and the future is affected by noalias too, which we don't +// want. +// +// See this thread for more information: +// <https://internals.rust-lang.org/t/surprising-soundness-trouble-around-pollfn/17484> +// +// The fact that `PollFn` is not `Unpin` when it shouldn't be is tested in +// `tests/async_send_sync.rs`. + /// Future for the [`poll_fn`] function. pub struct PollFn<F> { f: F, } -impl<F> Unpin for PollFn<F> {} - /// Creates a new future wrapping around a function returning [`Poll`]. pub fn poll_fn<T, F>(f: F) -> PollFn<F> where @@ -34,7 +44,17 @@ where { type Output = T; - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> { - (&mut self.f)(cx) + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> { + // Safety: We never construct a `Pin<&mut F>` anywhere, so accessing `f` + // mutably in an unpinned way is sound. + // + // This use of unsafe cannot be replaced with the pin-project macro + // because: + // * If we put `#[pin]` on the field, then it gives us a `Pin<&mut F>`, + // which we can't use to call the closure. + // * If we don't put `#[pin]` on the field, then it makes `PollFn` be + // unconditionally `Unpin`, which we also don't want. + let me = unsafe { Pin::into_inner_unchecked(self) }; + (me.f)(cx) } } diff --git a/vendor/tokio/src/future/ready.rs b/vendor/tokio/src/future/ready.rs deleted file mode 100644 index de2d60c13..000000000 --- a/vendor/tokio/src/future/ready.rs +++ /dev/null @@ -1,27 +0,0 @@ -use std::future::Future; -use std::pin::Pin; -use std::task::{Context, Poll}; - -/// Future for the [`ok`](ok()) function. -/// -/// `pub` in order to use the future as an associated type in a sealed trait. -#[derive(Debug)] -// Used as an associated type in a "sealed" trait. -#[allow(unreachable_pub)] -pub struct Ready<T>(Option<T>); - -impl<T> Unpin for Ready<T> {} - -impl<T> Future for Ready<T> { - type Output = T; - - #[inline] - fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> { - Poll::Ready(self.0.take().unwrap()) - } -} - -/// Creates a future that is immediately ready with a success value. -pub(crate) fn ok<T, E>(t: T) -> Ready<Result<T, E>> { - Ready(Some(Ok(t))) -} |