@@ -4,32 +4,17 @@ use proc_macro::TokenStream;
4
4
use proc_macro2:: { Span , TokenStream as TokenStream2 } ;
5
5
use quote:: { format_ident, quote} ;
6
6
use syn:: parse:: { Parse , ParseStream } ;
7
- use syn:: { parenthesized, parse_quote, Expr , Ident , Token } ;
8
-
9
- mod kw {
10
- syn:: custom_keyword!( futures_crate_path) ;
11
- }
7
+ use syn:: { Expr , Ident , Token } ;
12
8
13
9
#[ derive( Default ) ]
14
10
struct Join {
15
- futures_crate_path : Option < syn:: Path > ,
16
11
fut_exprs : Vec < Expr > ,
17
12
}
18
13
19
14
impl Parse for Join {
20
15
fn parse ( input : ParseStream < ' _ > ) -> syn:: Result < Self > {
21
16
let mut join = Join :: default ( ) ;
22
17
23
- // When `futures_crate_path(::path::to::futures::lib)` is provided,
24
- // it sets the path through which futures library functions will be
25
- // accessed.
26
- if input. peek ( kw:: futures_crate_path) {
27
- input. parse :: < kw:: futures_crate_path > ( ) ?;
28
- let content;
29
- parenthesized ! ( content in input) ;
30
- join. futures_crate_path = Some ( content. parse ( ) ?) ;
31
- }
32
-
33
18
while !input. is_empty ( ) {
34
19
join. fut_exprs . push ( input. parse :: < Expr > ( ) ?) ;
35
20
@@ -43,7 +28,6 @@ impl Parse for Join {
43
28
}
44
29
45
30
fn bind_futures (
46
- futures_crate : & syn:: Path ,
47
31
fut_exprs : Vec < Expr > ,
48
32
span : Span ,
49
33
) -> ( Vec < TokenStream2 > , Vec < Ident > ) {
@@ -56,7 +40,7 @@ fn bind_futures(
56
40
future_let_bindings. push ( quote ! {
57
41
// Move future into a local so that it is pinned in one place and
58
42
// is no longer accessible by the end user.
59
- let mut #name = #futures_crate :: future:: maybe_done( #expr) ;
43
+ let mut #name = __futures_crate :: future:: maybe_done( #expr) ;
60
44
} ) ;
61
45
name
62
46
} )
@@ -69,39 +53,35 @@ fn bind_futures(
69
53
pub ( crate ) fn join ( input : TokenStream ) -> TokenStream {
70
54
let parsed = syn:: parse_macro_input!( input as Join ) ;
71
55
72
- let futures_crate = parsed
73
- . futures_crate_path
74
- . unwrap_or_else ( || parse_quote ! ( :: futures_util) ) ;
75
-
76
56
// should be def_site, but that's unstable
77
57
let span = Span :: call_site ( ) ;
78
58
79
- let ( future_let_bindings, future_names) = bind_futures ( & futures_crate , parsed. fut_exprs , span) ;
59
+ let ( future_let_bindings, future_names) = bind_futures ( parsed. fut_exprs , span) ;
80
60
81
61
let poll_futures = future_names. iter ( ) . map ( |fut| {
82
62
quote ! {
83
- __all_done &= #futures_crate :: core_reexport :: future:: Future :: poll(
84
- unsafe { #futures_crate :: core_reexport:: pin:: Pin :: new_unchecked( & mut #fut) } , __cx) . is_ready( ) ;
63
+ __all_done &= __futures_crate :: future:: Future :: poll(
64
+ unsafe { __futures_crate :: core_reexport:: pin:: Pin :: new_unchecked( & mut #fut) } , __cx) . is_ready( ) ;
85
65
}
86
66
} ) ;
87
67
let take_outputs = future_names. iter ( ) . map ( |fut| {
88
68
quote ! {
89
- unsafe { #futures_crate :: core_reexport:: pin:: Pin :: new_unchecked( & mut #fut) } . take_output( ) . unwrap( ) ,
69
+ unsafe { __futures_crate :: core_reexport:: pin:: Pin :: new_unchecked( & mut #fut) } . take_output( ) . unwrap( ) ,
90
70
}
91
71
} ) ;
92
72
93
73
TokenStream :: from ( quote ! { {
94
74
#( #future_let_bindings ) *
95
75
96
- #futures_crate :: future:: poll_fn( move |__cx: & mut #futures_crate :: task:: Context <' _>| {
76
+ __futures_crate :: future:: poll_fn( move |__cx: & mut __futures_crate :: task:: Context <' _>| {
97
77
let mut __all_done = true ;
98
78
#( #poll_futures ) *
99
79
if __all_done {
100
- #futures_crate :: core_reexport :: task:: Poll :: Ready ( (
80
+ __futures_crate :: task:: Poll :: Ready ( (
101
81
#( #take_outputs ) *
102
82
) )
103
83
} else {
104
- #futures_crate :: core_reexport :: task:: Poll :: Pending
84
+ __futures_crate :: task:: Poll :: Pending
105
85
}
106
86
} ) . await
107
87
} } )
@@ -111,29 +91,25 @@ pub(crate) fn join(input: TokenStream) -> TokenStream {
111
91
pub ( crate ) fn try_join ( input : TokenStream ) -> TokenStream {
112
92
let parsed = syn:: parse_macro_input!( input as Join ) ;
113
93
114
- let futures_crate = parsed
115
- . futures_crate_path
116
- . unwrap_or_else ( || parse_quote ! ( :: futures_util) ) ;
117
-
118
94
// should be def_site, but that's unstable
119
95
let span = Span :: call_site ( ) ;
120
96
121
- let ( future_let_bindings, future_names) = bind_futures ( & futures_crate , parsed. fut_exprs , span) ;
97
+ let ( future_let_bindings, future_names) = bind_futures ( parsed. fut_exprs , span) ;
122
98
123
99
let poll_futures = future_names. iter ( ) . map ( |fut| {
124
100
quote ! {
125
- if #futures_crate :: core_reexport :: future:: Future :: poll(
126
- unsafe { #futures_crate :: core_reexport:: pin:: Pin :: new_unchecked( & mut #fut) } , __cx) . is_pending( )
101
+ if __futures_crate :: future:: Future :: poll(
102
+ unsafe { __futures_crate :: core_reexport:: pin:: Pin :: new_unchecked( & mut #fut) } , __cx) . is_pending( )
127
103
{
128
104
__all_done = false ;
129
- } else if unsafe { #futures_crate :: core_reexport:: pin:: Pin :: new_unchecked( & mut #fut) } . output_mut( ) . unwrap( ) . is_err( ) {
105
+ } else if unsafe { __futures_crate :: core_reexport:: pin:: Pin :: new_unchecked( & mut #fut) } . output_mut( ) . unwrap( ) . is_err( ) {
130
106
// `.err().unwrap()` rather than `.unwrap_err()` so that we don't introduce
131
107
// a `T: Debug` bound.
132
108
// Also, for an error type of ! any code after `err().unwrap()` is unreachable.
133
109
#[ allow( unreachable_code) ]
134
- return #futures_crate :: core_reexport :: task:: Poll :: Ready (
135
- #futures_crate :: core_reexport:: result:: Result :: Err (
136
- unsafe { #futures_crate :: core_reexport:: pin:: Pin :: new_unchecked( & mut #fut) } . take_output( ) . unwrap( ) . err( ) . unwrap( )
110
+ return __futures_crate :: task:: Poll :: Ready (
111
+ __futures_crate :: core_reexport:: result:: Result :: Err (
112
+ unsafe { __futures_crate :: core_reexport:: pin:: Pin :: new_unchecked( & mut #fut) } . take_output( ) . unwrap( ) . err( ) . unwrap( )
137
113
)
138
114
) ;
139
115
}
@@ -145,25 +121,25 @@ pub(crate) fn try_join(input: TokenStream) -> TokenStream {
145
121
// an `E: Debug` bound.
146
122
// Also, for an ok type of ! any code after `ok().unwrap()` is unreachable.
147
123
#[ allow( unreachable_code) ]
148
- unsafe { #futures_crate :: core_reexport:: pin:: Pin :: new_unchecked( & mut #fut) } . take_output( ) . unwrap( ) . ok( ) . unwrap( ) ,
124
+ unsafe { __futures_crate :: core_reexport:: pin:: Pin :: new_unchecked( & mut #fut) } . take_output( ) . unwrap( ) . ok( ) . unwrap( ) ,
149
125
}
150
126
} ) ;
151
127
152
128
TokenStream :: from ( quote ! { {
153
129
#( #future_let_bindings ) *
154
130
155
131
#[ allow( clippy:: diverging_sub_expression) ]
156
- #futures_crate :: future:: poll_fn( move |__cx: & mut #futures_crate :: task:: Context <' _>| {
132
+ __futures_crate :: future:: poll_fn( move |__cx: & mut __futures_crate :: task:: Context <' _>| {
157
133
let mut __all_done = true ;
158
134
#( #poll_futures ) *
159
135
if __all_done {
160
- #futures_crate :: core_reexport :: task:: Poll :: Ready (
161
- #futures_crate :: core_reexport:: result:: Result :: Ok ( (
136
+ __futures_crate :: task:: Poll :: Ready (
137
+ __futures_crate :: core_reexport:: result:: Result :: Ok ( (
162
138
#( #take_outputs ) *
163
139
) )
164
140
)
165
141
} else {
166
- #futures_crate :: core_reexport :: task:: Poll :: Pending
142
+ __futures_crate :: task:: Poll :: Pending
167
143
}
168
144
} ) . await
169
145
} } )
0 commit comments