diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:50 +0000 |
commit | 2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 (patch) | |
tree | d325add32978dbdc1db975a438b3a77d571b1ab8 /library/core/src/future | |
parent | Releasing progress-linux version 1.68.2+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.tar.xz rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.zip |
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/core/src/future')
-rw-r--r-- | library/core/src/future/mod.rs | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/library/core/src/future/mod.rs b/library/core/src/future/mod.rs index c4fb36209..46cbcd435 100644 --- a/library/core/src/future/mod.rs +++ b/library/core/src/future/mod.rs @@ -56,51 +56,6 @@ unsafe impl Send for ResumeTy {} #[unstable(feature = "gen_future", issue = "50547")] unsafe impl Sync for ResumeTy {} -/// Wrap a generator in a future. -/// -/// This function returns a `GenFuture` underneath, but hides it in `impl Trait` to give -/// better error messages (`impl Future` rather than `GenFuture<[closure.....]>`). -// This is `const` to avoid extra errors after we recover from `const async fn` -#[doc(hidden)] -#[unstable(feature = "gen_future", issue = "50547")] -#[rustc_const_unstable(feature = "gen_future", issue = "50547")] -#[inline] -pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return> -where - T: crate::ops::Generator<ResumeTy, Yield = ()>, -{ - use crate::{ - ops::{Generator, GeneratorState}, - pin::Pin, - task::Poll, - }; - - #[rustc_diagnostic_item = "gen_future"] - struct GenFuture<T: Generator<ResumeTy, Yield = ()>>(T); - - // We rely on the fact that async/await futures are immovable in order to create - // self-referential borrows in the underlying generator. - impl<T: Generator<ResumeTy, Yield = ()>> !Unpin for GenFuture<T> {} - - impl<T: Generator<ResumeTy, Yield = ()>> Future for GenFuture<T> { - type Output = T::Return; - #[track_caller] - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { - // SAFETY: Safe because we're !Unpin + !Drop, and this is just a field projection. - let gen = unsafe { Pin::map_unchecked_mut(self, |s| &mut s.0) }; - - // Resume the generator, turning the `&mut Context` into a `NonNull` raw pointer. The - // `.await` lowering will safely cast that back to a `&mut Context`. - match gen.resume(ResumeTy(NonNull::from(cx).cast::<Context<'static>>())) { - GeneratorState::Yielded(()) => Poll::Pending, - GeneratorState::Complete(x) => Poll::Ready(x), - } - } - } - - GenFuture(gen) -} - #[lang = "get_context"] #[doc(hidden)] #[unstable(feature = "gen_future", issue = "50547")] |