Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support trailing commas in macros #1733

Merged
merged 1 commit into from Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
}