Skip to content

Commit

Permalink
Rollup merge of rust-lang#81050 - yoshuawuyts:stabilize-task-ready, r…
Browse files Browse the repository at this point in the history
…=m-ou-se

Stabilize core::task::ready!

_Tracking issue: https://github.com/rust-lang/rust/issues/70922_

This PR stabilizes the `task::ready!` macro. Similar to rust-lang#80886, this PR was waiting on rust-lang#74355 to be fixed.

The `task::ready!` API has existed in the futures ecosystem for several years, and was added on nightly last year in rust-lang#70817. The motivation for this macro is the same as it was back then: virtually every single manual future implementation makes use of this; so much so that it's one of the few things included in the [futures-core](https://docs.rs/futures-core/0.3.12/futures_core) library.

r? `@tmandry`

cc/ `@rust-lang/wg-async-foundations` `@rust-lang/libs`

## Example
```rust
use core::task::{Context, Poll};
use core::future::Future;
use core::pin::Pin;

async fn get_num() -> usize {
    42
}

pub fn do_poll(cx: &mut Context<'_>) -> Poll<()> {
    let mut f = get_num();
    let f = unsafe { Pin::new_unchecked(&mut f) };

    let num = ready!(f.poll(cx));
    // ... use num

    Poll::Ready(())
}
```
  • Loading branch information
JohnTitor authored Jul 28, 2021
2 parents a28109a + 18cc06c commit f3fc3f2
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion library/core/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ mod wake;
pub use self::wake::{Context, RawWaker, RawWakerVTable, Waker};

mod ready;
#[unstable(feature = "ready_macro", issue = "70922")]
#[stable(feature = "ready_macro", since = "1.56.0")]
pub use ready::ready;
6 changes: 1 addition & 5 deletions library/core/src/task/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
/// # Examples
///
/// ```
/// #![feature(ready_macro)]
///
/// use std::task::{ready, Context, Poll};
/// use std::future::{self, Future};
/// use std::pin::Pin;
Expand All @@ -29,8 +27,6 @@
/// The `ready!` call expands to:
///
/// ```
/// # #![feature(ready_macro)]
/// #
/// # use std::task::{Context, Poll};
/// # use std::future::{self, Future};
/// # use std::pin::Pin;
Expand All @@ -49,7 +45,7 @@
/// # Poll::Ready(())
/// # }
/// ```
#[unstable(feature = "ready_macro", issue = "70922")]
#[stable(feature = "ready_macro", since = "1.56.0")]
#[rustc_macro_transparency = "semitransparent"]
pub macro ready($e:expr) {
match $e {
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@
#![feature(pin_static_ref)]
#![feature(prelude_import)]
#![feature(ptr_internals)]
#![feature(ready_macro)]
#![feature(rustc_attrs)]
#![feature(rustc_private)]
#![feature(shrink_to)]
Expand Down

0 comments on commit f3fc3f2

Please sign in to comment.