From 34db7f015093fb9f83009b45a404cc5cb17f5e72 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 7 Sep 2019 14:43:29 -0700 Subject: [PATCH] Update to syn 1 and quote 1. --- wasi-common-cbindgen/Cargo.toml | 4 ++-- wasi-common-cbindgen/src/lib.rs | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/wasi-common-cbindgen/Cargo.toml b/wasi-common-cbindgen/Cargo.toml index 9891039d21..390abb5f04 100644 --- a/wasi-common-cbindgen/Cargo.toml +++ b/wasi-common-cbindgen/Cargo.toml @@ -10,8 +10,8 @@ description = "Interface generator utilities used by wasi-common" proc-macro = true [dependencies] -syn = { version = "0.15.34", features = ["full"] } -quote = "0.6.12" +syn = { version = "1.0.5", features = ["full"] } +quote = "1.0.2" [dev-dependencies] trybuild = "1.0.4" diff --git a/wasi-common-cbindgen/src/lib.rs b/wasi-common-cbindgen/src/lib.rs index 31bd115b23..e6146bcdaa 100644 --- a/wasi-common-cbindgen/src/lib.rs +++ b/wasi-common-cbindgen/src/lib.rs @@ -2,7 +2,7 @@ extern crate proc_macro; use proc_macro::TokenStream; use quote::quote; -use syn::{ArgCaptured, FnArg, Pat, PatIdent, Type, TypeReference, TypeSlice}; +use syn::{FnArg, Pat, PatType, Type, TypeReference, TypeSlice}; #[proc_macro_attribute] pub fn wasi_common_cbindgen(attr: TokenStream, function: TokenStream) -> TokenStream { @@ -14,7 +14,7 @@ pub fn wasi_common_cbindgen(attr: TokenStream, function: TokenStream) -> TokenSt let vis = &function.vis; // generate C fn name prefixed with __wasi_ - let fn_ident = &function.ident; + let fn_ident = &function.sig.ident; let concatenated = format!("wasi_common_{}", fn_ident); let c_fn_ident = syn::Ident::new(&concatenated, fn_ident.span()); @@ -22,18 +22,26 @@ pub fn wasi_common_cbindgen(attr: TokenStream, function: TokenStream) -> TokenSt let mut arg_ident = Vec::new(); let mut arg_type = Vec::new(); let mut call_arg_ident = Vec::new(); - for input in &function.decl.inputs { + for input in &function.sig.inputs { match input { - FnArg::Captured(ArgCaptured { - pat: Pat::Ident(pat @ PatIdent { .. }), + FnArg::Typed(PatType { + attrs, + pat, colon_token: _, ty, }) => { // parse arg identifier - let ident = &pat.ident; + let ident = if let Pat::Ident(ident) = &**pat { + &ident.ident + } else { + panic!("expected function input to be an identifier") + }; + if !attrs.is_empty() { + panic!("unsupported attributes on function arg"); + } arg_ident.push(quote!(#ident)); // parse arg type - if let Type::Reference(ty @ TypeReference { .. }) = &ty { + if let Type::Reference(ty @ TypeReference { .. }) = &**ty { // if we're here, then we found a &-ref // so substitute it for *mut since we're exporting to C let elem = &*ty.elem; @@ -67,12 +75,14 @@ pub fn wasi_common_cbindgen(attr: TokenStream, function: TokenStream) -> TokenSt call_arg_ident.push(quote!(#ident)); } } - _ => {} + _ => { + unimplemented!("unrecognized function input pattern"); + } } } // capture output arg - let output = &function.decl.output; + let output = &function.sig.output; let result = quote! { #function