Skip to content

Commit 5372e66

Browse files
committed
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`.
1 parent d117135 commit 5372e66

File tree

1 file changed

+0
-45
lines changed

1 file changed

+0
-45
lines changed

library/core/src/future/mod.rs

-45
Original file line numberDiff line numberDiff line change
@@ -56,51 +56,6 @@ unsafe impl Send for ResumeTy {}
5656
#[unstable(feature = "gen_future", issue = "50547")]
5757
unsafe impl Sync for ResumeTy {}
5858

59-
/// Wrap a generator in a future.
60-
///
61-
/// This function returns a `GenFuture` underneath, but hides it in `impl Trait` to give
62-
/// better error messages (`impl Future` rather than `GenFuture<[closure.....]>`).
63-
// This is `const` to avoid extra errors after we recover from `const async fn`
64-
#[doc(hidden)]
65-
#[unstable(feature = "gen_future", issue = "50547")]
66-
#[rustc_const_unstable(feature = "gen_future", issue = "50547")]
67-
#[inline]
68-
pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
69-
where
70-
T: crate::ops::Generator<ResumeTy, Yield = ()>,
71-
{
72-
use crate::{
73-
ops::{Generator, GeneratorState},
74-
pin::Pin,
75-
task::Poll,
76-
};
77-
78-
#[rustc_diagnostic_item = "gen_future"]
79-
struct GenFuture<T: Generator<ResumeTy, Yield = ()>>(T);
80-
81-
// We rely on the fact that async/await futures are immovable in order to create
82-
// self-referential borrows in the underlying generator.
83-
impl<T: Generator<ResumeTy, Yield = ()>> !Unpin for GenFuture<T> {}
84-
85-
impl<T: Generator<ResumeTy, Yield = ()>> Future for GenFuture<T> {
86-
type Output = T::Return;
87-
#[track_caller]
88-
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
89-
// SAFETY: Safe because we're !Unpin + !Drop, and this is just a field projection.
90-
let gen = unsafe { Pin::map_unchecked_mut(self, |s| &mut s.0) };
91-
92-
// Resume the generator, turning the `&mut Context` into a `NonNull` raw pointer. The
93-
// `.await` lowering will safely cast that back to a `&mut Context`.
94-
match gen.resume(ResumeTy(NonNull::from(cx).cast::<Context<'static>>())) {
95-
GeneratorState::Yielded(()) => Poll::Pending,
96-
GeneratorState::Complete(x) => Poll::Ready(x),
97-
}
98-
}
99-
}
100-
101-
GenFuture(gen)
102-
}
103-
10459
#[lang = "get_context"]
10560
#[doc(hidden)]
10661
#[unstable(feature = "gen_future", issue = "50547")]

0 commit comments

Comments
 (0)