]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/future.rs
core: add IntoFuture trait and support for await
[rust.git] / src / libstd / future.rs
index 6de3f1d545b57fbfbe9a837b63d0c9516a182182..908736c63931bcb2a6b6bb453eb4ba699116e3f9 100644 (file)
@@ -2,15 +2,19 @@
 
 use core::cell::Cell;
 use core::marker::Unpin;
-use core::pin::Pin;
+use core::ops::{Drop, Generator, GeneratorState};
 use core::option::Option;
+use core::pin::Pin;
 use core::ptr::NonNull;
 use core::task::{Context, Poll};
-use core::ops::{Drop, Generator, GeneratorState};
 
 #[doc(inline)]
 #[stable(feature = "futures_api", since = "1.36.0")]
-pub use core::future::*;
+pub use core::future::Future;
+
+#[doc(inline)]
+#[unstable(feature = "into_future", issue = "67644")]
+pub use core::future::IntoFuture;
 
 /// Wrap a generator in a future.
 ///
@@ -26,7 +30,6 @@ pub fn from_generator<T: Generator<Yield = ()>>(x: T) -> impl Future<Output = T:
 #[doc(hidden)]
 #[unstable(feature = "gen_future", issue = "50547")]
 #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
-#[cfg_attr(not(test), rustc_diagnostic_item = "gen_future")]
 struct GenFuture<T: Generator<Yield = ()>>(T);
 
 // We rely on the fact that async/await futures are immovable in order to create
@@ -67,9 +70,7 @@ fn drop(&mut self) {
 unsafe fn set_task_context(cx: &mut Context<'_>) -> SetOnDrop {
     // transmute the context's lifetime to 'static so we can store it.
     let cx = core::mem::transmute::<&mut Context<'_>, &mut Context<'static>>(cx);
-    let old_cx = TLS_CX.with(|tls_cx| {
-        tls_cx.replace(Some(NonNull::from(cx)))
-    });
+    let old_cx = TLS_CX.with(|tls_cx| tls_cx.replace(Some(NonNull::from(cx))));
     SetOnDrop(old_cx)
 }
 
@@ -78,7 +79,7 @@ unsafe fn set_task_context(cx: &mut Context<'_>) -> SetOnDrop {
 /// Polls a future in the current thread-local task waker.
 pub fn poll_with_tls_context<F>(f: Pin<&mut F>) -> Poll<F::Output>
 where
-    F: Future
+    F: Future,
 {
     let cx_ptr = TLS_CX.with(|tls_cx| {
         // Clear the entry so that nested `get_task_waker` calls
@@ -89,7 +90,8 @@ pub fn poll_with_tls_context<F>(f: Pin<&mut F>) -> Poll<F::Output>
 
     let mut cx_ptr = cx_ptr.expect(
         "TLS Context not set. This is a rustc bug. \
-        Please file an issue on https://github.com/rust-lang/rust.");
+        Please file an issue on https://github.com/rust-lang/rust.",
+    );
 
     // Safety: we've ensured exclusive access to the context by
     // removing the pointer from TLS, only to be replaced once