Skip to content

Commit 621d491

Browse files
taiki-ecramertj
authored andcommitted
Support trailing commas in macros
1 parent 4937dd6 commit 621d491

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

futures-core/src/task/poll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// This macro bakes in propagation of `Pending` signals by returning early.
44
#[macro_export]
55
macro_rules! ready {
6-
($e:expr) => (match $e {
6+
($e:expr $(,)?) => (match $e {
77
$crate::core_reexport::task::Poll::Ready(t) => t,
88
$crate::core_reexport::task::Poll::Pending =>
99
return $crate::core_reexport::task::Poll::Pending,

futures-util/src/async_await/join.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/// ```
2626
#[macro_export]
2727
macro_rules! join {
28-
($($fut:ident),*) => { {
28+
($($fut:ident),* $(,)?) => { {
2929
$(
3030
// Move future into a local so that it is pinned in one place and
3131
// is no longer accessible by the end user.
@@ -91,7 +91,7 @@ macro_rules! join {
9191
/// ```
9292
#[macro_export]
9393
macro_rules! try_join {
94-
($($fut:ident),*) => { {
94+
($($fut:ident),* $(,)?) => { {
9595
$(
9696
// Move future into a local so that it is pinned in one place and
9797
// is no longer accessible by the end user.

futures-util/src/async_await/poll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use futures_core::task::{Context, Poll};
1111
/// _not_ activated by default.
1212
#[macro_export]
1313
macro_rules! poll {
14-
($x:expr) => {
14+
($x:expr $(,)?) => {
1515
$crate::async_await::poll($x).await
1616
}
1717
}

futures/tests/macro_comma_support.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#![feature(async_await)]
2+
3+
#[macro_use]
4+
extern crate futures;
5+
6+
use futures::{
7+
executor::block_on,
8+
future::{self, FutureExt},
9+
task::Poll,
10+
};
11+
12+
#[test]
13+
fn ready() {
14+
block_on(future::poll_fn(|_| {
15+
ready!(Poll::Ready(()),);
16+
Poll::Ready(())
17+
}))
18+
}
19+
20+
#[test]
21+
fn poll() {
22+
block_on(async {
23+
let _ = poll!(async { () }.boxed(),);
24+
})
25+
}
26+
27+
#[test]
28+
fn join() {
29+
block_on(async {
30+
let future1 = async { 1 };
31+
let future2 = async { 2 };
32+
join!(future1, future2,);
33+
})
34+
}
35+
36+
#[test]
37+
fn try_join() {
38+
block_on(async {
39+
let future1 = async { 1 }.never_error();
40+
let future2 = async { 2 }.never_error();
41+
try_join!(future1, future2,)
42+
})
43+
.unwrap();
44+
}

0 commit comments

Comments
 (0)