about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2023-01-31 11:46:23 +0900
committerGitHub <noreply@github.com>2023-01-31 11:46:23 +0900
commit39d2639f819ee80ba2b4e2c1ad0fd40955dd30e5 (patch)
treeef1d8381430a8b2f43232feae6224e01aa85ca09
parent6eeb981a580a630b3359d2ad46f0b086dcfa1681 (diff)
parent5372e66884b7962acfce99d5dd8aef7e48d0257e (diff)
downloadrust-39d2639f819ee80ba2b4e2c1ad0fd40955dd30e5.tar.gz
rust-39d2639f819ee80ba2b4e2c1ad0fd40955dd30e5.zip
Rollup merge of #107445 - Swatinem:rm-genfuture, r=cuviper
Remove `GenFuture` from core

The handling of async constructs in the compiler does not rely on `GenFuture` anymore since `1.67`, so this code can now be removed from `core`.
-rw-r--r--library/core/src/future/mod.rs45
1 files changed, 0 insertions, 45 deletions
diff --git a/library/core/src/future/mod.rs b/library/core/src/future/mod.rs
index c4fb3620946..46cbcd43530 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")]