@@ -28,9 +28,9 @@ if_nightly! {
28
28
#[ macro_use]
29
29
extern crate syn;
30
30
31
- use proc_macro2:: Span ;
31
+ use proc_macro2:: { Ident , Span } ;
32
32
use proc_macro:: { Delimiter , Group , TokenStream , TokenTree } ;
33
- use quote:: { Tokens , ToTokens } ;
33
+ use quote:: ToTokens ;
34
34
use syn:: * ;
35
35
use syn:: punctuated:: Punctuated ;
36
36
use syn:: fold:: Fold ;
@@ -47,7 +47,7 @@ if_nightly! {
47
47
fn async_inner<F >(
48
48
attribute: Attribute ,
49
49
function: TokenStream ,
50
- gen_function: Tokens ,
50
+ gen_function: proc_macro2 :: TokenStream ,
51
51
return_ty: F ,
52
52
) -> TokenStream
53
53
where F : FnOnce ( & Type , & [ & Lifetime ] ) -> proc_macro2:: TokenStream
@@ -144,7 +144,7 @@ if_nightly! {
144
144
// `ref a: B` (or some similar pattern)
145
145
FnArg :: Captured ( ArgCaptured { pat, ty, colon_token } ) => {
146
146
patterns. push( pat) ;
147
- let ident = Ident :: from ( format!( "__arg_{}" , i) ) ;
147
+ let ident = Ident :: new ( & format!( "__arg_{}" , i) , Span :: call_site ( ) ) ;
148
148
temp_bindings. push( ident. clone( ) ) ;
149
149
let pat = PatIdent {
150
150
by_ref: None ,
@@ -187,7 +187,7 @@ if_nightly! {
187
187
#( let #patterns = #temp_bindings; ) *
188
188
#block
189
189
} ;
190
- let mut result = Tokens :: new ( ) ;
190
+ let mut result = proc_macro2 :: TokenStream :: empty ( ) ;
191
191
block. brace_token. surround( & mut result, |tokens| {
192
192
block_inner. to_tokens( tokens) ;
193
193
} ) ;
@@ -204,7 +204,7 @@ if_nightly! {
204
204
loop { yield :: futures:: __rt:: Async :: Pending }
205
205
}
206
206
} ;
207
- let mut gen_body = Tokens :: new ( ) ;
207
+ let mut gen_body = proc_macro2 :: TokenStream :: empty ( ) ;
208
208
block. brace_token. surround( & mut gen_body, |tokens| {
209
209
gen_body_inner. to_tokens( tokens) ;
210
210
} ) ;
@@ -228,7 +228,7 @@ if_nightly! {
228
228
body_inner. into( )
229
229
} ;
230
230
231
- let mut body = Tokens :: new ( ) ;
231
+ let mut body = proc_macro2 :: TokenStream :: empty ( ) ;
232
232
block. brace_token. surround( & mut body, |tokens| {
233
233
body_inner. to_tokens( tokens) ;
234
234
} ) ;
@@ -253,7 +253,7 @@ if_nightly! {
253
253
let args = syn:: parse:: <AsyncArgs >( attribute)
254
254
. expect( & format!( "failed to parse attribute arguments: {}" , attr) ) ;
255
255
256
- let attribute = Attribute :: from( args. 0 . into_iter( ) . map( |arg| arg. 0 ) ) ;
256
+ let attribute = Attribute :: from( args. 0 . into_iter( ) . map( |arg| arg. 0 . to_string ( ) ) ) ;
257
257
258
258
async_inner( attribute, function, quote_cs! { :: futures:: __rt:: gen_future } , |output, lifetimes| {
259
259
// TODO: can we lift the restriction that `futures` must be at the root of
@@ -296,22 +296,22 @@ if_nightly! {
296
296
297
297
let mut item_ty = None ;
298
298
299
- for ( term , ty) in valued_args {
300
- match term . as_ref ( ) {
299
+ for ( ident , ty) in valued_args {
300
+ match ident . to_string ( ) . as_str ( ) {
301
301
"item" => {
302
302
if item_ty. is_some( ) {
303
303
panic!( "duplicate 'item' argument" ) ;
304
304
}
305
305
item_ty = Some ( ty) ;
306
306
}
307
307
_ => {
308
- panic!( "unexpected macro argument '{}'" , quote_cs!( #term = #ty) ) ;
308
+ panic!( "unexpected macro argument '{}'" , quote_cs!( #ident = #ty) ) ;
309
309
}
310
310
}
311
311
}
312
312
313
313
let item_ty = item_ty. expect( "#[async_stream] requires item type to be specified" ) ;
314
- let attribute = Attribute :: from( args) ;
314
+ let attribute = Attribute :: from( args. map ( |arg| arg . to_string ( ) ) ) ;
315
315
316
316
async_inner( attribute, function, quote_cs! { :: futures:: __rt:: gen_stream } , |output, lifetimes| {
317
317
let return_ty = match attribute {
@@ -464,7 +464,7 @@ if_nightly! {
464
464
}
465
465
466
466
fn first_last( tokens: & ToTokens ) -> ( Span , Span ) {
467
- let mut spans = Tokens :: new ( ) ;
467
+ let mut spans = proc_macro2 :: TokenStream :: empty ( ) ;
468
468
tokens. to_tokens( & mut spans) ;
469
469
let good_tokens = proc_macro2:: TokenStream :: from( spans) . into_iter( ) . collect:: <Vec <_>>( ) ;
470
470
let first_span = good_tokens. first( ) . map( |t| t. span( ) ) . unwrap_or( Span :: call_site( ) ) ;
@@ -487,10 +487,12 @@ if_nightly! {
487
487
fn replace_bang( input: proc_macro2:: TokenStream , tokens: & ToTokens )
488
488
-> proc_macro2:: TokenStream
489
489
{
490
- let mut new_tokens = Tokens :: new ( ) ;
490
+ let mut new_tokens = proc_macro2 :: TokenStream :: empty ( ) ;
491
491
for token in input. into_iter( ) {
492
492
match token {
493
- proc_macro2:: TokenTree :: Op ( op) if op. op( ) == '!' => tokens. to_tokens( & mut new_tokens) ,
493
+ proc_macro2:: TokenTree :: Punct ( ref punct) if punct. as_char( ) == '!' => {
494
+ tokens. to_tokens( & mut new_tokens)
495
+ } ,
494
496
_ => token. to_tokens( & mut new_tokens) ,
495
497
}
496
498
}
@@ -501,10 +503,10 @@ if_nightly! {
501
503
-> proc_macro2:: TokenStream
502
504
{
503
505
let mut replacements = replacements. iter( ) . cycle( ) ;
504
- let mut new_tokens = Tokens :: new ( ) ;
506
+ let mut new_tokens = proc_macro2 :: TokenStream :: empty ( ) ;
505
507
for token in input. into_iter( ) {
506
508
match token {
507
- proc_macro2:: TokenTree :: Op ( op ) if op . op ( ) == '!' => {
509
+ proc_macro2:: TokenTree :: Punct ( ref punct ) if punct . as_char ( ) == '!' => {
508
510
replacements. next( ) . unwrap( ) . to_tokens( & mut new_tokens) ;
509
511
}
510
512
_ => token. to_tokens( & mut new_tokens) ,
0 commit comments