diff --git a/Cargo.lock b/Cargo.lock index fbda247f8..f48e792f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,15 +30,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cbindgen" -version = "0.9.0" +version = "0.9.1" dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.93 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.38 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -100,18 +100,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "proc-macro2" -version = "0.4.30" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "quote" -version = "0.6.12" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -249,17 +249,17 @@ name = "serde" version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde_derive 1.0.93 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" -version = "1.0.93" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.38 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -279,12 +279,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "0.15.38" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -334,7 +334,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "unicode-xid" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -374,8 +374,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" -"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" +"checksum proc-macro2 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "19f287c234c9b2d0308d692dee5c449c1a171167a6f8150f7cf2a49d8fd96967" +"checksum quote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7ab938ebe6f1c82426b5fb82eaf10c3e3028c53deaa3fbe38f5904b37cf4d767" "checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" "checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" @@ -392,16 +392,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" "checksum ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f" "checksum serde 1.0.93 (registry+https://github.com/rust-lang/crates.io-index)" = "960e29cf7004b3b6e65fc5002981400eb3ccc017a08a2406940823e58e7179a9" -"checksum serde_derive 1.0.93 (registry+https://github.com/rust-lang/crates.io-index)" = "c4cce6663696bd38272e90bf34a0267e1226156c33f52d3f3915a2dd5d802085" +"checksum serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "cb4dc18c61206b08dc98216c98faa0232f4337e1e1b8574551d5bad29ea1b425" "checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -"checksum syn 0.15.38 (registry+https://github.com/rust-lang/crates.io-index)" = "37ea458a750f59ab679b47fef9b6722c586c5742f4cfe18a120bbc807e5e01fd" +"checksum syn 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "863ecbce06044c8380458360b4146d7372edadfedd77f120ba8c193da427b708" "checksum tempfile 3.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7dc4738f2e68ed2855de5ac9cdbe05c9216773ecde4739b2f095002ab03a13ef" "checksum termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a8fb22f7cde82c8220e5aeacb3258ed7ce996142c77cba193f203515e26c330" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" "checksum toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b8c96d7873fa7ef8bdeb3a9cda3ac48389b4154f32b9803b4bc26220b677b039" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" -"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" +"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" diff --git a/Cargo.toml b/Cargo.toml index 7995d2ced..2c94dc35d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cbindgen" -version = "0.9.0" +version = "0.9.1" authors = ["Jeff Muizelaar ", "Kartikaya Gupta ", "Ryan Hunt "] @@ -20,11 +20,11 @@ serde = { version = "1.0", default-features = false, features = ["derive"]} serde_json = "1.0" tempfile = "3.0" toml = "0.5" -proc-macro2 = "0.4" -quote = "0.6" +proc-macro2 = "1" +quote = "1" [dependencies.syn] -version = "0.15.0" +version = "1" default-features = false features = ["clone-impls", "extra-traits", "full", "parsing", "printing"] diff --git a/src/bindgen/ir/cfg.rs b/src/bindgen/ir/cfg.rs index 07cb7417d..4ecfd1234 100644 --- a/src/bindgen/ir/cfg.rs +++ b/src/bindgen/ir/cfg.rs @@ -107,14 +107,12 @@ impl Cfg { let mut configs = Vec::new(); for attr in attrs { - if let Some(syn::Meta::List(syn::MetaList { ident, nested, .. })) = - attr.interpret_meta() - { - if ident != "cfg" || nested.len() != 1 { + if let Ok(syn::Meta::List(syn::MetaList { path, nested, .. })) = attr.parse_meta() { + if !path.is_ident("cfg") || nested.len() != 1 { continue; } - if let Some(config) = Cfg::load_single(nested.first().unwrap().value()) { + if let Some(config) = Cfg::load_single(nested.first().unwrap()) { configs.push(config); } } @@ -136,11 +134,11 @@ impl Cfg { .expect("error parsing dependency's target metadata") }) .and_then(|target| { - if let syn::Meta::List(syn::MetaList { ident, nested, .. }) = target { - if ident != "cfg" || nested.len() != 1 { + if let syn::Meta::List(syn::MetaList { path, nested, .. }) = target { + if !path.is_ident("cfg") || nested.len() != 1 { return None; } - Cfg::load_single(nested.first().unwrap().value()) + Cfg::load_single(nested.first().unwrap()) } else { None } @@ -149,35 +147,39 @@ impl Cfg { fn load_single(item: &syn::NestedMeta) -> Option { match *item { - syn::NestedMeta::Meta(syn::Meta::Word(ref ident)) => { - Some(Cfg::Boolean(format!("{}", ident))) - } + syn::NestedMeta::Meta(syn::Meta::Path(ref path)) => Some(Cfg::Boolean(format!( + "{}", + path.segments.first().unwrap().ident + ))), syn::NestedMeta::Meta(syn::Meta::NameValue(syn::MetaNameValue { - ref ident, + ref path, ref lit, .. - })) => match *lit { - syn::Lit::Str(ref value) => Some(Cfg::Named(format!("{}", ident), value.value())), + })) => match lit { + &syn::Lit::Str(ref value) => Some(Cfg::Named( + format!("{}", path.segments.first().unwrap().ident), + value.value(), + )), _ => None, }, syn::NestedMeta::Meta(syn::Meta::List(syn::MetaList { - ref ident, + ref path, ref nested, .. })) => { - if ident == "any" { + if path.is_ident("any") { if let Some(configs) = Cfg::load_list(nested.iter()) { Some(Cfg::Any(configs)) } else { None } - } else if ident == "all" { + } else if path.is_ident("all") { if let Some(configs) = Cfg::load_list(nested.iter()) { Some(Cfg::All(configs)) } else { None } - } else if ident == "not" { + } else if path.is_ident("not") { if nested.len() != 1 { return None; } diff --git a/src/bindgen/ir/constant.rs b/src/bindgen/ir/constant.rs index d42f0634e..cf28155e9 100644 --- a/src/bindgen/ir/constant.rs +++ b/src/bindgen/ir/constant.rs @@ -5,7 +5,6 @@ use std::borrow::Cow; use std::fmt; use std::io::Write; -use std::mem; use syn; @@ -159,30 +158,11 @@ impl Literal { syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Int(ref value), .. - }) => match value.suffix() { - syn::IntSuffix::Usize - | syn::IntSuffix::U8 - | syn::IntSuffix::U16 - | syn::IntSuffix::U32 - | syn::IntSuffix::U64 - | syn::IntSuffix::U128 - | syn::IntSuffix::None => Ok(Literal::Expr(format!("{}", value.value()))), - syn::IntSuffix::Isize - | syn::IntSuffix::I8 - | syn::IntSuffix::I16 - | syn::IntSuffix::I32 - | syn::IntSuffix::I64 - | syn::IntSuffix::I128 => unsafe { - Ok(Literal::Expr(format!( - "{}", - mem::transmute::(value.value()) - ))) - }, - }, + }) => Ok(Literal::Expr(value.base10_digits().to_string())), syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Float(ref value), .. - }) => Ok(Literal::Expr(format!("{}", value.value()))), + }) => Ok(Literal::Expr(value.base10_digits().to_string())), syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Bool(ref value), .. diff --git a/src/bindgen/ir/enumeration.rs b/src/bindgen/ir/enumeration.rs index 8b5be1d41..38cde7f51 100644 --- a/src/bindgen/ir/enumeration.rs +++ b/src/bindgen/ir/enumeration.rs @@ -32,9 +32,7 @@ pub struct EnumVariant { fn value_from_expr(val: &syn::Expr) -> Option { match *val { syn::Expr::Lit(ref lit) => match lit.lit { - syn::Lit::Int(ref lit) if lit.value() <= ::std::i64::MAX as u64 => { - Some(lit.value() as i64) - } + syn::Lit::Int(ref lit) => lit.base10_parse::().ok(), _ => None, }, syn::Expr::Unary(ref unary) => { diff --git a/src/bindgen/ir/function.rs b/src/bindgen/ir/function.rs index bb9c60986..e557827e6 100644 --- a/src/bindgen/ir/function.rs +++ b/src/bindgen/ir/function.rs @@ -34,13 +34,13 @@ pub struct Function { impl Function { pub fn load( path: Path, - decl: &syn::FnDecl, + sig: &syn::Signature, extern_decl: bool, attrs: &[syn::Attribute], mod_cfg: Option<&Cfg>, ) -> Result { - let args = decl.inputs.iter().try_skip_map(|x| x.as_ident_and_type())?; - let ret = match decl.output { + let args = sig.inputs.iter().try_skip_map(|x| x.as_ident_and_type())?; + let ret = match sig.output { syn::ReturnType::Default => Type::Primitive(PrimitiveType::Void), syn::ReturnType::Type(_, ref ty) => { if let Some(x) = Type::load(ty)? { @@ -226,18 +226,19 @@ pub trait SynFnArgHelpers { impl SynFnArgHelpers for syn::FnArg { fn as_ident_and_type(&self) -> Result, String> { - match *self { - syn::FnArg::Captured(syn::ArgCaptured { - pat: syn::Pat::Ident(syn::PatIdent { ref ident, .. }), - ref ty, - .. - }) => { - if let Some(x) = Type::load(ty)? { - Ok(Some((ident.to_string(), x))) - } else { - Ok(None) + match self { + &syn::FnArg::Typed(syn::PatType { + ref pat, ref ty, .. + }) => match **pat { + syn::Pat::Ident(syn::PatIdent { ref ident, .. }) => { + if let Some(x) = Type::load(ty)? { + Ok(Some((ident.to_string(), x))) + } else { + Ok(None) + } } - } + _ => Err("Parameter has an unsupported type.".to_owned()), + }, _ => Err("Parameter has an unsupported type.".to_owned()), } } diff --git a/src/bindgen/ir/generic_path.rs b/src/bindgen/ir/generic_path.rs index a2109b6d3..f42e6fd9c 100644 --- a/src/bindgen/ir/generic_path.rs +++ b/src/bindgen/ir/generic_path.rs @@ -120,8 +120,7 @@ impl GenericPath { "{:?} doesn't have any segments", path ); - let last_segment_token = path.segments.last().unwrap(); - let last_segment = last_segment_token.value(); + let last_segment = path.segments.last().unwrap(); let name = last_segment.ident.to_string(); let path = Path::new(name); diff --git a/src/bindgen/ir/repr.rs b/src/bindgen/ir/repr.rs index 97c3a015f..1ed3f03b4 100644 --- a/src/bindgen/ir/repr.rs +++ b/src/bindgen/ir/repr.rs @@ -55,10 +55,10 @@ impl Repr { let ids = attrs .iter() .filter_map(|attr| { - if let syn::Meta::List(syn::MetaList { ident, nested, .. }) = - attr.interpret_meta()? + if let syn::Meta::List(syn::MetaList { path, nested, .. }) = + attr.parse_meta().ok()? { - if ident == "repr" { + if path.is_ident("repr") { return Some(nested.into_iter().collect::>()); } } @@ -66,7 +66,9 @@ impl Repr { }) .flat_map(|nested| nested) .filter_map(|meta| match meta { - syn::NestedMeta::Meta(syn::Meta::Word(ident)) => Some(ident.to_string()), + syn::NestedMeta::Meta(syn::Meta::Path(path)) => { + Some(path.segments.first().unwrap().ident.to_string()) + } _ => None, }); diff --git a/src/bindgen/ir/ty.rs b/src/bindgen/ir/ty.rs index e5660ec1e..f6eb48e79 100644 --- a/src/bindgen/ir/ty.rs +++ b/src/bindgen/ir/ty.rs @@ -295,7 +295,7 @@ impl Type { None => return Err("Cannot have an array of zero sized types.".to_owned()), }; - let len = ArrayLength::Value(format!("{}", len.value())); + let len = ArrayLength::Value(len.base10_digits().to_string()); // panic!("panic -> value: {:?}", len); Type::Array(Box::new(converted), len) } @@ -305,15 +305,16 @@ impl Type { Type::load(&x.ty).map(|opt_ty| { opt_ty.map(|ty| { ( - x.name.as_ref().map(|name| match name.0 { - syn::BareFnArgName::Named(ref ident) => ident.to_string(), - syn::BareFnArgName::Wild(_) => { + x.name.as_ref().map(|(ref ident, _)| { + if ident == "_" { wildcard_counter += 1; if wildcard_counter == 1 { "_".to_owned() } else { format!("_{}", wildcard_counter - 1) } + } else { + ident.to_string() } }), ty, diff --git a/src/bindgen/parser.rs b/src/bindgen/parser.rs index 660a399fa..fd5bf45c5 100644 --- a/src/bindgen/parser.rs +++ b/src/bindgen/parser.rs @@ -321,20 +321,18 @@ impl<'a> Parser<'a> { // Last chance to find a module path let mut path_attr_found = false; for attr in &item.attrs { - if let Some(syn::Meta::NameValue(syn::MetaNameValue { - ident, - lit, - .. - })) = attr.interpret_meta() - { - match lit { - syn::Lit::Str(ref path) if ident == "path" => { + match attr.parse_meta() { + Ok(syn::Meta::NameValue(syn::MetaNameValue { + path, lit, .. + })) => match lit { + syn::Lit::Str(ref path_lit) if path.is_ident("path") => { path_attr_found = true; - self.parse_mod(pkg, &mod_dir.join(path.value()))?; + self.parse_mod(pkg, &mod_dir.join(path_lit.value()))?; break; } _ => (), - } + }, + _ => (), } } @@ -541,21 +539,21 @@ impl Parse { if !parse_config.should_generate_top_level_item(crate_name, binding_crate_name) { info!( "Skip {}::{} - (fn's outside of the binding crate are not used).", - crate_name, &function.ident + crate_name, &function.sig.ident ); return; } - let path = Path::new(function.ident.to_string()); - match Function::load(path, &function.decl, true, &function.attrs, mod_cfg) { + let path = Path::new(function.sig.ident.to_string()); + match Function::load(path, &function.sig, true, &function.attrs, mod_cfg) { Ok(func) => { - info!("Take {}::{}.", crate_name, &function.ident); + info!("Take {}::{}.", crate_name, &function.sig.ident); self.functions.push(func); } Err(msg) => { error!( "Cannot use fn {}::{} ({}).", - crate_name, &function.ident, msg + crate_name, &function.sig.ident, msg ); } } @@ -575,22 +573,25 @@ impl Parse { if !parse_config.should_generate_top_level_item(crate_name, binding_crate_name) { info!( "Skip {}::{} - (fn's outside of the binding crate are not used).", - crate_name, &item.ident + crate_name, &item.sig.ident ); return; } if let syn::Visibility::Public(_) = item.vis { - if item.is_no_mangle() && (item.abi.is_omitted() || item.abi.is_c()) { - let path = Path::new(item.ident.to_string()); - match Function::load(path, &item.decl, false, &item.attrs, mod_cfg) { + if item.is_no_mangle() && (item.sig.abi.is_omitted() || item.sig.abi.is_c()) { + let path = Path::new(item.sig.ident.to_string()); + match Function::load(path, &item.sig, false, &item.attrs, mod_cfg) { Ok(func) => { - info!("Take {}::{}.", crate_name, &item.ident); + info!("Take {}::{}.", crate_name, &item.sig.ident); self.functions.push(func); } Err(msg) => { - error!("Cannot use fn {}::{} ({}).", crate_name, &item.ident, msg); + error!( + "Cannot use fn {}::{} ({}).", + crate_name, &item.sig.ident, msg + ); } } return; @@ -600,18 +601,18 @@ impl Parse { // TODO if let syn::Visibility::Public(_) = item.vis { } else { - warn!("Skip {}::{} - (not `pub`).", crate_name, &item.ident); + warn!("Skip {}::{} - (not `pub`).", crate_name, &item.sig.ident); } - if (item.abi.is_omitted() || item.abi.is_c()) && !item.is_no_mangle() { + if (item.sig.abi.is_omitted() || item.sig.abi.is_c()) && !item.is_no_mangle() { warn!( "Skip {}::{} - (`extern` but not `no_mangle`).", - crate_name, &item.ident + crate_name, &item.sig.ident ); } - if item.abi.is_some() && !(item.abi.is_omitted() || item.abi.is_c()) { + if item.sig.abi.is_some() && !(item.sig.abi.is_omitted() || item.sig.abi.is_c()) { warn!( "Skip {}::{} - (non `extern \"C\"`).", - crate_name, &item.ident + crate_name, &item.sig.ident ); } } @@ -845,7 +846,7 @@ impl Parse { item: &syn::ItemMacro, ) { let name = match item.mac.path.segments.last() { - Some(ref n) => n.value().ident.to_string(), + Some(ref n) => n.ident.to_string(), None => return, }; @@ -853,7 +854,7 @@ impl Parse { return; } - let bitflags = match bitflags::parse(item.mac.tts.clone()) { + let bitflags = match bitflags::parse(item.mac.tokens.clone()) { Ok(b) => b, Err(e) => { warn!("Failed to parse bitflags invocation: {:?}", e); diff --git a/src/bindgen/utilities.rs b/src/bindgen/utilities.rs index 53e59f0f3..3dc15e9cc 100644 --- a/src/bindgen/utilities.rs +++ b/src/bindgen/utilities.rs @@ -83,9 +83,9 @@ macro_rules! syn_item_match_helper { syn::Item::Type(ref item) => (|$i: &syn::ItemType| $a)(item), syn::Item::Union(ref item) => (|$i: &syn::ItemUnion| $a)(item), syn::Item::Use(ref item) => (|$i: &syn::ItemUse| $a)(item), - syn::Item::Existential(ref item) => (|$i: &syn::ItemExistential| $a)(item), syn::Item::TraitAlias(ref item) => (|$i: &syn::ItemTraitAlias| $a)(item), syn::Item::Verbatim(_) => (|| $b)(), + _ => panic!("Unhandled syn::Item: {:?}", $s), } }; } @@ -146,23 +146,8 @@ impl_syn_item_helper!(syn::ItemTrait); impl_syn_item_helper!(syn::ItemImpl); impl_syn_item_helper!(syn::ItemMacro); impl_syn_item_helper!(syn::ItemMacro2); -impl_syn_item_helper!(syn::ItemExistential); impl_syn_item_helper!(syn::ItemTraitAlias); -impl SynItemHelpers for syn::ItemVerbatim { - fn has_attr_word(&self, _name: &str) -> bool { - false - } - - fn has_attr_list(&self, _name: &str, _args: &[&str]) -> bool { - false - } - - fn has_attr_name_value(&self, _name: &str, _value: &str) -> bool { - false - } -} - /// Helper function for accessing Abi information pub trait SynAbiHelpers { fn is_c(&self) -> bool; @@ -209,9 +194,9 @@ pub trait SynAttributeHelpers { impl SynAttributeHelpers for [syn::Attribute] { fn has_attr_word(&self, name: &str) -> bool { - self.iter().filter_map(|x| x.interpret_meta()).any(|attr| { - if let syn::Meta::Word(ref ident) = attr { - ident == name + self.iter().filter_map(|x| x.parse_meta().ok()).any(|attr| { + if let syn::Meta::Path(ref path) = attr { + path.is_ident(name) } else { false } @@ -219,15 +204,15 @@ impl SynAttributeHelpers for [syn::Attribute] { } fn has_attr_list(&self, name: &str, args: &[&str]) -> bool { - self.iter().filter_map(|x| x.interpret_meta()).any(|attr| { - if let syn::Meta::List(syn::MetaList { ident, nested, .. }) = attr { - if ident != name { + self.iter().filter_map(|x| x.parse_meta().ok()).any(|attr| { + if let syn::Meta::List(syn::MetaList { path, nested, .. }) = attr { + if !path.is_ident(name) { return false; } args.iter().all(|arg| { nested.iter().any(|nested_meta| { - if let syn::NestedMeta::Meta(syn::Meta::Word(ident)) = nested_meta { - ident == arg + if let syn::NestedMeta::Meta(syn::Meta::Path(path)) = nested_meta { + path.is_ident(arg) } else { false } @@ -240,10 +225,10 @@ impl SynAttributeHelpers for [syn::Attribute] { } fn has_attr_name_value(&self, name: &str, value: &str) -> bool { - self.iter().filter_map(|x| x.interpret_meta()).any(|attr| { - if let syn::Meta::NameValue(syn::MetaNameValue { ident, lit, .. }) = attr { + self.iter().filter_map(|x| x.parse_meta().ok()).any(|attr| { + if let syn::Meta::NameValue(syn::MetaNameValue { path, lit, .. }) = attr { if let syn::Lit::Str(lit) = lit { - (ident == name) && (&lit.value() == value) + path.is_ident(name) && (&lit.value() == value) } else { false } @@ -258,14 +243,13 @@ impl SynAttributeHelpers for [syn::Attribute] { for attr in self { if attr.style == syn::AttrStyle::Outer { - if let Some(syn::Meta::NameValue(syn::MetaNameValue { - ident, + if let Ok(syn::Meta::NameValue(syn::MetaNameValue { + path, lit: syn::Lit::Str(content), .. - })) = attr.interpret_meta() + })) = attr.parse_meta() { - let name = ident.to_string(); - if &*name == "doc" { + if path.is_ident("doc") { let text = content.value().trim_end().to_owned(); comment.push(text); }