Skip to content

Update syn, quote and proc-macro2 #1021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions futures-macro-async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ few other assorted macros.
proc-macro = true

[dependencies]
quote = "0.5"
proc-macro2 = "0.3"
quote = "0.6"
proc-macro2 = "0.4.1"

[dependencies.syn]
version = "0.13"
version = "0.14"
features = ["full", "fold", "parsing", "printing", "extra-traits", "proc-macro"]
default-features = false

Expand Down
36 changes: 19 additions & 17 deletions futures-macro-async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ if_nightly! {
#[macro_use]
extern crate syn;

use proc_macro2::Span;
use proc_macro2::{Ident, Span};
use proc_macro::{Delimiter, Group, TokenStream, TokenTree};
use quote::{Tokens, ToTokens};
use quote::ToTokens;
use syn::*;
use syn::punctuated::Punctuated;
use syn::fold::Fold;
Expand All @@ -47,7 +47,7 @@ if_nightly! {
fn async_inner<F>(
attribute: Attribute,
function: TokenStream,
gen_function: Tokens,
gen_function: proc_macro2::TokenStream,
return_ty: F,
) -> TokenStream
where F: FnOnce(&Type, &[&Lifetime]) -> proc_macro2::TokenStream
Expand Down Expand Up @@ -144,7 +144,7 @@ if_nightly! {
// `ref a: B` (or some similar pattern)
FnArg::Captured(ArgCaptured { pat, ty, colon_token }) => {
patterns.push(pat);
let ident = Ident::from(format!("__arg_{}", i));
let ident = Ident::new(&format!("__arg_{}", i), Span::call_site());
temp_bindings.push(ident.clone());
let pat = PatIdent {
by_ref: None,
Expand Down Expand Up @@ -187,7 +187,7 @@ if_nightly! {
#( let #patterns = #temp_bindings; )*
#block
};
let mut result = Tokens::new();
let mut result = proc_macro2::TokenStream::empty();
block.brace_token.surround(&mut result, |tokens| {
block_inner.to_tokens(tokens);
});
Expand All @@ -204,7 +204,7 @@ if_nightly! {
loop { yield ::futures::__rt::Async::Pending }
}
};
let mut gen_body = Tokens::new();
let mut gen_body = proc_macro2::TokenStream::empty();
block.brace_token.surround(&mut gen_body, |tokens| {
gen_body_inner.to_tokens(tokens);
});
Expand All @@ -228,7 +228,7 @@ if_nightly! {
body_inner.into()
};

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

let attribute = Attribute::from(args.0.into_iter().map(|arg| arg.0));
let attribute = Attribute::from(args.0.into_iter().map(|arg| arg.0.to_string()));

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

let mut item_ty = None;

for (term, ty) in valued_args {
match term.as_ref() {
for (ident, ty) in valued_args {
match ident.to_string().as_str() {
"item" => {
if item_ty.is_some() {
panic!("duplicate 'item' argument");
}
item_ty = Some(ty);
}
_ => {
panic!("unexpected macro argument '{}'", quote_cs!(#term = #ty));
panic!("unexpected macro argument '{}'", quote_cs!(#ident = #ty));
}
}
}

let item_ty = item_ty.expect("#[async_stream] requires item type to be specified");
let attribute = Attribute::from(args);
let attribute = Attribute::from(args.map(|arg| arg.to_string()));

async_inner(attribute, function, quote_cs! { ::futures::__rt::gen_stream }, |output, lifetimes| {
let return_ty = match attribute {
Expand Down Expand Up @@ -464,7 +464,7 @@ if_nightly! {
}

fn first_last(tokens: &ToTokens) -> (Span, Span) {
let mut spans = Tokens::new();
let mut spans = proc_macro2::TokenStream::empty();
tokens.to_tokens(&mut spans);
let good_tokens = proc_macro2::TokenStream::from(spans).into_iter().collect::<Vec<_>>();
let first_span = good_tokens.first().map(|t| t.span()).unwrap_or(Span::call_site());
Expand All @@ -487,10 +487,12 @@ if_nightly! {
fn replace_bang(input: proc_macro2::TokenStream, tokens: &ToTokens)
-> proc_macro2::TokenStream
{
let mut new_tokens = Tokens::new();
let mut new_tokens = proc_macro2::TokenStream::empty();
for token in input.into_iter() {
match token {
proc_macro2::TokenTree::Op(op) if op.op() == '!' => tokens.to_tokens(&mut new_tokens),
proc_macro2::TokenTree::Punct(ref punct) if punct.as_char() == '!' => {
tokens.to_tokens(&mut new_tokens)
},
_ => token.to_tokens(&mut new_tokens),
}
}
Expand All @@ -501,10 +503,10 @@ if_nightly! {
-> proc_macro2::TokenStream
{
let mut replacements = replacements.iter().cycle();
let mut new_tokens = Tokens::new();
let mut new_tokens = proc_macro2::TokenStream::empty();
for token in input.into_iter() {
match token {
proc_macro2::TokenTree::Op(op) if op.op() == '!' => {
proc_macro2::TokenTree::Punct(ref punct) if punct.as_char() == '!' => {
replacements.next().unwrap().to_tokens(&mut new_tokens);
}
_ => token.to_tokens(&mut new_tokens),
Expand Down