From d596f5034df1263d905d7f2793468a65407c81e7 Mon Sep 17 00:00:00 2001 From: vms Date: Tue, 30 Jun 2020 23:42:26 +0300 Subject: [PATCH] move to new crates versions --- crates/macro/Cargo.toml | 6 +-- crates/macro/src/lib.rs | 63 +++++++------------------- crates/macro/src/macro_input_parser.rs | 9 ++-- 3 files changed, 23 insertions(+), 55 deletions(-) diff --git a/crates/macro/Cargo.toml b/crates/macro/Cargo.toml index a162fc7..88bd9df 100644 --- a/crates/macro/Cargo.toml +++ b/crates/macro/Cargo.toml @@ -18,7 +18,7 @@ all-features = true proc-macro = true [dependencies] -syn = { version = '0.15.44', features = ['full'] } -quote = "0.6.13" -proc-macro2 = "0.4" +syn = { version = '1.0.33', features = ['full'] } +quote = "1.0.7" +proc-macro2 = "1.0.18" fluence-sdk-main = { path = "../main", version = "=0.1.11" } diff --git a/crates/macro/src/lib.rs b/crates/macro/src/lib.rs index f0e5216..81ebdcb 100644 --- a/crates/macro/src/lib.rs +++ b/crates/macro/src/lib.rs @@ -96,75 +96,46 @@ use crate::macro_input_parser::{InputTypeGenerator, ParsedType, ReturnTypeGenera use proc_macro::TokenStream; use quote::quote; use syn::spanned::Spanned; -use syn::{parse::Error, parse_macro_input, ItemFn}; +use syn::{parse::Error, parse_macro_input, ItemFn, Visibility}; fn invoke_handler_impl( attr: proc_macro2::TokenStream, - fn_item: syn::ItemFn, + fn_item: ItemFn, ) -> syn::Result { let ItemFn { - constness, - unsafety, - abi, - ident, - decl, + vis, + sig, .. } = &fn_item; - if let Err(e) = (|| { - if let Some(constness) = constness { - return Err(Error::new( - constness.span, - "The invocation handler shouldn't be constant", - )); - } - if let Some(unsafety) = unsafety { - return Err(Error::new( - unsafety.span, - "The invocation handler shouldn't be unsage", - )); - } - if let Some(abi) = abi { - return Err(Error::new( - abi.extern_token.span, - "The invocation handler shouldn't have any custom linkage", - )); - } - if !decl.generics.params.is_empty() || decl.generics.where_clause.is_some() { - return Err(Error::new( - decl.fn_token.span, - "The invocation handler shouldn't use template parameters", - )); - } - if let Some(variadic) = decl.variadic { - return Err(Error::new( - variadic.spans[0], - "The invocation handler shouldn't use variadic interface", - )); - } - Ok(()) - })() { - return Err(e); + match vis { + Visibility::Public(_) => {}, + _ => return Err(Error::new( + vis.span(), + "The #[faas_export] could be applied only to public functions", + )) } - let input_type = match decl.inputs.len() { + let input_type = match sig.inputs.len() { 0 => ParsedType::Empty, - 1 => ParsedType::from_fn_arg(decl.inputs.first().unwrap().into_value())?, + 1 => ParsedType::from_fn_arg(sig.inputs.first().unwrap())?, _ => { return Err(Error::new( - decl.inputs.span(), + sig.inputs.span(), "The invocation handler shouldn't have more than one argument", )) }, }; - let output_type = ParsedType::from_return_type(&decl.output)?; + + let output_type = ParsedType::from_return_type(&sig.output)?; if output_type == ParsedType::Empty { return Err(Error::new( - decl.output.span(), + sig.output.span(), "The invocation handler should have the return value", )); } + let ident = &sig.ident; let prolog = input_type.generate_fn_prolog(); let prolog = match input_type { ParsedType::Empty => quote! { diff --git a/crates/macro/src/macro_input_parser.rs b/crates/macro/src/macro_input_parser.rs index acb6b83..36c30f8 100644 --- a/crates/macro/src/macro_input_parser.rs +++ b/crates/macro/src/macro_input_parser.rs @@ -43,13 +43,12 @@ impl ParsedType { "Unsuitable type in Vec brackets - only Vec is supported", ) })?; - let arg_val = arg.value(); // converts T to syn::Type - let arg_type = match arg_val { + let arg_type = match arg { syn::GenericArgument::Type(ty) => Ok(ty), _ => Err(Error::new( - arg_val.span(), + arg.span(), "Unsuitable type in Vec brackets - only Vec is supported", )), }?; @@ -79,7 +78,6 @@ impl ParsedType { "Unsuitable type in Vec brackets - only Vec is supported", ) })?; - let arg_segment = arg_segment.value(); Ok(arg_segment.ident.to_string()) } @@ -103,7 +101,6 @@ impl ParsedType { "The invocation handler should have a non-empty input argument type", ) })?; - let type_segment = type_segment.value(); match type_segment.ident.to_string().as_str() { "String" => Ok(ParsedType::Utf8String), @@ -126,7 +123,7 @@ impl ParsedType { pub fn from_fn_arg(fn_arg: &syn::FnArg) -> syn::Result { match fn_arg { - syn::FnArg::Captured(arg) => ParsedType::from_type(&arg.ty), + syn::FnArg::Typed(arg) => ParsedType::from_type(&arg.ty), _ => Err(Error::new(fn_arg.span(), "Unknown argument")), } }