Skip to content

Commit

Permalink
Support trailing commas in macros
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e authored and cramertj committed Jul 15, 2019
1 parent 4937dd6 commit 621d491
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion futures-core/src/task/poll.rs
Expand Up @@ -3,7 +3,7 @@
/// This macro bakes in propagation of `Pending` signals by returning early.
#[macro_export]
macro_rules! ready {
($e:expr) => (match $e {
($e:expr $(,)?) => (match $e {
$crate::core_reexport::task::Poll::Ready(t) => t,
$crate::core_reexport::task::Poll::Pending =>
return $crate::core_reexport::task::Poll::Pending,
Expand Down
4 changes: 2 additions & 2 deletions futures-util/src/async_await/join.rs
Expand Up @@ -25,7 +25,7 @@
/// ```
#[macro_export]
macro_rules! join {
($($fut:ident),*) => { {
($($fut:ident),* $(,)?) => { {
$(
// Move future into a local so that it is pinned in one place and
// is no longer accessible by the end user.
Expand Down Expand Up @@ -91,7 +91,7 @@ macro_rules! join {
/// ```
#[macro_export]
macro_rules! try_join {
($($fut:ident),*) => { {
($($fut:ident),* $(,)?) => { {
$(
// Move future into a local so that it is pinned in one place and
// is no longer accessible by the end user.
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/async_await/poll.rs
Expand Up @@ -11,7 +11,7 @@ use futures_core::task::{Context, Poll};
/// _not_ activated by default.
#[macro_export]
macro_rules! poll {
($x:expr) => {
($x:expr $(,)?) => {
$crate::async_await::poll($x).await
}
}
Expand Down
44 changes: 44 additions & 0 deletions futures/tests/macro_comma_support.rs
@@ -0,0 +1,44 @@
#![feature(async_await)]

#[macro_use]
extern crate futures;

use futures::{
executor::block_on,
future::{self, FutureExt},
task::Poll,
};

#[test]
fn ready() {
block_on(future::poll_fn(|_| {
ready!(Poll::Ready(()),);
Poll::Ready(())
}))
}

#[test]
fn poll() {
block_on(async {
let _ = poll!(async { () }.boxed(),);
})
}

#[test]
fn join() {
block_on(async {
let future1 = async { 1 };
let future2 = async { 2 };
join!(future1, future2,);
})
}

#[test]
fn try_join() {
block_on(async {
let future1 = async { 1 }.never_error();
let future2 = async { 2 }.never_error();
try_join!(future1, future2,)
})
.unwrap();
}

0 comments on commit 621d491

Please sign in to comment.