diff --git a/proxmox-api-macro/Cargo.toml b/proxmox-api-macro/Cargo.toml index 2eff89a9..7a21d4b2 100644 --- a/proxmox-api-macro/Cargo.toml +++ b/proxmox-api-macro/Cargo.toml @@ -10,9 +10,9 @@ proc-macro = true [dependencies] derive_builder = "0.7" failure = "0.1" -proc-macro2 = "0.4" -quote = "0.6" -syn = { version = "0.15", features = [ "full" ] } +proc-macro2 = "1.0" +quote = "1.0" +syn = { version = "1.0", features = [ "full" ] } [dev-dependencies] bytes = "0.4" diff --git a/proxmox-api-macro/src/api_macro/enum_types.rs b/proxmox-api-macro/src/api_macro/enum_types.rs index 68988a0f..1fe2ba64 100644 --- a/proxmox-api-macro/src/api_macro/enum_types.rs +++ b/proxmox-api-macro/src/api_macro/enum_types.rs @@ -9,7 +9,7 @@ use std::mem; -use proc_macro2::{Ident, Span, TokenStream}; +use proc_macro2::TokenStream; use failure::Error; use quote::quote_spanned; @@ -26,8 +26,8 @@ where { let cap = attrs.len(); for attr in mem::replace(attrs, Vec::with_capacity(cap)) { - if attr.path.is_ident(Ident::new("api", Span::call_site())) { - let attrs: util::ApiAttr = syn::parse2(attr.tts)?; + if attr.path.get_ident().map(|i| i == "api").unwrap_or(false) { + let attrs: util::ApiAttr = syn::parse2(attr.tokens)?; for attr in attrs.items { func(attr)?; diff --git a/proxmox-api-macro/src/api_macro/function.rs b/proxmox-api-macro/src/api_macro/function.rs index f1cdcc3d..4d8a30e7 100644 --- a/proxmox-api-macro/src/api_macro/function.rs +++ b/proxmox-api-macro/src/api_macro/function.rs @@ -14,9 +14,9 @@ pub fn handle_function( mut definition: Object, mut item: syn::ItemFn, ) -> Result { - if item.decl.generics.lt_token.is_some() { + if item.sig.generics.lt_token.is_some() { c_bail!( - item.decl.generics.span(), + item.sig.generics.span(), "cannot use generic functions for api macros currently", ); // Not until we stabilize our generated representation! @@ -64,16 +64,16 @@ pub fn handle_function( let mut parameter_verifiers = TokenStream::new(); let vis = std::mem::replace(&mut item.vis, syn::Visibility::Inherited); - let span = item.ident.span(); - let name_str = item.ident.to_string(); + let span = item.sig.ident.span(); + let name_str = item.sig.ident.to_string(); //let impl_str = format!("{}_impl", name_str); //let impl_ident = Ident::new(&impl_str, span); let impl_checked_str = format!("{}_checked_impl", name_str); let impl_checked_ident = Ident::new(&impl_checked_str, span); let impl_unchecked_str = format!("{}_unchecked_impl", name_str); let impl_unchecked_ident = Ident::new(&impl_unchecked_str, span); - let name = std::mem::replace(&mut item.ident, impl_unchecked_ident.clone()); - let mut return_type = match item.decl.output { + let name = std::mem::replace(&mut item.sig.ident, impl_unchecked_ident.clone()); + let mut return_type = match item.sig.output { syn::ReturnType::Default => syn::Type::Tuple(syn::TypeTuple { paren_token: syn::token::Paren { span: Span::call_site(), @@ -87,15 +87,15 @@ pub fn handle_function( let mut passed_args = syn::punctuated::Punctuated::::new(); let mut arg_extraction = Vec::new(); - let inputs = item.decl.inputs.clone(); - for arg in item.decl.inputs.iter() { + let inputs = item.sig.inputs.clone(); + for arg in item.sig.inputs.iter() { let arg = match arg { - syn::FnArg::Captured(ref arg) => arg, + syn::FnArg::Typed(ref arg) => arg, other => bail!("unhandled type of method parameter ({:?})", other), }; let arg_type = &arg.ty; - let name = match &arg.pat { + let name = match &*arg.pat { syn::Pat::Ident(name) => &name.ident, 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: body.push(quote! { impl #struct_name { @@ -270,8 +270,8 @@ pub fn handle_function( }); } else { // Non async fn must return an ApiFuture already! - return_type = syn::Type::Verbatim(syn::TypeVerbatim { - tts: definition + return_type = syn::Type::Verbatim( + definition .remove("returns") .ok_or_else(|| { format_err!( @@ -281,7 +281,7 @@ pub fn handle_function( })? .expect_type()? .into_token_stream(), - }); + ); body.push(quote! { impl #struct_name { diff --git a/proxmox-api-macro/src/api_macro/struct_types/newtype.rs b/proxmox-api-macro/src/api_macro/struct_types/newtype.rs index 3b174447..bd84df21 100644 --- a/proxmox-api-macro/src/api_macro/struct_types/newtype.rs +++ b/proxmox-api-macro/src/api_macro/struct_types/newtype.rs @@ -24,8 +24,7 @@ pub fn handle_newtype( let type_str = syn::LitStr::new(&type_s, type_span); let fields = &item.unnamed; - let field_punct = fields.first().unwrap(); - let field = field_punct.value(); + let field = fields.first().unwrap(); let common = CommonTypeDefinition::from_object(&mut definition)?; @@ -141,7 +140,7 @@ fn newtype_filter_derive_attrs( 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 { for ty in mem::replace(&mut exprtuple.elems, syn::punctuated::Punctuated::new()) { if let syn::Expr::Path(ref exprpath) = ty { @@ -166,7 +165,7 @@ fn newtype_filter_derive_attrs( exprtuple.elems.push(ty); } } - attr.tts = quote! { #content }; + attr.tokens = quote! { #content }; attrs.push(attr); } diff --git a/proxmox-api-macro/src/parsing.rs b/proxmox-api-macro/src/parsing.rs index 04738a58..41ac9ebc 100644 --- a/proxmox-api-macro/src/parsing.rs +++ b/proxmox-api-macro/src/parsing.rs @@ -298,7 +298,7 @@ impl Expression { pub fn is_ident(&self, ident: &str) -> bool { match self { 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,