api-macro: update to 1.0 of syn/quote/proc_macro2

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-10-04 13:42:03 +02:00
parent e0b50d07bf
commit df55ab2dda
5 changed files with 24 additions and 25 deletions

View File

@ -10,9 +10,9 @@ proc-macro = true
[dependencies] [dependencies]
derive_builder = "0.7" derive_builder = "0.7"
failure = "0.1" failure = "0.1"
proc-macro2 = "0.4" proc-macro2 = "1.0"
quote = "0.6" quote = "1.0"
syn = { version = "0.15", features = [ "full" ] } syn = { version = "1.0", features = [ "full" ] }
[dev-dependencies] [dev-dependencies]
bytes = "0.4" bytes = "0.4"

View File

@ -9,7 +9,7 @@
use std::mem; use std::mem;
use proc_macro2::{Ident, Span, TokenStream}; use proc_macro2::TokenStream;
use failure::Error; use failure::Error;
use quote::quote_spanned; use quote::quote_spanned;
@ -26,8 +26,8 @@ where
{ {
let cap = attrs.len(); let cap = attrs.len();
for attr in mem::replace(attrs, Vec::with_capacity(cap)) { for attr in mem::replace(attrs, Vec::with_capacity(cap)) {
if attr.path.is_ident(Ident::new("api", Span::call_site())) { if attr.path.get_ident().map(|i| i == "api").unwrap_or(false) {
let attrs: util::ApiAttr = syn::parse2(attr.tts)?; let attrs: util::ApiAttr = syn::parse2(attr.tokens)?;
for attr in attrs.items { for attr in attrs.items {
func(attr)?; func(attr)?;

View File

@ -14,9 +14,9 @@ pub fn handle_function(
mut definition: Object, mut definition: Object,
mut item: syn::ItemFn, mut item: syn::ItemFn,
) -> Result<TokenStream, Error> { ) -> Result<TokenStream, Error> {
if item.decl.generics.lt_token.is_some() { if item.sig.generics.lt_token.is_some() {
c_bail!( c_bail!(
item.decl.generics.span(), item.sig.generics.span(),
"cannot use generic functions for api macros currently", "cannot use generic functions for api macros currently",
); );
// Not until we stabilize our generated representation! // Not until we stabilize our generated representation!
@ -64,16 +64,16 @@ pub fn handle_function(
let mut parameter_verifiers = TokenStream::new(); let mut parameter_verifiers = TokenStream::new();
let vis = std::mem::replace(&mut item.vis, syn::Visibility::Inherited); let vis = std::mem::replace(&mut item.vis, syn::Visibility::Inherited);
let span = item.ident.span(); let span = item.sig.ident.span();
let name_str = item.ident.to_string(); let name_str = item.sig.ident.to_string();
//let impl_str = format!("{}_impl", name_str); //let impl_str = format!("{}_impl", name_str);
//let impl_ident = Ident::new(&impl_str, span); //let impl_ident = Ident::new(&impl_str, span);
let impl_checked_str = format!("{}_checked_impl", name_str); let impl_checked_str = format!("{}_checked_impl", name_str);
let impl_checked_ident = Ident::new(&impl_checked_str, span); let impl_checked_ident = Ident::new(&impl_checked_str, span);
let impl_unchecked_str = format!("{}_unchecked_impl", name_str); let impl_unchecked_str = format!("{}_unchecked_impl", name_str);
let impl_unchecked_ident = Ident::new(&impl_unchecked_str, span); let impl_unchecked_ident = Ident::new(&impl_unchecked_str, span);
let name = std::mem::replace(&mut item.ident, impl_unchecked_ident.clone()); let name = std::mem::replace(&mut item.sig.ident, impl_unchecked_ident.clone());
let mut return_type = match item.decl.output { let mut return_type = match item.sig.output {
syn::ReturnType::Default => syn::Type::Tuple(syn::TypeTuple { syn::ReturnType::Default => syn::Type::Tuple(syn::TypeTuple {
paren_token: syn::token::Paren { paren_token: syn::token::Paren {
span: Span::call_site(), span: Span::call_site(),
@ -87,15 +87,15 @@ pub fn handle_function(
let mut passed_args = syn::punctuated::Punctuated::<Ident, Token![,]>::new(); let mut passed_args = syn::punctuated::Punctuated::<Ident, Token![,]>::new();
let mut arg_extraction = Vec::new(); let mut arg_extraction = Vec::new();
let inputs = item.decl.inputs.clone(); let inputs = item.sig.inputs.clone();
for arg in item.decl.inputs.iter() { for arg in item.sig.inputs.iter() {
let arg = match arg { let arg = match arg {
syn::FnArg::Captured(ref arg) => arg, syn::FnArg::Typed(ref arg) => arg,
other => bail!("unhandled type of method parameter ({:?})", other), other => bail!("unhandled type of method parameter ({:?})", other),
}; };
let arg_type = &arg.ty; let arg_type = &arg.ty;
let name = match &arg.pat { let name = match &*arg.pat {
syn::Pat::Ident(name) => &name.ident, syn::Pat::Ident(name) => &name.ident,
other => bail!("invalid kind of parameter pattern: {:?}", other), other => bail!("invalid kind of parameter pattern: {:?}", other),
}; };
@ -239,7 +239,7 @@ pub fn handle_function(
} }
}); });
if item.asyncness.is_some() { if item.sig.asyncness.is_some() {
// An async function is expected to return its value, so we wrap it a bit: // An async function is expected to return its value, so we wrap it a bit:
body.push(quote! { body.push(quote! {
impl #struct_name { impl #struct_name {
@ -270,8 +270,8 @@ pub fn handle_function(
}); });
} else { } else {
// Non async fn must return an ApiFuture already! // Non async fn must return an ApiFuture already!
return_type = syn::Type::Verbatim(syn::TypeVerbatim { return_type = syn::Type::Verbatim(
tts: definition definition
.remove("returns") .remove("returns")
.ok_or_else(|| { .ok_or_else(|| {
format_err!( format_err!(
@ -281,7 +281,7 @@ pub fn handle_function(
})? })?
.expect_type()? .expect_type()?
.into_token_stream(), .into_token_stream(),
}); );
body.push(quote! { body.push(quote! {
impl #struct_name { impl #struct_name {

View File

@ -24,8 +24,7 @@ pub fn handle_newtype(
let type_str = syn::LitStr::new(&type_s, type_span); let type_str = syn::LitStr::new(&type_s, type_span);
let fields = &item.unnamed; let fields = &item.unnamed;
let field_punct = fields.first().unwrap(); let field = fields.first().unwrap();
let field = field_punct.value();
let common = CommonTypeDefinition::from_object(&mut definition)?; let common = CommonTypeDefinition::from_object(&mut definition)?;
@ -141,7 +140,7 @@ fn newtype_filter_derive_attrs(
continue; continue;
} }
let mut content: syn::Expr = syn::parse2(attr.tts)?; let mut content: syn::Expr = syn::parse2(attr.tokens)?;
if let syn::Expr::Tuple(ref mut exprtuple) = content { if let syn::Expr::Tuple(ref mut exprtuple) = content {
for ty in mem::replace(&mut exprtuple.elems, syn::punctuated::Punctuated::new()) { for ty in mem::replace(&mut exprtuple.elems, syn::punctuated::Punctuated::new()) {
if let syn::Expr::Path(ref exprpath) = ty { if let syn::Expr::Path(ref exprpath) = ty {
@ -166,7 +165,7 @@ fn newtype_filter_derive_attrs(
exprtuple.elems.push(ty); exprtuple.elems.push(ty);
} }
} }
attr.tts = quote! { #content }; attr.tokens = quote! { #content };
attrs.push(attr); attrs.push(attr);
} }

View File

@ -298,7 +298,7 @@ impl Expression {
pub fn is_ident(&self, ident: &str) -> bool { pub fn is_ident(&self, ident: &str) -> bool {
match self { match self {
Expression::Expr(expr) => match expr { Expression::Expr(expr) => match expr {
Expr::Path(path) => path.path.is_ident(Ident::new(ident, Span::call_site())), Expr::Path(path) => path.path.get_ident().map(|i| i == ident).unwrap_or(false),
_ => false, _ => false,
}, },
_ => false, _ => false,