diff options
| author | Taylor Cramer <cramertj@google.com> | 2018-06-22 11:36:01 -0700 |
|---|---|---|
| committer | Taylor Cramer <cramertj@google.com> | 2018-06-22 11:36:01 -0700 |
| commit | ee51a3c10aa26b6e6c4e86622181d4a3d396fb34 (patch) | |
| tree | 5e2ca9e0e1b58ecd90511330fc08b266a0390101 /src/libstd | |
| parent | 85e4866320e992126e73d1c640f16a4c755a66b3 (diff) | |
| download | rust-ee51a3c10aa26b6e6c4e86622181d4a3d396fb34.tar.gz rust-ee51a3c10aa26b6e6c4e86622181d4a3d396fb34.zip | |
Review nits and updates
Move future_from_generator out of raw Update await to use $crate Renumber errors
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/future.rs (renamed from src/libstd/raw.rs) | 28 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 35 | ||||
| -rw-r--r-- | src/libstd/macros.rs | 10 |
3 files changed, 35 insertions, 38 deletions
diff --git a/src/libstd/raw.rs b/src/libstd/future.rs index 62fd42c4de7..abacb862656 100644 --- a/src/libstd/raw.rs +++ b/src/libstd/future.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,18 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(missing_docs)] -#![unstable(feature = "raw", issue = "27751")] - -//! Contains struct definitions for the layout of compiler built-in types. -//! -//! They can be used as targets of transmutes in unsafe code for manipulating -//! the raw representations directly. -//! -//! Their definition should always match the ABI defined in `rustc::back::abi`. +//! Asynchronous values. use core::cell::Cell; -use core::future::Future; use core::marker::Unpin; use core::mem::PinMut; use core::option::Option; @@ -27,8 +18,8 @@ use core::ptr::NonNull; use core::task::{self, Poll}; use core::ops::{Drop, Generator, GeneratorState}; -#[stable(feature = "rust1", since = "1.0.0")] -pub use core::raw::*; +#[doc(inline)] +pub use core::future::*; /// Wrap a future in a generator. /// @@ -52,7 +43,7 @@ impl<T: Generator<Yield = ()>> !Unpin for GenFuture<T> {} impl<T: Generator<Yield = ()>> Future for GenFuture<T> { type Output = T::Return; fn poll(self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> { - with_set_cx(cx, || match unsafe { PinMut::get_mut(self).0.resume() } { + set_task_cx(cx, || match unsafe { PinMut::get_mut(self).0.resume() } { GeneratorState::Yielded(()) => Poll::Pending, GeneratorState::Complete(x) => Poll::Ready(x), }) @@ -74,7 +65,8 @@ impl Drop for SetOnDrop { } #[unstable(feature = "gen_future", issue = "50547")] -pub fn with_set_cx<F, R>(cx: &mut task::Context, f: F) -> R +/// Sets the thread-local task context used by async/await futures. +pub fn set_task_cx<F, R>(cx: &mut task::Context, f: F) -> R where F: FnOnce() -> R { @@ -90,7 +82,11 @@ where } #[unstable(feature = "gen_future", issue = "50547")] -pub fn with_get_cx<F, R>(f: F) -> R +/// Retrieves the thread-local task context used by async/await futures. +/// +/// Panics if no task has been set or if the task context has already been +/// retrived by a surrounding call to get_task_cx. +pub fn get_task_cx<F, R>(f: F) -> R where F: FnOnce(&mut task::Context) -> R { diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index c74cd3feca3..caad924ea5b 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -411,6 +411,8 @@ pub use core::ops; #[stable(feature = "rust1", since = "1.0.0")] pub use core::ptr; #[stable(feature = "rust1", since = "1.0.0")] +pub use core::raw; +#[stable(feature = "rust1", since = "1.0.0")] pub use core::result; #[stable(feature = "rust1", since = "1.0.0")] pub use core::option; @@ -461,22 +463,6 @@ pub use core::u128; #[stable(feature = "core_hint", since = "1.27.0")] pub use core::hint; -#[unstable(feature = "futures_api", - reason = "futures in libcore are unstable", - issue = "50547")] -pub mod task { - //! Types and Traits for working with asynchronous tasks. - #[doc(inline)] - pub use core::task::*; - #[doc(inline)] - pub use alloc_crate::task::*; -} - -#[unstable(feature = "futures_api", - reason = "futures in libcore are unstable", - issue = "50547")] -pub use core::future; - pub mod f32; pub mod f64; @@ -495,10 +481,25 @@ pub mod os; pub mod panic; pub mod path; pub mod process; -pub mod raw; pub mod sync; pub mod time; +#[unstable(feature = "futures_api", + reason = "futures in libcore are unstable", + issue = "50547")] +pub mod task { + //! Types and Traits for working with asynchronous tasks. + #[doc(inline)] + pub use core::task::*; + #[doc(inline)] + pub use alloc_crate::task::*; +} + +#[unstable(feature = "futures_api", + reason = "futures in libcore are unstable", + issue = "50547")] +pub mod future; + // Platform-abstraction modules #[macro_use] mod sys_common; diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 1f2a6e2bfea..1e9da42d40d 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -220,15 +220,15 @@ macro_rules! eprintln { macro_rules! await { ($e:expr) => { { let mut pinned = $e; - let mut pinned = unsafe { ::core::mem::PinMut::new_unchecked(&mut pinned) }; + let mut pinned = unsafe { $crate::mem::PinMut::new_unchecked(&mut pinned) }; loop { - match ::std::raw::with_get_cx(|cx| - ::core::future::Future::poll(pinned.reborrow(), cx)) + match $crate::future::get_task_cx(|cx| + $crate::future::Future::poll(pinned.reborrow(), cx)) { // FIXME(cramertj) prior to stabilizing await, we have to ensure that this // can't be used to create a generator on stable via `|| await!()`. - ::core::task::Poll::Pending => yield, - ::core::task::Poll::Ready(x) => break x, + $crate::task::Poll::Pending => yield, + $crate::task::Poll::Ready(x) => break x, } } } } |
