3
3
use proc_macro:: TokenStream ;
4
4
use proc_macro2:: Span ;
5
5
use quote:: { format_ident, quote} ;
6
- use syn:: { parenthesized , parse_quote, Expr , Ident , Pat , Token } ;
6
+ use syn:: { parse_quote, Expr , Ident , Pat , Token } ;
7
7
use syn:: parse:: { Parse , ParseStream } ;
8
8
9
9
mod kw {
10
10
syn:: custom_keyword!( complete) ;
11
- syn:: custom_keyword!( futures_crate_path) ;
12
11
}
13
12
14
13
struct Select {
15
- futures_crate_path : Option < syn:: Path > ,
16
14
// span of `complete`, then expression after `=> ...`
17
15
complete : Option < Expr > ,
18
16
default : Option < Expr > ,
@@ -30,23 +28,12 @@ enum CaseKind {
30
28
impl Parse for Select {
31
29
fn parse ( input : ParseStream < ' _ > ) -> syn:: Result < Self > {
32
30
let mut select = Select {
33
- futures_crate_path : None ,
34
31
complete : None ,
35
32
default : None ,
36
33
normal_fut_exprs : vec ! [ ] ,
37
34
normal_fut_handlers : vec ! [ ] ,
38
35
} ;
39
36
40
- // When `futures_crate_path(::path::to::futures::lib)` is provided,
41
- // it sets the path through which futures library functions will be
42
- // accessed.
43
- if input. peek ( kw:: futures_crate_path) {
44
- input. parse :: < kw:: futures_crate_path > ( ) ?;
45
- let content;
46
- parenthesized ! ( content in input) ;
47
- select. futures_crate_path = Some ( content. parse ( ) ?) ;
48
- }
49
-
50
37
while !input. is_empty ( ) {
51
38
let case_kind = if input. peek ( kw:: complete) {
52
39
// `complete`
@@ -147,8 +134,6 @@ pub(crate) fn select_biased(input: TokenStream) -> TokenStream {
147
134
fn select_inner ( input : TokenStream , random : bool ) -> TokenStream {
148
135
let parsed = syn:: parse_macro_input!( input as Select ) ;
149
136
150
- let futures_crate: syn:: Path = parsed. futures_crate_path . unwrap_or_else ( || parse_quote ! ( :: futures_util) ) ;
151
-
152
137
// should be def_site, but that's unstable
153
138
let span = Span :: call_site ( ) ;
154
139
@@ -175,8 +160,8 @@ fn select_inner(input: TokenStream, random: bool) -> TokenStream {
175
160
// We check for this condition here in order to be able to
176
161
// safely use Pin::new_unchecked(&mut #path) later on.
177
162
future_let_bindings. push ( quote ! {
178
- #futures_crate :: async_await:: assert_fused_future( & #path) ;
179
- #futures_crate :: async_await:: assert_unpin( & #path) ;
163
+ __futures_crate :: async_await:: assert_fused_future( & #path) ;
164
+ __futures_crate :: async_await:: assert_unpin( & #path) ;
180
165
} ) ;
181
166
path
182
167
} ,
@@ -214,28 +199,28 @@ fn select_inner(input: TokenStream, random: bool) -> TokenStream {
214
199
// 2. The Future is created in scope of the select! function and will
215
200
// not be moved for the duration of it. It is thereby stack-pinned
216
201
quote ! {
217
- let mut #variant_name = |__cx: & mut #futures_crate :: task:: Context <' _>| {
202
+ let mut #variant_name = |__cx: & mut __futures_crate :: task:: Context <' _>| {
218
203
let mut #bound_future_name = unsafe {
219
204
:: core:: pin:: Pin :: new_unchecked( & mut #bound_future_name)
220
205
} ;
221
- if #futures_crate :: future:: FusedFuture :: is_terminated( & #bound_future_name) {
206
+ if __futures_crate :: future:: FusedFuture :: is_terminated( & #bound_future_name) {
222
207
None
223
208
} else {
224
- Some ( #futures_crate :: future:: FutureExt :: poll_unpin(
209
+ Some ( __futures_crate :: future:: FutureExt :: poll_unpin(
225
210
& mut #bound_future_name,
226
211
__cx,
227
212
) . map( #enum_ident:: #variant_name) )
228
213
}
229
214
} ;
230
215
let #variant_name: & mut dyn FnMut (
231
- & mut #futures_crate :: task:: Context <' _>
232
- ) -> Option <#futures_crate :: task:: Poll <_>> = & mut #variant_name;
216
+ & mut __futures_crate :: task:: Context <' _>
217
+ ) -> Option <__futures_crate :: task:: Poll <_>> = & mut #variant_name;
233
218
}
234
219
} ) ;
235
220
236
221
let none_polled = if parsed. complete . is_some ( ) {
237
222
quote ! {
238
- #futures_crate :: task:: Poll :: Ready ( #enum_ident:: Complete )
223
+ __futures_crate :: task:: Poll :: Ready ( #enum_ident:: Complete )
239
224
}
240
225
} else {
241
226
quote ! {
@@ -267,21 +252,21 @@ fn select_inner(input: TokenStream, random: bool) -> TokenStream {
267
252
let await_select_fut = if parsed. default . is_some ( ) {
268
253
// For select! with default this returns the Poll result
269
254
quote ! {
270
- __poll_fn( & mut #futures_crate :: task:: Context :: from_waker(
271
- #futures_crate :: task:: noop_waker_ref( )
255
+ __poll_fn( & mut __futures_crate :: task:: Context :: from_waker(
256
+ __futures_crate :: task:: noop_waker_ref( )
272
257
) )
273
258
}
274
259
} else {
275
260
quote ! {
276
- #futures_crate :: future:: poll_fn( __poll_fn) . await
261
+ __futures_crate :: future:: poll_fn( __poll_fn) . await
277
262
}
278
263
} ;
279
264
280
265
let execute_result_expr = if let Some ( default_expr) = & parsed. default {
281
266
// For select! with default __select_result is a Poll, otherwise not
282
267
quote ! {
283
268
match __select_result {
284
- #futures_crate :: task:: Poll :: Ready ( result) => match result {
269
+ __futures_crate :: task:: Poll :: Ready ( result) => match result {
285
270
#branches
286
271
} ,
287
272
_ => #default_expr
@@ -297,7 +282,7 @@ fn select_inner(input: TokenStream, random: bool) -> TokenStream {
297
282
298
283
let shuffle = if random {
299
284
quote ! {
300
- #futures_crate :: async_await:: shuffle( & mut __select_arr) ;
285
+ __futures_crate :: async_await:: shuffle( & mut __select_arr) ;
301
286
}
302
287
} else {
303
288
quote ! ( )
@@ -309,7 +294,7 @@ fn select_inner(input: TokenStream, random: bool) -> TokenStream {
309
294
let __select_result = {
310
295
#( #future_let_bindings ) *
311
296
312
- let mut __poll_fn = |__cx: & mut #futures_crate :: task:: Context <' _>| {
297
+ let mut __poll_fn = |__cx: & mut __futures_crate :: task:: Context <' _>| {
313
298
let mut __any_polled = false ;
314
299
315
300
#( #poll_functions ) *
@@ -318,12 +303,12 @@ fn select_inner(input: TokenStream, random: bool) -> TokenStream {
318
303
#shuffle
319
304
for poller in & mut __select_arr {
320
305
let poller: & mut & mut dyn FnMut (
321
- & mut #futures_crate :: task:: Context <' _>
322
- ) -> Option <#futures_crate :: task:: Poll <_>> = poller;
306
+ & mut __futures_crate :: task:: Context <' _>
307
+ ) -> Option <__futures_crate :: task:: Poll <_>> = poller;
323
308
match poller( __cx) {
324
- Some ( x @ #futures_crate :: task:: Poll :: Ready ( _) ) =>
309
+ Some ( x @ __futures_crate :: task:: Poll :: Ready ( _) ) =>
325
310
return x,
326
- Some ( #futures_crate :: task:: Poll :: Pending ) => {
311
+ Some ( __futures_crate :: task:: Poll :: Pending ) => {
327
312
__any_polled = true ;
328
313
}
329
314
None => { }
@@ -333,7 +318,7 @@ fn select_inner(input: TokenStream, random: bool) -> TokenStream {
333
318
if !__any_polled {
334
319
#none_polled
335
320
} else {
336
- #futures_crate :: task:: Poll :: Pending
321
+ __futures_crate :: task:: Poll :: Pending
337
322
}
338
323
} ;
339
324
0 commit comments