Skip to content

Commit e05773e

Browse files
hcplcramertj
authored andcommitted
Update syn, quote and proc-macro2
1 parent 6810513 commit e05773e

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

futures-macro-async/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ few other assorted macros.
1313
proc-macro = true
1414

1515
[dependencies]
16-
quote = "0.5"
17-
proc-macro2 = "0.3"
16+
quote = "0.6"
17+
proc-macro2 = "0.4.1"
1818

1919
[dependencies.syn]
20-
version = "0.13"
20+
version = "0.14"
2121
features = ["full", "fold", "parsing", "printing", "extra-traits", "proc-macro"]
2222
default-features = false
2323

futures-macro-async/src/lib.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ if_nightly! {
2828
#[macro_use]
2929
extern crate syn;
3030

31-
use proc_macro2::Span;
31+
use proc_macro2::{Ident, Span};
3232
use proc_macro::{Delimiter, Group, TokenStream, TokenTree};
33-
use quote::{Tokens, ToTokens};
33+
use quote::ToTokens;
3434
use syn::*;
3535
use syn::punctuated::Punctuated;
3636
use syn::fold::Fold;
@@ -47,7 +47,7 @@ if_nightly! {
4747
fn async_inner<F>(
4848
attribute: Attribute,
4949
function: TokenStream,
50-
gen_function: Tokens,
50+
gen_function: proc_macro2::TokenStream,
5151
return_ty: F,
5252
) -> TokenStream
5353
where F: FnOnce(&Type, &[&Lifetime]) -> proc_macro2::TokenStream
@@ -144,7 +144,7 @@ if_nightly! {
144144
// `ref a: B` (or some similar pattern)
145145
FnArg::Captured(ArgCaptured { pat, ty, colon_token }) => {
146146
patterns.push(pat);
147-
let ident = Ident::from(format!("__arg_{}", i));
147+
let ident = Ident::new(&format!("__arg_{}", i), Span::call_site());
148148
temp_bindings.push(ident.clone());
149149
let pat = PatIdent {
150150
by_ref: None,
@@ -187,7 +187,7 @@ if_nightly! {
187187
#( let #patterns = #temp_bindings; )*
188188
#block
189189
};
190-
let mut result = Tokens::new();
190+
let mut result = proc_macro2::TokenStream::empty();
191191
block.brace_token.surround(&mut result, |tokens| {
192192
block_inner.to_tokens(tokens);
193193
});
@@ -204,7 +204,7 @@ if_nightly! {
204204
loop { yield ::futures::__rt::Async::Pending }
205205
}
206206
};
207-
let mut gen_body = Tokens::new();
207+
let mut gen_body = proc_macro2::TokenStream::empty();
208208
block.brace_token.surround(&mut gen_body, |tokens| {
209209
gen_body_inner.to_tokens(tokens);
210210
});
@@ -228,7 +228,7 @@ if_nightly! {
228228
body_inner.into()
229229
};
230230

231-
let mut body = Tokens::new();
231+
let mut body = proc_macro2::TokenStream::empty();
232232
block.brace_token.surround(&mut body, |tokens| {
233233
body_inner.to_tokens(tokens);
234234
});
@@ -253,7 +253,7 @@ if_nightly! {
253253
let args = syn::parse::<AsyncArgs>(attribute)
254254
.expect(&format!("failed to parse attribute arguments: {}", attr));
255255

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()));
257257

258258
async_inner(attribute, function, quote_cs! { ::futures::__rt::gen_future }, |output, lifetimes| {
259259
// TODO: can we lift the restriction that `futures` must be at the root of
@@ -296,22 +296,22 @@ if_nightly! {
296296

297297
let mut item_ty = None;
298298

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() {
301301
"item" => {
302302
if item_ty.is_some() {
303303
panic!("duplicate 'item' argument");
304304
}
305305
item_ty = Some(ty);
306306
}
307307
_ => {
308-
panic!("unexpected macro argument '{}'", quote_cs!(#term = #ty));
308+
panic!("unexpected macro argument '{}'", quote_cs!(#ident = #ty));
309309
}
310310
}
311311
}
312312

313313
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()));
315315

316316
async_inner(attribute, function, quote_cs! { ::futures::__rt::gen_stream }, |output, lifetimes| {
317317
let return_ty = match attribute {
@@ -464,7 +464,7 @@ if_nightly! {
464464
}
465465

466466
fn first_last(tokens: &ToTokens) -> (Span, Span) {
467-
let mut spans = Tokens::new();
467+
let mut spans = proc_macro2::TokenStream::empty();
468468
tokens.to_tokens(&mut spans);
469469
let good_tokens = proc_macro2::TokenStream::from(spans).into_iter().collect::<Vec<_>>();
470470
let first_span = good_tokens.first().map(|t| t.span()).unwrap_or(Span::call_site());
@@ -487,10 +487,12 @@ if_nightly! {
487487
fn replace_bang(input: proc_macro2::TokenStream, tokens: &ToTokens)
488488
-> proc_macro2::TokenStream
489489
{
490-
let mut new_tokens = Tokens::new();
490+
let mut new_tokens = proc_macro2::TokenStream::empty();
491491
for token in input.into_iter() {
492492
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+
},
494496
_ => token.to_tokens(&mut new_tokens),
495497
}
496498
}
@@ -501,10 +503,10 @@ if_nightly! {
501503
-> proc_macro2::TokenStream
502504
{
503505
let mut replacements = replacements.iter().cycle();
504-
let mut new_tokens = Tokens::new();
506+
let mut new_tokens = proc_macro2::TokenStream::empty();
505507
for token in input.into_iter() {
506508
match token {
507-
proc_macro2::TokenTree::Op(op) if op.op() == '!' => {
509+
proc_macro2::TokenTree::Punct(ref punct) if punct.as_char() == '!' => {
508510
replacements.next().unwrap().to_tokens(&mut new_tokens);
509511
}
510512
_ => token.to_tokens(&mut new_tokens),

0 commit comments

Comments
 (0)