diff --git a/Cargo.lock b/Cargo.lock index 3097436d7c..71e001173c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,7 +34,8 @@ dependencies = [ "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "which 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -205,10 +206,21 @@ name = "peeking_take_while" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "proc-macro2" +version = "0.3.2" +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)", +] + [[package]] name = "quote" -version = "0.3.15" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "redox_syscall" @@ -298,6 +310,11 @@ name = "unicode-width" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unreachable" version = "0.1.1" @@ -392,7 +409,8 @@ dependencies = [ "checksum num-iter 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "4b226df12c5a59b63569dd57fafb926d91b385dfce33d8074a412411b689d593" "checksum num-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e7de20f146db9d920c45ee8ed8f71681fd9ade71909b48c3acbd766aa504cf10" "checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" -"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" +"checksum proc-macro2 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "681c2c8e039ff358cb926dbc5151d561cbd0249089986ace39dfe8e405bb7511" +"checksum quote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7b0ff51282f28dc1b53fd154298feaa2e77c5ea0dba68e1fd8b03b72fbe13d2a" "checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" "checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b" "checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db" @@ -405,6 +423,7 @@ dependencies = [ "checksum time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a15375f1df02096fb3317256ce2cee6a1f42fc84ea5ad5fc8c421cfe40c73098" "checksum unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8083c594e02b8ae1654ae26f0ade5158b119bd88ad0e8227a5d8fcd72407946" "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" +"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2ae5ddb18e1c92664717616dd9549dde73f539f01bd7b77c2edb2446bdff91" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" "checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" diff --git a/Cargo.toml b/Cargo.toml index 6e58f6aa60..a9f2bdc6cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,9 +50,10 @@ clap = "2" clang-sys = { version = "0.22.0", features = ["runtime", "clang_6_0"] } lazy_static = "1" peeking_take_while = "0.1.2" -quote = "0.3.15" +quote = { version = "0.5", default-features = false } regex = "0.2" which = "1.0.2" +proc-macro2 = { version = "0.3.2", default-features = false } [dependencies.env_logger] optional = true diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs index 9905430572..f1007c51e6 100644 --- a/src/codegen/helpers.rs +++ b/src/codegen/helpers.rs @@ -4,26 +4,28 @@ use ir::context::BindgenContext; use ir::layout::Layout; use quote; use std::mem; +use proc_macro2::{Term, Span}; pub mod attributes { use quote; + use proc_macro2::{Term, Span}; pub fn repr(which: &str) -> quote::Tokens { - let which = quote::Ident::new(which); + let which = Term::new(which, Span::call_site()); quote! { #[repr( #which )] } } pub fn repr_list(which_ones: &[&str]) -> quote::Tokens { - let which_ones = which_ones.iter().cloned().map(quote::Ident::new); + let which_ones = which_ones.iter().cloned().map(|one| Term::new(one, Span::call_site())); quote! { #[repr( #( #which_ones ),* )] } } pub fn derives(which_ones: &[&str]) -> quote::Tokens { - let which_ones = which_ones.iter().cloned().map(quote::Ident::new); + let which_ones = which_ones.iter().cloned().map(|one| Term::new(one, Span::call_site())); quote! { #[derive( #( #which_ones ),* )] } @@ -40,9 +42,9 @@ pub mod attributes { // time they get here. Just make sure that we have newlines around it so // that nothing else gets wrapped into the comment. let mut tokens = quote! {}; - tokens.append("\n"); - tokens.append(comment); - tokens.append("\n"); + tokens.append(Term::new("\n", Span::call_site())); + tokens.append(Term::new(&comment, Span::call_site())); + tokens.append(Term::new("\n", Span::call_site())); tokens } @@ -73,7 +75,7 @@ pub fn blob(layout: Layout) -> quote::Tokens { } }; - let ty_name = quote::Ident::new(ty_name); + let ty_name = Term::new(ty_name, Span::call_site()); let data_len = opaque.array_size().unwrap_or(layout.size); @@ -103,7 +105,7 @@ pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> quote::Tokens { let mut tokens = quote! {}; if ctx.options().enable_cxx_namespaces { - tokens.append(quote! { root:: }); + tokens.append_all(quote! { root:: }); } let align = match layout.align { @@ -114,7 +116,7 @@ pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> quote::Tokens { }; let size = layout.size; - tokens.append(quote! { + tokens.append_all(quote! { __BindgenBitfieldUnit<[u8; #size], #align> }); @@ -126,6 +128,7 @@ pub mod ast_ty { use ir::function::FunctionSig; use ir::ty::FloatKind; use quote; + use proc_macro2; pub fn raw_type(ctx: &BindgenContext, name: &str) -> quote::Tokens { let ident = ctx.rust_ident_raw(name); @@ -166,29 +169,25 @@ pub mod ast_ty { pub fn int_expr(val: i64) -> quote::Tokens { // Don't use quote! { #val } because that adds the type suffix. - let mut tokens = quote! {}; - tokens.append(val.to_string()); - tokens + let val = proc_macro2::Literal::i64_unsuffixed(val); + quote!(#val) } pub fn uint_expr(val: u64) -> quote::Tokens { // Don't use quote! { #val } because that adds the type suffix. - let mut tokens = quote! {}; - tokens.append(val.to_string()); - tokens + let val = proc_macro2::Literal::u64_unsuffixed(val); + quote!(#val) } pub fn byte_array_expr(bytes: &[u8]) -> quote::Tokens { let mut bytes: Vec<_> = bytes.iter().cloned().collect(); bytes.push(0); - quote! { - #bytes - } + quote! { [ #(#bytes),* ] } } pub fn cstr_expr(mut string: String) -> quote::Tokens { string.push('\0'); - let b = quote::ByteStr(&string); + let b = proc_macro2::Literal::byte_string(&string.as_bytes()); quote! { #b } @@ -199,16 +198,9 @@ pub mod ast_ty { f: f64, ) -> Result { if f.is_finite() { - let mut string = f.to_string(); - - // So it gets properly recognised as a floating point constant. - if !string.contains('.') { - string.push('.'); - } + let val = proc_macro2::Literal::f64_unsuffixed(f); - let mut tokens = quote! {}; - tokens.append(string); - return Ok(tokens); + return Ok(quote!(#val)); } let prefix = ctx.trait_prefix(); diff --git a/src/codegen/impl_partialeq.rs b/src/codegen/impl_partialeq.rs index 31c2c97976..a05c65e7ff 100644 --- a/src/codegen/impl_partialeq.rs +++ b/src/codegen/impl_partialeq.rs @@ -4,6 +4,7 @@ use ir::context::BindgenContext; use ir::item::{IsOpaque, Item}; use ir::ty::{TypeKind, RUST_DERIVE_IN_ARRAY_LIMIT}; use quote; +use proc_macro2; /// Generate a manual implementation of `PartialEq` trait for the /// specified compound type. @@ -71,7 +72,7 @@ pub fn gen_partialeq_impl( } fn gen_field(ctx: &BindgenContext, ty_item: &Item, name: &str) -> quote::Tokens { - fn quote_equals(name_ident: quote::Ident) -> quote::Tokens { + fn quote_equals(name_ident: proc_macro2::Term) -> quote::Tokens { quote! { self.#name_ident == other.#name_ident } } diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 39babb6bab..63e1e11ecb 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -38,6 +38,7 @@ use ir::ty::{Type, TypeKind}; use ir::var::Var; use quote; +use proc_macro2::{self, Term, Span}; use std::borrow::Cow; use std::cell::Cell; @@ -74,7 +75,7 @@ fn root_import(ctx: &BindgenContext, module: &Item) -> quote::Tokens { let mut tokens = quote! {}; - tokens.append_separated(path, "::"); + tokens.append_separated(path, Term::new("::", Span::call_site())); quote! { #[allow(unused_imports)] @@ -308,7 +309,7 @@ impl AppendImplicitTemplateParams for quote::Tokens { .expect("template params cannot fail to be a rust type") }); - self.append(quote! { + self.append_all(quote! { < #( #params ),* > }); } @@ -690,7 +691,7 @@ impl CodeGenerator for Type { // We prefer using `pub use` over `pub type` because of: // https://github.com/rust-lang/rust/issues/26264 - if inner_rust_type.as_str() + if inner_rust_type.to_string() .chars() .all(|c| match c { // These are the only characters allowed in simple @@ -701,19 +702,19 @@ impl CodeGenerator for Type { outer_params.is_none() && inner_item.expect_type().canonical_type(ctx).is_enum() { - tokens.append(quote! { + tokens.append_all(quote! { pub use }); let path = top_level_path(ctx, item); - tokens.append_separated(path, "::"); - tokens.append(quote! { + tokens.append_separated(path, Term::new("::", Span::call_site())); + tokens.append_all(quote! { :: #inner_rust_type as #rust_name ; }); result.push(tokens); return; } - tokens.append(quote! { + tokens.append_all(quote! { pub type #rust_name }); @@ -736,12 +737,12 @@ impl CodeGenerator for Type { .expect("type parameters can always convert to rust ty OK") }); - tokens.append(quote! { + tokens.append_all(quote! { < #( #params ),* > }); } - tokens.append(quote! { + tokens.append_all(quote! { = #inner_rust_type ; }); @@ -1058,11 +1059,11 @@ impl<'a> FieldCodegen<'a> for FieldData { self.annotations().accessor_kind().unwrap_or(accessor_kind); if is_private { - field.append(quote! { + field.append_all(quote! { #field_ident : #ty , }); } else { - field.append(quote! { + field.append_all(quote! { pub #field_ident : #ty , }); } @@ -1122,7 +1123,7 @@ impl<'a> FieldCodegen<'a> for FieldData { impl BitfieldUnit { /// Get the constructor name for this bitfield unit. fn ctor_name(&self) -> quote::Tokens { - let ctor_name = quote::Ident::new(format!("new_bitfield_{}", self.nth())); + let ctor_name = Term::new(&format!("new_bitfield_{}", self.nth()), Span::call_site()); quote! { #ctor_name } @@ -1153,7 +1154,7 @@ impl Bitfield { let width = self.width() as u8; let prefix = ctx.trait_prefix(); - ctor_impl.append(quote! { + ctor_impl.append_all(quote! { __bindgen_bitfield_unit.set( #offset, #width, @@ -1321,7 +1322,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { let prefix = ctx.trait_prefix(); let getter_name = bitfield_getter_name(ctx, self); let setter_name = bitfield_setter_name(ctx, self); - let unit_field_ident = quote::Ident::new(unit_field_name); + let unit_field_ident = Term::new(unit_field_name, Span::call_site()); let bitfield_ty_item = ctx.resolve_item(self.ty()); let bitfield_ty = bitfield_ty_item.expect_type(); @@ -1726,7 +1727,7 @@ impl CodeGenerator for CompInfo { } }; - tokens.append(quote! { + tokens.append_all(quote! { #generics { #( #fields )* } @@ -1749,7 +1750,7 @@ impl CodeGenerator for CompInfo { if self.found_unknown_attr() { warn!( "Type {} has an unkown attribute that may affect layout", - canonical_ident + canonical_ident.as_str() ); } @@ -1763,7 +1764,7 @@ impl CodeGenerator for CompInfo { if ctx.options().layout_tests && !self.is_forward_declaration() { if let Some(layout) = layout { let fn_name = - format!("bindgen_test_layout_{}", canonical_ident); + format!("bindgen_test_layout_{}", canonical_ident.as_str()); let fn_name = ctx.rust_ident_raw(fn_name); let prefix = ctx.trait_prefix(); let size_of_expr = quote! { @@ -2146,7 +2147,7 @@ enum EnumBuilder<'a> { Rust { codegen_depth: usize, attrs: Vec, - ident: quote::Ident, + ident: Term, tokens: quote::Tokens, emitted_any_variants: bool, }, @@ -2186,7 +2187,7 @@ impl<'a> EnumBuilder<'a> { enum_variation: EnumVariation, enum_codegen_depth: usize, ) -> Self { - let ident = quote::Ident::new(name); + let ident = Term::new(name, Span::call_site()); match enum_variation { EnumVariation::Bitfield => { @@ -2201,7 +2202,7 @@ impl<'a> EnumBuilder<'a> { } EnumVariation::Rust => { - let tokens = quote!{}; + let tokens = quote!(); EnumBuilder::Rust { codegen_depth: enum_codegen_depth + 1, attrs, @@ -2224,7 +2225,7 @@ impl<'a> EnumBuilder<'a> { } EnumVariation::ModuleConsts => { - let ident = quote::Ident::new(CONSTIFIED_ENUM_MODULE_REPR_NAME); + let ident = Term::new(CONSTIFIED_ENUM_MODULE_REPR_NAME, Span::call_site()); let type_definition = quote! { #( #attrs )* pub type #ident = #repr; @@ -2513,18 +2514,18 @@ impl CodeGenerator for Enum { ctx: &BindgenContext, enum_: &Type, // Only to avoid recomputing every time. - enum_canonical_name: "e::Ident, + enum_canonical_name: &Term, // May be the same as "variant" if it's because the // enum is unnamed and we still haven't seen the // value. variant_name: &str, - referenced_name: "e::Ident, + referenced_name: &Term, enum_rust_ty: quote::Tokens, result: &mut CodegenResult<'a>, ) { let constant_name = if enum_.name().is_some() { if ctx.options().prepend_enum_name { - format!("{}_{}", enum_canonical_name, variant_name) + format!("{}_{}", enum_canonical_name.as_str(), variant_name) } else { variant_name.into() } @@ -2553,7 +2554,7 @@ impl CodeGenerator for Enum { ); // A map where we keep a value -> variant relation. - let mut seen_values = HashMap::<_, quote::Ident>::new(); + let mut seen_values = HashMap::<_, Term>::new(); let enum_rust_ty = item.to_rust_ty_or_opaque(ctx, &()); let is_toplevel = item.is_toplevel(ctx); @@ -2651,12 +2652,13 @@ impl CodeGenerator for Enum { let parent_name = parent_canonical_name.as_ref().unwrap(); - quote::Ident::new( - format!( + Term::new( + &format!( "{}_{}", parent_name, - variant_name - ) + variant_name.as_str() + ), + Span::call_site() ) }; @@ -2664,14 +2666,14 @@ impl CodeGenerator for Enum { ctx, enum_ty, &ident, - mangled_name.as_ref(), + mangled_name.as_str(), &variant_name, enum_rust_ty.clone(), result, ); } - entry.insert(quote::Ident::new(variant_name)); + entry.insert(variant_name); } } } @@ -2998,10 +3000,9 @@ impl TryToRustTy for Type { }) } TypeKind::Enum(..) => { - let mut tokens = quote! {}; let path = item.namespace_aware_canonical_path(ctx); - tokens.append_separated(path.into_iter().map(quote::Ident::new), "::"); - Ok(tokens) + let path = Term::new(&path.join("::"), Span::call_site()); + Ok(quote!(#path)) } TypeKind::TemplateInstantiation(ref inst) => { inst.try_to_rust_ty(ctx, item) @@ -3123,7 +3124,7 @@ impl TryToRustTy for TemplateInstantiation { let mut ty = quote! {}; let def_path = def.namespace_aware_canonical_path(ctx); - ty.append_separated(def_path.into_iter().map(|p| ctx.rust_ident(p)), "::"); + ty.append_separated(def_path.into_iter().map(|p| ctx.rust_ident(p)), Term::new("::", Span::call_site())); let def_params = match def.self_template_params(ctx) { Some(params) => params, @@ -3336,7 +3337,7 @@ fn objc_method_codegen( let class_name = class_name .expect("Generating a class method without class name?") .to_owned(); - let expect_msg = format!("Couldn't find {}", class_name); + let expect_msg = proc_macro2::Literal::string(&format!("Couldn't find {}", class_name)); quote! { msg_send!(objc::runtime::Class::get(#class_name).expect(#expect_msg), #methods_and_args) } @@ -3462,11 +3463,12 @@ mod utils { use ir::item::{Item, ItemCanonicalPath}; use ir::ty::TypeKind; use quote; + use proc_macro2::{Term, Span}; use std::mem; pub fn prepend_bitfield_unit_type(result: &mut Vec) { - let mut bitfield_unit_type = quote! {}; - bitfield_unit_type.append(include_str!("./bitfield_unit.rs")); + let bitfield_unit_type = Term::new(include_str!("./bitfield_unit.rs"), Span::call_site()); + let bitfield_unit_type = quote!(#bitfield_unit_type); let items = vec![bitfield_unit_type]; let old_items = mem::replace(result, items); @@ -3692,10 +3694,12 @@ mod utils { item: &Item, ctx: &BindgenContext, ) -> error::Result { - let path = item.namespace_aware_canonical_path(ctx); + use proc_macro2::{Term, Span}; - let mut tokens = quote! {}; - tokens.append_separated(path.into_iter().map(quote::Ident::new), "::"); + let path = item.namespace_aware_canonical_path(ctx); + let path = Term::new(&path.join("::"), Span::call_site()); + let tokens = quote! {#path}; + //tokens.append_separated(path, "::"); Ok(tokens) } diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs index 3a641f4a30..6de7e03069 100644 --- a/src/codegen/struct_layout.rs +++ b/src/codegen/struct_layout.rs @@ -7,6 +7,7 @@ use ir::context::BindgenContext; use ir::layout::Layout; use ir::ty::{Type, TypeKind}; use quote; +use proc_macro2::{Term, Span}; use std::cmp; /// Trace the layout of struct. @@ -310,7 +311,7 @@ impl<'a> StructLayoutTracker<'a> { self.padding_count += 1; - let padding_field_name = quote::Ident::new(format!("__bindgen_padding_{}", padding_count)); + let padding_field_name = Term::new(&format!("__bindgen_padding_{}", padding_count), Span::call_site()); self.max_field_align = cmp::max(self.max_field_align, layout.align); diff --git a/src/ir/context.rs b/src/ir/context.rs index 07863809c5..6ced43e886 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -24,7 +24,7 @@ use cexpr; use clang::{self, Cursor}; use clang_sys; use parse::ClangItemParser; -use quote; +use proc_macro2::{Term, Span}; use std::borrow::Cow; use std::cell::Cell; use std::collections::{HashMap, HashSet, hash_map}; @@ -905,7 +905,7 @@ impl BindgenContext { } /// Returns a mangled name as a rust identifier. - pub fn rust_ident(&self, name: S) -> quote::Ident + pub fn rust_ident(&self, name: S) -> Term where S: AsRef { @@ -913,11 +913,11 @@ impl BindgenContext { } /// Returns a mangled name as a rust identifier. - pub fn rust_ident_raw(&self, name: T) -> quote::Ident + pub fn rust_ident_raw(&self, name: T) -> Term where - T: Into + T: AsRef { - name.into() + Term::new(name.as_ref(), Span::call_site()) } /// Iterate over all items that have been defined. @@ -2341,7 +2341,7 @@ impl BindgenContext { /// Convenient method for getting the prefix to use for most traits in /// codegen depending on the `use_core` option. - pub fn trait_prefix(&self) -> quote::Ident { + pub fn trait_prefix(&self) -> Term { if self.options().use_core { self.rust_ident_raw("core") } else { diff --git a/src/ir/function.rs b/src/ir/function.rs index 588090accf..602de80ce3 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -193,7 +193,7 @@ impl Abi { impl quote::ToTokens for Abi { fn to_tokens(&self, tokens: &mut quote::Tokens) { - tokens.append(match *self { + tokens.append_all(match *self { Abi::C => quote! { "C" }, Abi::Stdcall => quote! { "stdcall" }, Abi::Fastcall => quote! { "fastcall" }, diff --git a/src/ir/objc.rs b/src/ir/objc.rs index 0f72c39917..46c0802e87 100644 --- a/src/ir/objc.rs +++ b/src/ir/objc.rs @@ -13,6 +13,7 @@ use clang_sys::CXCursor_ObjCInstanceMethodDecl; use clang_sys::CXCursor_ObjCProtocolDecl; use clang_sys::CXCursor_ObjCProtocolRef; use quote; +use proc_macro2::{Term, Span}; /// Objective C interface as used in TypeKind /// @@ -216,7 +217,7 @@ impl ObjCMethod { let split_name: Vec<_> = self.name .split(':') .filter(|p| !p.is_empty()) - .map(quote::Ident::new) + .map(|name| Term::new(name, Span::call_site())) .collect(); // No arguments @@ -239,9 +240,10 @@ impl ObjCMethod { // Get arguments without type signatures to pass to `msg_send!` let mut args_without_types = vec![]; for arg in args.iter() { - let name_and_sig: Vec<&str> = arg.as_str().split(' ').collect(); + let arg = arg.to_string(); + let name_and_sig: Vec<&str> = arg.split(' ').collect(); let name = name_and_sig[0]; - args_without_types.push(quote::Ident::new(name)) + args_without_types.push(Term::new(name, Span::call_site())) }; let args = split_name diff --git a/src/lib.rs b/src/lib.rs index 6cdce76fd9..c715b9c2fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,7 @@ extern crate lazy_static; extern crate peeking_take_while; #[macro_use] extern crate quote; +extern crate proc_macro2; extern crate regex; extern crate which; @@ -1646,7 +1647,7 @@ impl Bindings { writer.write("\n".as_bytes())?; } - let bindings = self.module.as_str().to_string(); + let bindings = self.module.to_string(); match self.rustfmt_generated_string(&bindings) { Ok(rustfmt_bindings) => { @@ -1654,7 +1655,7 @@ impl Bindings { }, Err(err) => { eprintln!("{:?}", err); - writer.write(bindings.as_str().as_bytes())?; + writer.write(bindings.as_bytes())?; }, } Ok(()) diff --git a/tests/expectations/tests/comment-indent.rs b/tests/expectations/tests/comment-indent.rs index f00b0235f8..97afeefa95 100644 --- a/tests/expectations/tests/comment-indent.rs +++ b/tests/expectations/tests/comment-indent.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs index d105c58688..f9d29afd13 100644 --- a/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit diff --git a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs index 096bc1822f..159dba7c52 100644 --- a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs @@ -16,7 +16,7 @@ pub type EasyToOverflow = ::std::os::raw::c_ulonglong; pub const k: EasyToOverflow = 2147483648; pub const k_expr: EasyToOverflow = 0; pub const BAZ: ::std::os::raw::c_longlong = 24; -pub const fuzz: f64 = 51.; +pub const fuzz: f64 = 51.0; pub const BAZZ: ::std::os::raw::c_char = 53; pub const WAT: ::std::os::raw::c_char = 0; pub const bytestring: &'static [u8; 4usize] = b"Foo\0"; diff --git a/tests/expectations/tests/libclang-4/constant-evaluate.rs b/tests/expectations/tests/libclang-4/constant-evaluate.rs index 51365df584..045710f9d7 100644 --- a/tests/expectations/tests/libclang-4/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-4/constant-evaluate.rs @@ -14,7 +14,7 @@ pub type EasyToOverflow = ::std::os::raw::c_ulonglong; pub const k: EasyToOverflow = 2147483648; pub const k_expr: EasyToOverflow = 0; pub const BAZ: ::std::os::raw::c_longlong = 24; -pub const fuzz: f64 = 51.; +pub const fuzz: f64 = 51.0; pub const BAZZ: ::std::os::raw::c_char = 53; pub const WAT: ::std::os::raw::c_char = 0; pub const bytestring: &'static [u8; 4usize] = b"Foo\0"; diff --git a/tests/expectations/tests/libclang-5/constant-evaluate.rs b/tests/expectations/tests/libclang-5/constant-evaluate.rs index 51365df584..045710f9d7 100644 --- a/tests/expectations/tests/libclang-5/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-5/constant-evaluate.rs @@ -14,7 +14,7 @@ pub type EasyToOverflow = ::std::os::raw::c_ulonglong; pub const k: EasyToOverflow = 2147483648; pub const k_expr: EasyToOverflow = 0; pub const BAZ: ::std::os::raw::c_longlong = 24; -pub const fuzz: f64 = 51.; +pub const fuzz: f64 = 51.0; pub const BAZZ: ::std::os::raw::c_char = 53; pub const WAT: ::std::os::raw::c_char = 0; pub const bytestring: &'static [u8; 4usize] = b"Foo\0"; diff --git a/tests/expectations/tests/objc_class_method.rs b/tests/expectations/tests/objc_class_method.rs index a10a1fca10..2c5a326d80 100644 --- a/tests/expectations/tests/objc_class_method.rs +++ b/tests/expectations/tests/objc_class_method.rs @@ -1,6 +1,5 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] @@ -23,31 +22,31 @@ pub trait Foo { impl Foo for id { unsafe fn method() { msg_send!( - objc::runtime::Class::get("Foo").expect("Couldn't find Foo"), + objc::runtime::Class::get("Foo").expect("Couldn\'t find Foo"), method ) } unsafe fn methodWithInt_(foo: ::std::os::raw::c_int) { msg_send!( - objc::runtime::Class::get("Foo").expect("Couldn't find Foo"), + objc::runtime::Class::get("Foo").expect("Couldn\'t find Foo"), methodWithInt: foo ) } unsafe fn methodWithFoo_(foo: id) { msg_send!( - objc::runtime::Class::get("Foo").expect("Couldn't find Foo"), + objc::runtime::Class::get("Foo").expect("Couldn\'t find Foo"), methodWithFoo: foo ) } unsafe fn methodReturningInt() -> ::std::os::raw::c_int { msg_send!( - objc::runtime::Class::get("Foo").expect("Couldn't find Foo"), + objc::runtime::Class::get("Foo").expect("Couldn\'t find Foo"), methodReturningInt ) } unsafe fn methodReturningFoo() -> *mut id { msg_send!( - objc::runtime::Class::get("Foo").expect("Couldn't find Foo"), + objc::runtime::Class::get("Foo").expect("Couldn\'t find Foo"), methodReturningFoo ) } @@ -56,6 +55,6 @@ impl Foo for id { ptr: *mut ::std::os::raw::c_char, floatvalue: f32, ) { - msg_send ! ( objc :: runtime :: Class :: get ( "Foo" ) . expect ( "Couldn't find Foo" ) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue ) + msg_send ! ( objc :: runtime :: Class :: get ( "Foo" ) . expect ( "Couldn\'t find Foo" ) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue ) } } diff --git a/tests/expectations/tests/objc_method_clash.rs b/tests/expectations/tests/objc_method_clash.rs index f57951b47e..158a044391 100644 --- a/tests/expectations/tests/objc_method_clash.rs +++ b/tests/expectations/tests/objc_method_clash.rs @@ -1,6 +1,5 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] @@ -18,7 +17,7 @@ impl Foo for id { } unsafe fn class_foo() { msg_send!( - objc::runtime::Class::get("Foo").expect("Couldn't find Foo"), + objc::runtime::Class::get("Foo").expect("Couldn\'t find Foo"), foo ) } diff --git a/tests/expectations/tests/objc_whitelist.rs b/tests/expectations/tests/objc_whitelist.rs index 38881ad0fe..7a6e20fc20 100644 --- a/tests/expectations/tests/objc_whitelist.rs +++ b/tests/expectations/tests/objc_whitelist.rs @@ -1,6 +1,5 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] @@ -18,7 +17,7 @@ impl protocol_SomeProtocol for id { } unsafe fn protocolClassMethod() { msg_send!( - objc::runtime::Class::get("SomeProtocol").expect("Couldn't find SomeProtocol"), + objc::runtime::Class::get("SomeProtocol").expect("Couldn\'t find SomeProtocol"), protocolClassMethod ) } @@ -33,7 +32,7 @@ impl WhitelistMe for id { } unsafe fn classMethod() { msg_send!( - objc::runtime::Class::get("WhitelistMe").expect("Couldn't find WhitelistMe"), + objc::runtime::Class::get("WhitelistMe").expect("Couldn\'t find WhitelistMe"), classMethod ) }