about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-07-11 06:28:04 +0000
committerbors <bors@rust-lang.org>2020-07-11 06:28:04 +0000
commit346aec9b02f3c74f3fce97fd6bda24709d220e49 (patch)
tree8ddad2b3c566486f44ea01f6305e1beeb11140f7 /src/libcore
parentdaecab3a784f28082df90cebb204998051f3557d (diff)
parent79fc3861dfd1190b257ef7f4208533c3945254b7 (diff)
Auto merge of #74235 - Manishearth:rollup-bgs3q14, r=Manishearth
Rollup of 19 pull requests

Successful merges:

 - #71322 (Accept tuple.0.0 as tuple indexing (take 2))
 - #72303 (Add core::future::{poll_fn, PollFn})
 - #73862 (Stabilize casts and coercions to `&[T]` in const fn)
 - #73887 (stabilize const mem::forget)
 - #73989 (adjust ub-enum test to be endianess-independent)
 - #74045 (Explain effects of debugging options from config.toml)
 - #74076 (Add `read_exact_at` and `write_all_at` to WASI's `FileExt`)
 - #74099 (Add VecDeque::range* methods)
 - #74100 (Use str::strip* in bootstrap)
 - #74103 (Only add CFGuard on `windows-msvc` targets)
 - #74109 (Only allow `repr(i128/u128)` on enum)
 - #74122 (Start-up clean-up)
 - #74125 (Correctly mark the ending span of a match arm)
 - #74127 (Avoid "whitelist")
 - #74129 (:arrow_up: rust-analyzer)
 - #74135 (Update books)
 - #74145 (Update rust-installer to latest version)
 - #74161 (Fix  disabled dockerfiles)
 - #74162 (take self by value in ToPredicate)

Failed merges:

r? @ghost
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/ffi.rs2
-rw-r--r--src/libcore/future/mod.rs4
-rw-r--r--src/libcore/future/poll_fn.rs66
-rw-r--r--src/libcore/mem/mod.rs2
-rw-r--r--src/libcore/tests/lib.rs1
5 files changed, 72 insertions, 3 deletions
diff --git a/src/libcore/ffi.rs b/src/libcore/ffi.rs
index ee3192eddbd..e9689af39d5 100644
--- a/src/libcore/ffi.rs
+++ b/src/libcore/ffi.rs
@@ -280,7 +280,7 @@ impl<'a, 'f: 'a> DerefMut for VaList<'a, 'f> {
 // within a private module. Once RFC 2145 has been implemented look into
 // improving this.
 mod sealed_trait {
-    /// Trait which whitelists the allowed types to be used with [VaList::arg]
+    /// Trait which permits the allowed types to be used with [VaList::arg].
     ///
     /// [VaList::arg]: ../struct.VaList.html#method.arg
     #[unstable(
diff --git a/src/libcore/future/mod.rs b/src/libcore/future/mod.rs
index 2555d91ae8d..6d1ad9db744 100644
--- a/src/libcore/future/mod.rs
+++ b/src/libcore/future/mod.rs
@@ -12,6 +12,7 @@ use crate::{
 mod future;
 mod into_future;
 mod pending;
+mod poll_fn;
 mod ready;
 
 #[stable(feature = "futures_api", since = "1.36.0")]
@@ -25,6 +26,9 @@ pub use pending::{pending, Pending};
 #[unstable(feature = "future_readiness_fns", issue = "70921")]
 pub use ready::{ready, Ready};
 
+#[unstable(feature = "future_poll_fn", issue = "72302")]
+pub use poll_fn::{poll_fn, PollFn};
+
 /// This type is needed because:
 ///
 /// a) Generators cannot implement `for<'a, 'b> Generator<&'a mut Context<'b>>`, so we need to pass
diff --git a/src/libcore/future/poll_fn.rs b/src/libcore/future/poll_fn.rs
new file mode 100644
index 00000000000..9ab3bfcea1c
--- /dev/null
+++ b/src/libcore/future/poll_fn.rs
@@ -0,0 +1,66 @@
+use crate::fmt;
+use crate::future::Future;
+use crate::pin::Pin;
+use crate::task::{Context, Poll};
+
+/// Creates a future that wraps a function returning `Poll`.
+///
+/// Polling the future delegates to the wrapped function.
+///
+/// # Examples
+///
+/// ```
+/// #![feature(future_poll_fn)]
+/// # async fn run() {
+/// use core::future::poll_fn;
+/// use core::task::{Context, Poll};
+///
+/// fn read_line(_cx: &mut Context<'_>) -> Poll<String> {
+///     Poll::Ready("Hello, World!".into())
+/// }
+///
+/// let read_future = poll_fn(read_line);
+/// assert_eq!(read_future.await, "Hello, World!".to_owned());
+/// # };
+/// ```
+#[unstable(feature = "future_poll_fn", issue = "72302")]
+pub fn poll_fn<T, F>(f: F) -> PollFn<F>
+where
+    F: FnMut(&mut Context<'_>) -> Poll<T>,
+{
+    PollFn { f }
+}
+
+/// A Future that wraps a function returning `Poll`.
+///
+/// This `struct` is created by the [`poll_fn`] function. See its
+/// documentation for more.
+///
+/// [`poll_fn`]: fn.poll_fn.html
+#[must_use = "futures do nothing unless you `.await` or poll them"]
+#[unstable(feature = "future_poll_fn", issue = "72302")]
+pub struct PollFn<F> {
+    f: F,
+}
+
+#[unstable(feature = "future_poll_fn", issue = "72302")]
+impl<F> Unpin for PollFn<F> {}
+
+#[unstable(feature = "future_poll_fn", issue = "72302")]
+impl<F> fmt::Debug for PollFn<F> {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        f.debug_struct("PollFn").finish()
+    }
+}
+
+#[unstable(feature = "future_poll_fn", issue = "72302")]
+impl<T, F> Future for PollFn<F>
+where
+    F: FnMut(&mut Context<'_>) -> Poll<T>,
+{
+    type Output = T;
+
+    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> {
+        (&mut self.f)(cx)
+    }
+}
diff --git a/src/libcore/mem/mod.rs b/src/libcore/mem/mod.rs
index 0a976a4ca00..98d2027268b 100644
--- a/src/libcore/mem/mod.rs
+++ b/src/libcore/mem/mod.rs
@@ -142,7 +142,7 @@ pub use crate::intrinsics::transmute;
 /// [ub]: ../../reference/behavior-considered-undefined.html
 /// [`ManuallyDrop`]: struct.ManuallyDrop.html
 #[inline]
-#[rustc_const_unstable(feature = "const_forget", issue = "69616")]
+#[rustc_const_stable(feature = "const_forget", since = "1.46.0")]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub const fn forget<T>(t: T) {
     ManuallyDrop::new(t);
diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs
index 68a5e20a66f..090ce471745 100644
--- a/src/libcore/tests/lib.rs
+++ b/src/libcore/tests/lib.rs
@@ -40,7 +40,6 @@
 #![feature(const_raw_ptr_deref)]
 #![feature(never_type)]
 #![feature(unwrap_infallible)]
-#![feature(const_forget)]
 #![feature(option_unwrap_none)]
 #![feature(peekable_next_if)]
 #![feature(partition_point)]