summaryrefslogtreecommitdiffstats
path: root/ffi-macros
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-08-22 15:49:35 +0200
committerJustus Winter <justus@sequoia-pgp.org>2019-08-22 15:49:35 +0200
commit51da1f3911ea79ae7dc83e0f30789f35ac5ef4c4 (patch)
tree9a5ed36524ee87db33c9ab3d30f11e88a1da2b43 /ffi-macros
parentee21a762b5595cbdea6de05c7c651e2c3e87025b (diff)
Bump syn, quote, and proc-macro2 to 1.0.
Diffstat (limited to 'ffi-macros')
-rw-r--r--ffi-macros/Cargo.toml6
-rw-r--r--ffi-macros/src/lib.rs58
-rw-r--r--ffi-macros/src/rust2c.rs15
3 files changed, 43 insertions, 36 deletions
diff --git a/ffi-macros/Cargo.toml b/ffi-macros/Cargo.toml
index 6c1329d5..d659d849 100644
--- a/ffi-macros/Cargo.toml
+++ b/ffi-macros/Cargo.toml
@@ -21,12 +21,12 @@ maintenance = { status = "actively-developed" }
[dependencies]
lazy_static = "1.0.0"
-proc-macro2 = "0.4"
-quote = "0.6"
+proc-macro2 = "1.0"
+quote = "1.0"
sha2 = "0.8"
[dependencies.syn]
-version = "0.15"
+version = "1.0"
features = ["full"]
[lib]
diff --git a/ffi-macros/src/lib.rs b/ffi-macros/src/lib.rs
index 858a3539..4d9590dc 100644
--- a/ffi-macros/src/lib.rs
+++ b/ffi-macros/src/lib.rs
@@ -50,19 +50,19 @@ pub fn cdecl(_attr: TokenStream, item: TokenStream) -> TokenStream {
acc
});
let vis = &fun.vis;
- let constness = &fun.constness;
- let unsafety = &fun.unsafety;
- let asyncness = &fun.asyncness;
- let abi = &fun.abi;
- let ident = &fun.ident;
+ let constness = &fun.sig.constness;
+ let unsafety = &fun.sig.unsafety;
+ let asyncness = &fun.sig.asyncness;
+ let abi = &fun.sig.abi;
+ let ident = &fun.sig.ident;
- let decl = &fun.decl;
- let fn_token = &decl.fn_token;
- let fn_generics = &decl.generics;
- let fn_out = &decl.output;
+ let fn_token = &fun.sig.fn_token;
+ let fn_generics = &fun.sig.generics;
+ let fn_out = &fun.sig.output;
let mut fn_params = TokenStream2::new();
- decl.paren_token.surround(&mut fn_params, |ts| decl.inputs.to_tokens(ts));
+ fun.sig.paren_token.surround(&mut fn_params,
+ |ts| fun.sig.inputs.to_tokens(ts));
let block = &fun.block;
@@ -131,19 +131,19 @@ pub fn ffi_catch_abort(_attr: TokenStream, item: TokenStream) -> TokenStream {
acc
});
let vis = &fun.vis;
- let constness = &fun.constness;
- let unsafety = &fun.unsafety;
- let asyncness = &fun.asyncness;
- let abi = &fun.abi;
- let ident = &fun.ident;
+ let constness = &fun.sig.constness;
+ let unsafety = &fun.sig.unsafety;
+ let asyncness = &fun.sig.asyncness;
+ let abi = &fun.sig.abi;
+ let ident = &fun.sig.ident;
- let decl = &fun.decl;
- let fn_token = &decl.fn_token;
- let fn_generics = &decl.generics;
- let fn_out = &decl.output;
+ let fn_token = &fun.sig.fn_token;
+ let fn_generics = &fun.sig.generics;
+ let fn_out = &fun.sig.output;
let mut fn_params = TokenStream2::new();
- decl.paren_token.surround(&mut fn_params, |ts| decl.inputs.to_tokens(ts));
+ fun.sig.paren_token.surround(&mut fn_params,
+ |ts| fun.sig.inputs.to_tokens(ts));
let block = &fun.block;
@@ -202,7 +202,15 @@ pub fn ffi_wrapper_type(args: TokenStream, input: TokenStream) -> TokenStream {
syn::Lit::Str(ref s) => s.value(),
_ => unreachable!(),
};
- match mnv.ident.to_string().as_ref() {
+ let mnv_ident = if let Some(i) = mnv.path.get_ident() {
+ i
+ } else {
+ return syn::Error::new(
+ mnv.path.span(),
+ "unexpected path, must be an ident")
+ .to_compile_error().into();
+ };
+ match mnv_ident.to_string().as_ref() {
"name" => name = Some(value),
"prefix" => prefix = Some(value),
"derive" => {
@@ -212,7 +220,7 @@ pub fn ffi_wrapper_type(args: TokenStream, input: TokenStream) -> TokenStream {
if let Some(i) = ident.find('(') {
if ! ident.ends_with(")") {
return syn::Error::new(
- mnv.ident.span(),
+ mnv.path.span(),
format!("missing closing \
parenthesis: \
{}", ident))
@@ -229,14 +237,14 @@ pub fn ffi_wrapper_type(args: TokenStream, input: TokenStream) -> TokenStream {
derive.push((*f, arg));
} else {
return syn::Error::new(
- mnv.ident.span(),
+ mnv.path.span(),
format!("unknown derive: {}", ident))
.to_compile_error().into();
}
}
},
name => return
- syn::Error::new(mnv.ident.span(),
+ syn::Error::new(mnv.path.span(),
format!("unexpected parameter: {}",
name))
.to_compile_error().into(),
@@ -262,7 +270,7 @@ pub fn ffi_wrapper_type(args: TokenStream, input: TokenStream) -> TokenStream {
"expected a single field")
.to_compile_error().into();
}
- fields.unnamed.first().unwrap().value().ty.clone()
+ fields.unnamed.first().unwrap().ty.clone()
},
_ => return
syn::Error::new(argument_span,
diff --git a/ffi-macros/src/rust2c.rs b/ffi-macros/src/rust2c.rs
index f801fd0b..cec39be2 100644
--- a/ffi-macros/src/rust2c.rs
+++ b/ffi-macros/src/rust2c.rs
@@ -135,18 +135,17 @@ fn type2c<T: ToTokens>(typ: T) -> String {
}
pub fn rust2c(fun: &syn::ItemFn) -> String {
- let decl = &fun.decl;
- let return_type = match &decl.output {
+ let return_type = match &fun.sig.output {
syn::ReturnType::Default => "void".into(),
syn::ReturnType::Type(_, ref typ) => type2c(typ).trim_end().to_string(),
};
- let fun_ident = format!("{}", fun.ident);
+ let fun_ident = format!("{}", fun.sig.ident);
let mut s = String::new();
s += &format!("{}\n{} (", return_type, fun_ident);
let indent = fun_ident.len() + 2;
- for (i, arg) in decl.inputs.iter().enumerate() {
+ for (i, arg) in fun.sig.inputs.iter().enumerate() {
// All but the first line need to be indented.
if i > 0 {
for _ in 0..indent {
@@ -155,9 +154,9 @@ pub fn rust2c(fun: &syn::ItemFn) -> String {
}
match arg {
- &syn::FnArg::Captured(ref cap) => {
- let pat_ident = match &cap.pat {
- &syn::Pat::Ident(ref i) => i,
+ &syn::FnArg::Typed(ref cap) => {
+ let pat_ident = match *cap.pat {
+ syn::Pat::Ident(ref i) => i,
_ => unimplemented!(),
};
s += &format!("{}{}", type2c(&cap.ty), pat_ident.ident);
@@ -166,7 +165,7 @@ pub fn rust2c(fun: &syn::ItemFn) -> String {
}
// All but the last one need a comma.
- if i < decl.inputs.len() - 1 {
+ if i < fun.sig.inputs.len() - 1 {
s += ",\n";
}
}