# HG changeset patch # User Emilio Cobos Alvarez # Date 1520002112 -3600 # Node ID 0e06932d93c20f596e29e2b0b30fde9e79b663cb # Parent a43b6329a3e8202a32acdb9d8d93b5d7f241f339 Bug 1432153: Update bindgen. r=xidorn on a CLOSED TREE. MozReview-Commit-ID: BJH6Y58oYtk diff --git a/Cargo.lock b/Cargo.lock --- a/Cargo.lock +++ b/Cargo.lock @@ -139,29 +139,30 @@ source = "registry+https://github.com/ru checksum = "9a6301db0b49fb63551bc15b5ae348147101cdf323242b93ec7546d5002ff1af" dependencies = [ "byteorder", "serde", ] [[package]] name = "bindgen" -version = "0.32.2" +version = "0.32.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ed9557522980fcdb4986097c2ea9d2504eafa7e5818f393110205b5325a52ce" +checksum = "8b242e11a8f446f5fc7b76b37e81d737cabca562a927bd33766dac55b5f1177f" dependencies = [ "cexpr", "cfg-if", "clang-sys", "clap", "env_logger", "lazy_static 1.0.0", "log 0.3.9", "peeking_take_while", - "quote 0.3.15", + "proc-macro2", + "quote 0.4.2", "regex", "which", ] [[package]] name = "bitflags" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1282,19 +1283,19 @@ source = "registry+https://github.com/ru checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "prefs_parser" version = "0.0.1" [[package]] name = "proc-macro2" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cb7aaaa4bf022ec2b14ff2f2ba1643a22f3cee88df014a85e14b392282c61d" +checksum = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0" dependencies = [ "unicode-xid 0.1.0", ] [[package]] name = "procedural-masquerade" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1322,17 +1323,17 @@ source = "registry+https://github.com/ru checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" [[package]] name = "quote" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1eca14c727ad12702eb4b6bfb5a232287dcf8385cb8ca83a3eeaf6519c44c408" dependencies = [ - "proc-macro2 0.2.2", + "proc-macro2", ] [[package]] name = "rand" version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6475140dfd8655aeb72e1fd4b7a1cc1c202be65d71669476e392fe62532b9edd" dependencies = [ diff --git a/js/rust/Cargo.toml b/js/rust/Cargo.toml --- a/js/rust/Cargo.toml +++ b/js/rust/Cargo.toml @@ -3,17 +3,17 @@ name = "js" version = "0.1.4" authors = ["The Servo Project Developers"] build = "build.rs" license = "MPL-2.0" [build-dependencies] env_logger = {version = "0.4", default-features = false} # disable `regex` to reduce code size log = "0.3" -bindgen = {version = "0.32.2", default-features = false} # disable `logging` to reduce code size +bindgen = {version = "0.32.3", default-features = false} # disable `logging` to reduce code size cmake = "0.1" glob = "0.2.11" [[test]] name = "callback" [[test]] name = "enumerate" [[test]] diff --git a/third_party/rust/bindgen/.cargo-checksum.json b/third_party/rust/bindgen/.cargo-checksum.json --- a/third_party/rust/bindgen/.cargo-checksum.json +++ b/third_party/rust/bindgen/.cargo-checksum.json @@ -1,1 +1,1 @@ -{"files":{"Cargo.toml":"1373d611f13384cfb380e67f4553d83428094168d0149d464af4b9e49015057c","build.rs":"032a1c51963894a421b0535f9227796d88768ac5f665a81d2edced69dc6d106a","src/callbacks.rs":"c5c4e5bc8c49cb191d1b100339772fdc7dd1dbf5025a9de1ecaafb70f86cb48f","src/clang.rs":"c816d5291ccdc1d4ba028ae817ef385048e1fb8443911d026af5c721a6d57854","src/codegen/bitfield_unit.rs":"bd1a19701f1766d0bae3bcb97d7c3cb3881d4b182c56b8f4dfd24b7cc87b5338","src/codegen/bitfield_unit_tests.rs":"2073ac6a36e0bc9afaef5b1207966817c8fb7a1a9f6368c3b1b8f79822efbfba","src/codegen/error.rs":"2613af1d833377fd4a70719f4a09951d9d45dc9227827b9a2a938a1bcaaea2dd","src/codegen/helpers.rs":"bcb951f320fd0948e341d8eabdb58567296d77bf1ae5040c05d967e6435a15d5","src/codegen/impl_debug.rs":"e2ffd5b6ed936698aa4b9e7e3459d353383792707ad51f829a18a822f69cab0e","src/codegen/impl_partialeq.rs":"e86050b98f57fa4496dbde0beea319a89e46290309d274f626361779549b95bd","src/codegen/mod.rs":"4efd9f819f2417e76235fdbb61f9f66a5bbb3ac0a402f69a8826ebf9ce9276e1","src/codegen/struct_layout.rs":"3c4b2b4543c6aa1da03f7522ad7f831e95dc146cf5edd08ebd5facb1305daddb","src/extra_assertions.rs":"449549c4a7a50c3f0b06332452b2fb6c9b23f31ca8e5e1656fe6c7f21e8ef7fa","src/features.rs":"8c2148a6f922ca9cb0de2dd3ad77c4dd5734c4c219a5bea9d6b22c4367acb187","src/ir/analysis/derive_copy.rs":"c8d700dcde2419d2687377a7cb1024ad3722bbcb83d0b1031618f57d484793b4","src/ir/analysis/derive_debug.rs":"1d6621c0fa5d899310cc175cb99703606ed34fd7f7ad77bb60f012f25ba504af","src/ir/analysis/derive_default.rs":"3af97eaa9bdc91a0bded060b393d0bb23ef9dcf59a7a6ed7d79814f35f73b66a","src/ir/analysis/derive_hash.rs":"c8a95040352b3d10f8edb46f6ae513d4f15ec87197668b1fc1d7cf2cb416054f","src/ir/analysis/derive_partialeq_or_partialord.rs":"1f7c097bde85ebb4082a3a318a753db13e8b4733fa1433dcc054f137dc0e6c2d","src/ir/analysis/has_destructor.rs":"d9aaaceba580b48eb0df4e5537b34b417c51ccdfeb8f6b72484f3bf4992317fe","src/ir/analysis/has_float.rs":"2a0465503d2c8247eaf916bd6a03594f3dc0370533d9a7c58cc5afb86693816c","src/ir/analysis/has_type_param_in_array.rs":"fcb1c78b6000f1f5eb8d8147e2afdaba9eb0e3a81b61e72537048dfdbeea7bcd","src/ir/analysis/has_vtable.rs":"37765e954ef792e369a58ccfe1d827a00fe9bce680466da1d6523671b94b6c92","src/ir/analysis/mod.rs":"ea5ace45c77e855674bb565ba0fef556f60e3293b0ddcf11d3a5a6ec15ab0648","src/ir/analysis/sizedness.rs":"3d3c8bde40604d53bb64273a3cbd8c55936a7dfe1de9b2ba92fc2c45572624b4","src/ir/analysis/template_params.rs":"5c6ee7a251a321ef5733e2e7ac3264621b4181268babcc008b69dbfc37691fb1","src/ir/annotations.rs":"ef106afcbe6084c18bd13a37ee3c1cdc9596bfb055db8c773d81f8f15fec3208","src/ir/comment.rs":"36f2a1d3970fdbf3d72c1f094043902747cde395215bdf7e9103926d9df011fd","src/ir/comp.rs":"461ae606b0f49638c1f78c627da4837949dd367d3589d92a7f7d05eca7028796","src/ir/context.rs":"05258f113012a923d1e0516aee2c60769757727c2e1aa7a6101e17ef8db1f944","src/ir/derive.rs":"1fd6ad621e3c60b950acbd51fbe386d1f0fadb7c1889c723245afff45e42e143","src/ir/dot.rs":"eca03a493a7fe48044b832c37c71d51f1bd4e8689feb6f1cb8bc0422541c7284","src/ir/enum_ty.rs":"63cf8ba48858e2f02b58cd437d763cc18ddf6a841044cafdd51687c28ace1862","src/ir/function.rs":"6d6d011df29ccf1c0c1db39ceb0acb70e9dda61282d45b6eb5bc4581543a2588","src/ir/int.rs":"1f61a472288afe489d9320bc8b13920333ece57891ae8570b4c4f25ab50688e6","src/ir/item.rs":"527b9a006dd1865cb77bac7e0e3826904c71b3b77679bcf7cd4ea63791dfa5ec","src/ir/item_kind.rs":"13048962657436a757ff9483d96f2ce351ec5f827ecab4921ed643f6f115c497","src/ir/layout.rs":"e3d1adf1ad2fa5bd96530cdd5097db3d9cc7b44d33ec23a04fcfccecd9cf4469","src/ir/mod.rs":"2eae90f207fad2e45957ec9287064992a419e3fc916aba84faff2ea25cbeb5ee","src/ir/module.rs":"c4d90bf38fe3672e01923734ccbdb7951ea929949d5f413a9c2aee12395a5094","src/ir/objc.rs":"05068c4fbf42429c4ac2a233c874f18ffcf7dc1744398e400a5a48d0e7a972f2","src/ir/template.rs":"bcd750450a4df0200a6e7958f9c96a09b91e3ccd29c60712f2b9d3458f1234aa","src/ir/traversal.rs":"a108f2b2a1b3d2e679274eead8cf6f8fc78454e88943527d56bb30b5f071f104","src/ir/ty.rs":"4d5f1b2e11f6fb7df3348bdab7775cdfa209e136afe84a7b0e862068e53e7183","src/ir/var.rs":"f6eb7a29b262c2eb8615612f207f251097e4bcbcb523f53dcad174ec6d11f4ce","src/lib.rs":"9f6136c49ec1118cf0eec474534db63a1190cf93717bfbf10a95b5a73411b8f6","src/log_stubs.rs":"6dfdd908b7c6453da416cf232893768f9480e551ca4add0858ef88bf71ee6ceb","src/main.rs":"fa0a21b4aca4df72896f911de3ee252bec87abb4c871e39b53e90923181a1658","src/options.rs":"c31da7f76035a7831073e44773bfbe796840403b88db7ae58a49b688cd90aef6","src/parse.rs":"be7d13cc84fae79ec7b3aa9e77063fa475a48d74a854423e2c72d75006a25202","src/regex_set.rs":"a55241f2117f15729d174790f386e255fcb224b692325bbe6716dbb1d6874881","src/time.rs":"a02befb48d10dcc31e3f9571b2fa1c40f97fafe6f6ae7d7fc4f8fd01f1a169ba"},"package":"6ed9557522980fcdb4986097c2ea9d2504eafa7e5818f393110205b5325a52ce"} \ No newline at end of file +{"files":{"Cargo.toml":"9194dcdbb9477b1f4311debaad3ad044f721be054574416734ba09d2d7194a81","build.rs":"032a1c51963894a421b0535f9227796d88768ac5f665a81d2edced69dc6d106a","src/callbacks.rs":"c5c4e5bc8c49cb191d1b100339772fdc7dd1dbf5025a9de1ecaafb70f86cb48f","src/clang.rs":"c816d5291ccdc1d4ba028ae817ef385048e1fb8443911d026af5c721a6d57854","src/codegen/bitfield_unit.rs":"bd1a19701f1766d0bae3bcb97d7c3cb3881d4b182c56b8f4dfd24b7cc87b5338","src/codegen/bitfield_unit_tests.rs":"2073ac6a36e0bc9afaef5b1207966817c8fb7a1a9f6368c3b1b8f79822efbfba","src/codegen/error.rs":"2613af1d833377fd4a70719f4a09951d9d45dc9227827b9a2a938a1bcaaea2dd","src/codegen/helpers.rs":"15407de2a521043d456fddc0934757a8da0a5decac3ecdf93b669b27fb6a6be2","src/codegen/impl_debug.rs":"e2ffd5b6ed936698aa4b9e7e3459d353383792707ad51f829a18a822f69cab0e","src/codegen/impl_partialeq.rs":"9f3c6aaa8da01ecad0c4d4d8996f6d20c00b8cf68d7620654b7d42d6a23725d9","src/codegen/mod.rs":"c7d933cab870d798bfa8fb6ea3d5768832c6e5fbae741994a3b6ce2c96b159ec","src/codegen/struct_layout.rs":"9edf0bbd0a3d17a93e188f9aba42bdf5bd938eca9c50e9c509977923eb16ef11","src/extra_assertions.rs":"449549c4a7a50c3f0b06332452b2fb6c9b23f31ca8e5e1656fe6c7f21e8ef7fa","src/features.rs":"8c2148a6f922ca9cb0de2dd3ad77c4dd5734c4c219a5bea9d6b22c4367acb187","src/ir/analysis/derive_copy.rs":"c8d700dcde2419d2687377a7cb1024ad3722bbcb83d0b1031618f57d484793b4","src/ir/analysis/derive_debug.rs":"1d6621c0fa5d899310cc175cb99703606ed34fd7f7ad77bb60f012f25ba504af","src/ir/analysis/derive_default.rs":"3af97eaa9bdc91a0bded060b393d0bb23ef9dcf59a7a6ed7d79814f35f73b66a","src/ir/analysis/derive_hash.rs":"c8a95040352b3d10f8edb46f6ae513d4f15ec87197668b1fc1d7cf2cb416054f","src/ir/analysis/derive_partialeq_or_partialord.rs":"1f7c097bde85ebb4082a3a318a753db13e8b4733fa1433dcc054f137dc0e6c2d","src/ir/analysis/has_destructor.rs":"d9aaaceba580b48eb0df4e5537b34b417c51ccdfeb8f6b72484f3bf4992317fe","src/ir/analysis/has_float.rs":"2a0465503d2c8247eaf916bd6a03594f3dc0370533d9a7c58cc5afb86693816c","src/ir/analysis/has_type_param_in_array.rs":"fcb1c78b6000f1f5eb8d8147e2afdaba9eb0e3a81b61e72537048dfdbeea7bcd","src/ir/analysis/has_vtable.rs":"37765e954ef792e369a58ccfe1d827a00fe9bce680466da1d6523671b94b6c92","src/ir/analysis/mod.rs":"ea5ace45c77e855674bb565ba0fef556f60e3293b0ddcf11d3a5a6ec15ab0648","src/ir/analysis/sizedness.rs":"3d3c8bde40604d53bb64273a3cbd8c55936a7dfe1de9b2ba92fc2c45572624b4","src/ir/analysis/template_params.rs":"5c6ee7a251a321ef5733e2e7ac3264621b4181268babcc008b69dbfc37691fb1","src/ir/annotations.rs":"ef106afcbe6084c18bd13a37ee3c1cdc9596bfb055db8c773d81f8f15fec3208","src/ir/comment.rs":"36f2a1d3970fdbf3d72c1f094043902747cde395215bdf7e9103926d9df011fd","src/ir/comp.rs":"461ae606b0f49638c1f78c627da4837949dd367d3589d92a7f7d05eca7028796","src/ir/context.rs":"870e2743cc7b547c04b20205354aa1c3b8c70f4d393db37288dd72ab6997104d","src/ir/derive.rs":"1fd6ad621e3c60b950acbd51fbe386d1f0fadb7c1889c723245afff45e42e143","src/ir/dot.rs":"eca03a493a7fe48044b832c37c71d51f1bd4e8689feb6f1cb8bc0422541c7284","src/ir/enum_ty.rs":"63cf8ba48858e2f02b58cd437d763cc18ddf6a841044cafdd51687c28ace1862","src/ir/function.rs":"2eb054ae04ef8067b020717c82d055c9f9853c8b31e14de6319be85656d88cf2","src/ir/int.rs":"1f61a472288afe489d9320bc8b13920333ece57891ae8570b4c4f25ab50688e6","src/ir/item.rs":"527b9a006dd1865cb77bac7e0e3826904c71b3b77679bcf7cd4ea63791dfa5ec","src/ir/item_kind.rs":"13048962657436a757ff9483d96f2ce351ec5f827ecab4921ed643f6f115c497","src/ir/layout.rs":"e3d1adf1ad2fa5bd96530cdd5097db3d9cc7b44d33ec23a04fcfccecd9cf4469","src/ir/mod.rs":"2eae90f207fad2e45957ec9287064992a419e3fc916aba84faff2ea25cbeb5ee","src/ir/module.rs":"c4d90bf38fe3672e01923734ccbdb7951ea929949d5f413a9c2aee12395a5094","src/ir/objc.rs":"6516f60b71a8b652e618c64cd4eac6e8bfaa561a3c159cfc44d15bf216b1224f","src/ir/template.rs":"bcd750450a4df0200a6e7958f9c96a09b91e3ccd29c60712f2b9d3458f1234aa","src/ir/traversal.rs":"a108f2b2a1b3d2e679274eead8cf6f8fc78454e88943527d56bb30b5f071f104","src/ir/ty.rs":"4d5f1b2e11f6fb7df3348bdab7775cdfa209e136afe84a7b0e862068e53e7183","src/ir/var.rs":"f6eb7a29b262c2eb8615612f207f251097e4bcbcb523f53dcad174ec6d11f4ce","src/lib.rs":"439d0f5c4e2c6df76c71856fdbddf03657c677fe341760a4305f4a240b6fee2b","src/log_stubs.rs":"6dfdd908b7c6453da416cf232893768f9480e551ca4add0858ef88bf71ee6ceb","src/main.rs":"fa0a21b4aca4df72896f911de3ee252bec87abb4c871e39b53e90923181a1658","src/options.rs":"c31da7f76035a7831073e44773bfbe796840403b88db7ae58a49b688cd90aef6","src/parse.rs":"be7d13cc84fae79ec7b3aa9e77063fa475a48d74a854423e2c72d75006a25202","src/regex_set.rs":"a55241f2117f15729d174790f386e255fcb224b692325bbe6716dbb1d6874881","src/time.rs":"a02befb48d10dcc31e3f9571b2fa1c40f97fafe6f6ae7d7fc4f8fd01f1a169ba"},"package":"8b242e11a8f446f5fc7b76b37e81d737cabca562a927bd33766dac55b5f1177f"} \ No newline at end of file diff --git a/third_party/rust/bindgen/Cargo.toml b/third_party/rust/bindgen/Cargo.toml --- a/third_party/rust/bindgen/Cargo.toml +++ b/third_party/rust/bindgen/Cargo.toml @@ -7,17 +7,17 @@ # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "bindgen" -version = "0.32.2" +version = "0.32.3" authors = ["Jyun-Yan You ", "Emilio Cobos Álvarez ", "Nick Fitzgerald ", "The Servo project developers"] build = "build.rs" include = ["Cargo.toml", "build.rs", "src/*.rs", "src/**/*.rs"] description = "Automatically generates Rust FFI bindings to C and C++ libraries." documentation = "https://docs.rs/bindgen" readme = "README.md" keywords = ["bindings", "ffi", "code-generation"] categories = ["external-ffi-bindings", "development-tools::ffi"] @@ -53,18 +53,21 @@ version = "1" [dependencies.log] version = "0.3" optional = true [dependencies.peeking_take_while] version = "0.1.2" +[dependencies.proc-macro2] +version = "0.2" + [dependencies.quote] -version = "0.3.15" +version = "0.4" [dependencies.regex] version = "0.2" [dependencies.which] version = "1.0.2" [dev-dependencies.clap] version = "2" diff --git a/third_party/rust/bindgen/src/codegen/helpers.rs b/third_party/rust/bindgen/src/codegen/helpers.rs --- a/third_party/rust/bindgen/src/codegen/helpers.rs +++ b/third_party/rust/bindgen/src/codegen/helpers.rs @@ -1,54 +1,53 @@ //! Helpers for code generation that don't need macro expansion. use ir::context::BindgenContext; use ir::layout::Layout; use quote; +use proc_macro2; use std::mem; pub mod attributes { use quote; + use proc_macro2; pub fn repr(which: &str) -> quote::Tokens { - let which = quote::Ident::new(which); + let which = proc_macro2::Term::intern(which); 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(proc_macro2::Term::intern); 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(proc_macro2::Term::intern); quote! { #[derive( #( #which_ones ),* )] } } pub fn inline() -> quote::Tokens { quote! { #[inline] } } pub fn doc(comment: String) -> quote::Tokens { // Doc comments are already preprocessed into nice `///` formats by the // 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 + let comment = proc_macro2::Literal::doccomment(&comment); + quote! {#comment} } pub fn link_name(name: &str) -> quote::Tokens { // LLVM mangles the name by default but it's already mangled. // Prefixing the name with \u{1} should tell LLVM to not mangle it. let name = format!("\u{1}{}", name); quote! { #[link_name = #name] @@ -68,17 +67,17 @@ pub fn blob(layout: Layout) -> quote::To let ty_name = match opaque.known_rust_type_for_array() { Some(ty) => ty, None => { warn!("Found unknown alignment on code generation!"); "u8" } }; - let ty_name = quote::Ident::new(ty_name); + let ty_name = proc_macro2::Term::intern(ty_name); let data_len = opaque.array_size().unwrap_or(layout.size); if data_len == 1 { quote! { #ty_name } } else { @@ -98,39 +97,40 @@ pub fn integer_type(layout: Layout) -> O } } /// Generates a bitfield allocation unit type for a type with the given `Layout`. 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 { n if n >= 8 => quote! { u64 }, 4 => quote! { u32 }, 2 => quote! { u16 }, _ => quote! { u8 }, }; let size = layout.size; - tokens.append(quote! { + tokens.append_all(quote! { __BindgenBitfieldUnit<[u8; #size], #align> }); tokens } pub mod ast_ty { use ir::context::BindgenContext; 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); match ctx.options().ctypes_prefix { Some(ref prefix) => { let prefix = ctx.rust_ident_raw(prefix.as_str()); quote! { #prefix::#ident @@ -161,59 +161,48 @@ pub mod ast_ty { (FloatKind::Double, false) | (FloatKind::LongDouble, false) => raw_type(ctx, "c_double"), (FloatKind::Float128, _) => quote! { [u8; 16] }, } } 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::integer(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::Term::intern(&val.to_string()); + 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 } } pub fn float_expr( ctx: &BindgenContext, f: f64, ) -> Result { if f.is_finite() { - let mut string = f.to_string(); + let val = proc_macro2::Literal::float(f); - // So it gets properly recognised as a floating point constant. - if !string.contains('.') { - string.push('.'); - } - - let mut tokens = quote! {}; - tokens.append(string); - return Ok(tokens); + return Ok(quote!(#val)); } let prefix = ctx.trait_prefix(); if f.is_nan() { return Ok(quote! { ::#prefix::f64::NAN }); diff --git a/third_party/rust/bindgen/src/codegen/impl_partialeq.rs b/third_party/rust/bindgen/src/codegen/impl_partialeq.rs --- a/third_party/rust/bindgen/src/codegen/impl_partialeq.rs +++ b/third_party/rust/bindgen/src/codegen/impl_partialeq.rs @@ -1,14 +1,15 @@ use ir::comp::{CompInfo, CompKind, Field, FieldMethods}; 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. pub fn gen_partialeq_impl( ctx: &BindgenContext, comp_info: &CompInfo, item: &Item, ty_for_impl: "e::Tokens, @@ -66,17 +67,17 @@ pub fn gen_partialeq_impl( Some(quote! { fn eq(&self, other: & #ty_for_impl) -> bool { #( #tokens )&&* } }) } 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 } } let name_ident = ctx.rust_ident(name); let ty = ty_item.expect_type(); match *ty.kind() { TypeKind::Void | diff --git a/third_party/rust/bindgen/src/codegen/mod.rs b/third_party/rust/bindgen/src/codegen/mod.rs --- a/third_party/rust/bindgen/src/codegen/mod.rs +++ b/third_party/rust/bindgen/src/codegen/mod.rs @@ -33,16 +33,17 @@ use ir::item_kind::ItemKind; use ir::layout::Layout; use ir::module::Module; use ir::objc::{ObjCInterface, ObjCMethod}; use ir::template::{AsTemplateParam, TemplateInstantiation, TemplateParameters}; use ir::ty::{Type, TypeKind}; use ir::var::Var; use quote; +use proc_macro2; use std::borrow::Cow; use std::cell::Cell; use std::collections::{HashSet, VecDeque}; use std::collections::hash_map::{Entry, HashMap}; use std::fmt::Write; use std::iter; use std::mem; @@ -70,17 +71,17 @@ fn root_import(ctx: &BindgenContext, mod let mut path = top_level_path(ctx, module); let root = ctx.root_module().canonical_name(ctx); let root_ident = ctx.rust_ident(&root); path.push(quote! { #root_ident }); let mut tokens = quote! {}; - tokens.append_separated(path, "::"); + tokens.append_separated(path, proc_macro2::Term::intern("::")); quote! { #[allow(unused_imports)] use #tokens ; } } struct CodegenResult<'a> { @@ -304,17 +305,17 @@ impl AppendImplicitTemplateParams for qu return; } let params = params.into_iter().map(|p| { p.try_to_rust_ty(ctx, &()) .expect("template params cannot fail to be a rust type") }); - self.append(quote! { + self.append_all(quote! { < #( #params ),* > }); } } } trait CodeGenerator { /// Extra information from the caller. @@ -555,29 +556,22 @@ impl CodeGenerator for Var { } else { let mut attrs = vec![]; if let Some(mangled) = self.mangled_name() { attrs.push(attributes::link_name(mangled)); } else if canonical_name != self.name() { attrs.push(attributes::link_name(self.name())); } - let mut tokens = quote! { - extern "C" - }; - tokens.append("{\n"); - if !attrs.is_empty() { - tokens.append_separated(attrs, "\n"); - tokens.append("\n"); - } - tokens.append("pub static mut "); - tokens.append(quote! { #canonical_ident }); - tokens.append(" : "); - tokens.append(quote! { #ty }); - tokens.append(";\n}"); + let mut tokens = quote!( + extern "C" { + #(#attrs)* + pub static mut #canonical_ident: #ty; + } + ); result.push(tokens); } } } impl CodeGenerator for Type { type Extra = Item; @@ -687,40 +681,40 @@ impl CodeGenerator for Type { let mut tokens = if let Some(comment) = item.comment(ctx) { attributes::doc(comment) } else { quote! {} }; // 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 // paths, eg `good::dogs::Bront`. 'A'...'Z' | 'a'...'z' | '0'...'9' | ':' | '_' | ' ' => true, _ => false, }) && 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, proc_macro2::Term::intern("::")); + 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 }); if let Some(params) = outer_params { let params: Vec<_> = params.into_iter() .filter_map(|p| p.as_template_param(ctx, &())) .collect(); if params.iter().any(|p| ctx.resolve_type(*p).is_invalid_type_param()) { @@ -733,22 +727,22 @@ impl CodeGenerator for Type { } let params = params.iter() .map(|p| { p.try_to_rust_ty(ctx, &()) .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 ; }); result.push(tokens); } TypeKind::Enum(ref ei) => ei.codegen(ctx, result, item), TypeKind::ObjCId | TypeKind::ObjCSel => { result.saw_objc(); @@ -1055,21 +1049,21 @@ impl<'a> FieldCodegen<'a> for FieldData let is_private = self.annotations().private_fields().unwrap_or( fields_should_be_private, ); let accessor_kind = 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 , }); } fields.extend(Some(field)); // TODO: Factor the following code out, please! if accessor_kind == FieldAccessorKind::None { @@ -1119,17 +1113,17 @@ 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 = proc_macro2::Term::intern(&format!("new_bitfield_{}", self.nth())); quote! { #ctor_name } } } impl Bitfield { /// Extend an under construction bitfield unit constructor with this @@ -1150,17 +1144,17 @@ impl Bitfield { "Bitfield without layout? Gah!", ); let bitfield_int_ty = helpers::blob(bitfield_ty_layout); let offset = self.offset_into_unit(); 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, { let #param_name: #bitfield_int_ty = unsafe { ::#prefix::mem::transmute(#param_name) }; #param_name as u64 @@ -1318,17 +1312,17 @@ impl<'a> FieldCodegen<'a> for Bitfield { (unit_field_name, bitfield_representable_as_int): (&'a str, &mut bool), ) where F: Extend, M: Extend, { 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 = proc_macro2::Term::intern(unit_field_name); let bitfield_ty_item = ctx.resolve_item(self.ty()); let bitfield_ty = bitfield_ty_item.expect_type(); let bitfield_ty_layout = bitfield_ty.layout(ctx).expect( "Bitfield without layout? Gah!", ); let bitfield_int_ty = match helpers::integer_type(bitfield_ty_layout) { @@ -1723,17 +1717,17 @@ impl CodeGenerator for CompInfo { } } else { quote! { #( #attributes )* pub struct #canonical_ident } }; - tokens.append(quote! { + tokens.append_all(quote! { #generics { #( #fields )* } }); result.push(tokens); // Generate the inner types and all that stuff. // @@ -1746,31 +1740,31 @@ impl CodeGenerator for CompInfo { } // NOTE: Some unexposed attributes (like alignment attributes) may // affect layout, so we're bad and pray to the gods for avoid sending // all the tests to shit when parsing things like max_align_t. if self.found_unknown_attr() { warn!( "Type {} has an unkown attribute that may affect layout", - canonical_ident + canonical_ident.as_str() ); } if used_template_params.is_none() { if !is_opaque { for var in self.inner_vars() { ctx.resolve_item(*var).codegen(ctx, result, &()); } } if ctx.options().layout_tests { 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! { ::#prefix::mem::size_of::<#canonical_ident>() }; let align_of_expr = quote! { ::#prefix::mem::align_of::<#canonical_ident>() }; @@ -2139,16 +2133,18 @@ impl EnumVariation { _ => false } } } /// A helper type to construct different enum variations. enum EnumBuilder<'a> { Rust { + attrs: Vec, + ident: proc_macro2::Term, tokens: quote::Tokens, emitted_any_variants: bool, }, Bitfield { canonical_name: &'a str, tokens: quote::Tokens, }, Consts(Vec), @@ -2162,51 +2158,49 @@ impl<'a> EnumBuilder<'a> { /// Create a new enum given an item builder, a canonical name, a name for /// the representation, and which variation it should be generated as. fn new( name: &'a str, attrs: Vec, repr: quote::Tokens, enum_variation: EnumVariation ) -> Self { - let ident = quote::Ident::new(name); + let ident = proc_macro2::Term::intern(name); match enum_variation { EnumVariation::Bitfield => { EnumBuilder::Bitfield { canonical_name: name, tokens: quote! { #( #attrs )* pub struct #ident (pub #repr); }, } } EnumVariation::Rust => { - let mut tokens = quote! { - #( #attrs )* - pub enum #ident - }; - tokens.append("{"); + let tokens = quote!(); EnumBuilder::Rust { + attrs, + ident, tokens, emitted_any_variants: false, } } EnumVariation::Consts => { EnumBuilder::Consts(vec![ quote! { pub type #ident = #repr; } ]) } EnumVariation::ModuleConsts => { - let ident = quote::Ident::new(CONSTIFIED_ENUM_MODULE_REPR_NAME); + let ident = proc_macro2::Term::intern(CONSTIFIED_ENUM_MODULE_REPR_NAME); let type_definition = quote! { pub type #ident = #repr; }; EnumBuilder::ModuleConsts { module_name: name, module_items: vec![type_definition], } @@ -2225,19 +2219,21 @@ impl<'a> EnumBuilder<'a> { ) -> Self { let variant_name = ctx.rust_mangle(variant.name()); let expr = match variant.val() { EnumVariantValue::Signed(v) => helpers::ast_ty::int_expr(v), EnumVariantValue::Unsigned(v) => helpers::ast_ty::uint_expr(v), }; match self { - EnumBuilder::Rust { tokens, emitted_any_variants: _ } => { + EnumBuilder::Rust { attrs, ident, tokens, emitted_any_variants: _ } => { let name = ctx.rust_ident(variant_name); EnumBuilder::Rust { + attrs, + ident, tokens: quote! { #tokens #name = #expr, }, emitted_any_variants: true, } } @@ -2294,22 +2290,29 @@ impl<'a> EnumBuilder<'a> { fn build<'b>( self, ctx: &BindgenContext, rust_ty: quote::Tokens, result: &mut CodegenResult<'b>, ) -> quote::Tokens { match self { - EnumBuilder::Rust { mut tokens, emitted_any_variants } => { - if !emitted_any_variants { - tokens.append(quote! { __bindgen_cannot_repr_c_on_empty_enum = 0 }); - } - tokens.append("}"); - tokens + EnumBuilder::Rust { attrs, ident, tokens, emitted_any_variants } => { + let variants = if !emitted_any_variants { + quote!(__bindgen_cannot_repr_c_on_empty_enum = 0) + } else { + tokens + }; + + quote! ( + #( #attrs )* + pub enum #ident { + #variants + } + ) } EnumBuilder::Bitfield { canonical_name, tokens, } => { let rust_ty_name = ctx.rust_ident_raw(canonical_name); let prefix = ctx.trait_prefix(); @@ -2455,28 +2458,28 @@ impl CodeGenerator for Enum { &["Debug", "Copy", "Clone", "PartialEq", "Eq", "Hash"], )); } fn add_constant<'a>( ctx: &BindgenContext, enum_: &Type, // Only to avoid recomputing every time. - enum_canonical_name: "e::Ident, + enum_canonical_name: &proc_macro2::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: &proc_macro2::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() } } else { variant_name.into() }; let constant_name = ctx.rust_ident(constant_name); @@ -2494,17 +2497,17 @@ impl CodeGenerator for Enum { let mut builder = EnumBuilder::new( &name, attrs, repr, variation ); // A map where we keep a value -> variant relation. - let mut seen_values = HashMap::<_, quote::Ident>::new(); + let mut seen_values = HashMap::<_, proc_macro2::Term>::new(); let enum_rust_ty = item.to_rust_ty_or_opaque(ctx, &()); let is_toplevel = item.is_toplevel(ctx); // Used to mangle the constants we generate in the unnamed-enum case. let parent_canonical_name = if is_toplevel { None } else { Some(item.parent_id().canonical_name(ctx)) @@ -2593,37 +2596,37 @@ impl CodeGenerator for Enum { variant.force_constification() { let mangled_name = if is_toplevel { variant_name.clone() } else { let parent_name = parent_canonical_name.as_ref().unwrap(); - quote::Ident::new( - format!( + proc_macro2::Term::intern( + &format!( "{}_{}", parent_name, - variant_name + variant_name.as_str() ) ) }; add_constant( 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); } } } let item = builder.build(ctx, enum_rust_ty, result); result.push(item); } } @@ -2941,20 +2944,19 @@ impl TryToRustTy for Type { } TypeKind::Array(item, len) => { let ty = item.try_to_rust_ty(ctx, &())?; Ok(quote! { [ #ty ; #len ] }) } 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 = proc_macro2::Term::intern(&path.join("::")); + Ok(quote!(#path)) } TypeKind::TemplateInstantiation(ref inst) => { inst.try_to_rust_ty(ctx, item) } TypeKind::ResolvedTypeRef(inner) => inner.try_to_rust_ty(ctx, &()), TypeKind::TemplateAlias(..) | TypeKind::Alias(..) => { let template_params = item.used_template_params(ctx) @@ -3066,17 +3068,17 @@ impl TryToRustTy for TemplateInstantiati let def = self.template_definition() .into_resolver() .through_type_refs() .resolve(ctx); 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)), proc_macro2::Term::intern("::")); let def_params = match def.self_template_params(ctx) { Some(params) => params, None => { // This can happen if we generated an opaque type for a partial // template specialization, and we've hit an instantiation of // that partial specialization. extra_assert!( @@ -3240,26 +3242,20 @@ impl CodeGenerator for Function { canonical_name, self ); } abi => abi, }; let ident = ctx.rust_ident(canonical_name); - let mut tokens = quote! { extern #abi }; - tokens.append("{\n"); - if !attributes.is_empty() { - tokens.append_separated(attributes, "\n"); - tokens.append("\n"); - } - tokens.append(quote! { + let tokens = quote!( extern #abi { + #(#attributes)* pub fn #ident ( #( #args ),* ) #ret; }); - tokens.append("\n}"); result.push(tokens); } } fn objc_method_codegen( ctx: &BindgenContext, method: &ObjCMethod, @@ -3285,17 +3281,17 @@ fn objc_method_codegen( }; let methods_and_args = method.format_method_call(&fn_args); let body = if method.is_class_method() { 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) } } else { quote! { msg_send!(self, #methods_and_args) } }; @@ -3411,21 +3407,22 @@ pub(crate) fn codegen(context: BindgenCo mod utils { use super::{ToRustTyOrOpaque, error}; use ir::context::BindgenContext; use ir::function::FunctionSig; use ir::item::{Item, ItemCanonicalPath}; use ir::ty::TypeKind; use quote; + use proc_macro2; 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 = proc_macro2::Term::intern(include_str!("./bitfield_unit.rs")); + let bitfield_unit_type = quote!(#bitfield_unit_type); let items = vec![bitfield_unit_type]; let old_items = mem::replace(result, items); result.extend(old_items); } pub fn prepend_objc_header( ctx: &BindgenContext, @@ -3641,20 +3638,21 @@ mod utils { let old_items = mem::replace(result, items); result.extend(old_items.into_iter()); } pub fn build_path( item: &Item, ctx: &BindgenContext, ) -> error::Result { + use proc_macro2; let path = item.namespace_aware_canonical_path(ctx); - - let mut tokens = quote! {}; - tokens.append_separated(path.into_iter().map(quote::Ident::new), "::"); + let path = proc_macro2::Term::intern(&path.join("::")); + let tokens = quote! {#path}; + //tokens.append_separated(path, "::"); Ok(tokens) } fn primitive_ty(ctx: &BindgenContext, name: &str) -> quote::Tokens { let ident = ctx.rust_ident_raw(name); quote! { #ident diff --git a/third_party/rust/bindgen/src/codegen/struct_layout.rs b/third_party/rust/bindgen/src/codegen/struct_layout.rs --- a/third_party/rust/bindgen/src/codegen/struct_layout.rs +++ b/third_party/rust/bindgen/src/codegen/struct_layout.rs @@ -2,16 +2,17 @@ use super::helpers; use ir::comp::CompInfo; use ir::context::BindgenContext; use ir::layout::Layout; use ir::ty::{Type, TypeKind}; use quote; +use proc_macro2; use std::cmp; use std::mem; /// Trace the layout of struct. #[derive(Debug)] pub struct StructLayoutTracker<'a> { name: &'a str, ctx: &'a BindgenContext, @@ -301,17 +302,17 @@ impl<'a> StructLayoutTracker<'a> { } fn padding_field(&mut self, layout: Layout) -> quote::Tokens { let ty = helpers::blob(layout); let padding_count = self.padding_count; self.padding_count += 1; - let padding_field_name = quote::Ident::new(format!("__bindgen_padding_{}", padding_count)); + let padding_field_name = proc_macro2::Term::intern(&format!("__bindgen_padding_{}", padding_count)); self.max_field_align = cmp::max(self.max_field_align, layout.align); quote! { pub #padding_field_name : #ty , } } diff --git a/third_party/rust/bindgen/src/ir/context.rs b/third_party/rust/bindgen/src/ir/context.rs --- a/third_party/rust/bindgen/src/ir/context.rs +++ b/third_party/rust/bindgen/src/ir/context.rs @@ -19,17 +19,17 @@ use super::ty::{FloatKind, Type, TypeKin use super::function::Function; use super::super::time::Timer; use BindgenOptions; use callbacks::ParseCallbacks; use cexpr; use clang::{self, Cursor}; use clang_sys; use parse::ClangItemParser; -use quote; +use proc_macro2; use std::borrow::Cow; use std::cell::Cell; use std::collections::{HashMap, HashSet, hash_map}; use std::collections::btree_map::{self, BTreeMap}; use std::iter::IntoIterator; use std::mem; /// An identifier for some kind of IR item. @@ -876,29 +876,29 @@ impl BindgenContext { s = s.replace("$", "_"); s.push_str("_"); return Cow::Owned(s); } Cow::Borrowed(name) } /// Returns a mangled name as a rust identifier. - pub fn rust_ident(&self, name: S) -> quote::Ident + pub fn rust_ident(&self, name: S) -> proc_macro2::Term where S: AsRef { self.rust_ident_raw(self.rust_mangle(name.as_ref())) } /// 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) -> proc_macro2::Term where - T: Into + T: AsRef { - name.into() + proc_macro2::Term::intern(name.as_ref()) } /// Iterate over all items that have been defined. pub fn items<'a>(&'a self) -> btree_map::Iter<'a, ItemId, Item> { self.items.iter() } /// Have we collected all unresolved type references yet? @@ -2316,17 +2316,17 @@ impl BindgenContext { }; self.whitelisted = Some(whitelisted); self.codegen_items = Some(codegen_items); } /// 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) -> proc_macro2::Term { if self.options().use_core { self.rust_ident_raw("core") } else { self.rust_ident_raw("std") } } /// Call if a binden complex is generated diff --git a/third_party/rust/bindgen/src/ir/function.rs b/third_party/rust/bindgen/src/ir/function.rs --- a/third_party/rust/bindgen/src/ir/function.rs +++ b/third_party/rust/bindgen/src/ir/function.rs @@ -188,17 +188,17 @@ impl Abi { Abi::Unknown(..) => true, _ => false, } } } 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" }, Abi::ThisCall => quote! { "thiscall" }, Abi::Aapcs => quote! { "aapcs" }, Abi::Win64 => quote! { "win64" }, Abi::Unknown(cc) => panic!( "Cannot turn unknown calling convention to tokens: {:?}", diff --git a/third_party/rust/bindgen/src/ir/objc.rs b/third_party/rust/bindgen/src/ir/objc.rs --- a/third_party/rust/bindgen/src/ir/objc.rs +++ b/third_party/rust/bindgen/src/ir/objc.rs @@ -8,16 +8,17 @@ use clang; use clang_sys::CXChildVisit_Continue; use clang_sys::CXCursor_ObjCCategoryDecl; use clang_sys::CXCursor_ObjCClassMethodDecl; use clang_sys::CXCursor_ObjCClassRef; use clang_sys::CXCursor_ObjCInstanceMethodDecl; use clang_sys::CXCursor_ObjCProtocolDecl; use clang_sys::CXCursor_ObjCProtocolRef; use quote; +use proc_macro2; /// Objective C interface as used in TypeKind /// /// Also protocols and categories are parsed as this type #[derive(Debug)] pub struct ObjCInterface { /// The name /// like, NSObject @@ -211,17 +212,17 @@ impl ObjCMethod { self.is_class_method } /// Formats the method call pub fn format_method_call(&self, args: &[quote::Tokens]) -> quote::Tokens { let split_name: Vec<_> = self.name .split(':') .filter(|p| !p.is_empty()) - .map(quote::Ident::new) + .map(proc_macro2::Term::intern) .collect(); // No arguments if args.len() == 0 && split_name.len() == 1 { let name = &split_name[0]; return quote! { #name }; @@ -234,19 +235,20 @@ impl ObjCMethod { args, split_name ); } // 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(proc_macro2::Term::intern(name)) }; let args = split_name .into_iter() .zip(args_without_types) .map(|(arg, arg_val)| quote! { #arg : #arg_val }); quote! { diff --git a/third_party/rust/bindgen/src/lib.rs b/third_party/rust/bindgen/src/lib.rs --- a/third_party/rust/bindgen/src/lib.rs +++ b/third_party/rust/bindgen/src/lib.rs @@ -18,16 +18,17 @@ extern crate cexpr; #[allow(unused_extern_crates)] extern crate cfg_if; extern crate clang_sys; #[macro_use] extern crate lazy_static; extern crate peeking_take_while; #[macro_use] extern crate quote; +extern crate proc_macro2; extern crate regex; extern crate which; #[cfg(feature = "logging")] #[macro_use] extern crate log; #[cfg(not(feature = "logging"))] @@ -1073,16 +1074,22 @@ impl Builder { /// Set the absolute path to the rustfmt configuration file, if None, the standard rustfmt /// options are used. pub fn rustfmt_configuration_file(mut self, path: Option) -> Self { self = self.rustfmt_bindings(true); self.options.rustfmt_configuration_file = path; self } + /// Sets an explicit path to rustfmt, to be used when rustfmt is enabled. + pub fn with_rustfmt>(mut self, path: P) -> Self { + self.options.rustfmt_path = Some(path.into()); + self + } + /// Generate the Rust bindings using the options built up thus far. pub fn generate(mut self) -> Result { self.options.input_header = self.input_headers.pop(); self.options.clang_args.extend( self.input_headers .drain(..) .flat_map(|header| { iter::once("-include".into()).chain(iter::once(header)) @@ -1210,16 +1217,19 @@ struct BindgenOptions { /// The set of types that have been blacklisted and should not appear /// anywhere in the generated code. blacklisted_types: RegexSet, /// The set of types that should be treated as opaque structures in the /// generated code. opaque_types: RegexSet, + /// The explicit rustfmt path. + rustfmt_path: Option, + /// The set of types that we should have bindings for in the generated /// code. /// /// This includes all types transitively reachable from any type in this /// set. One might think of whitelisted types/vars/functions as GC roots, /// and the generated Rust code as including everything that gets marked. whitelisted_types: RegexSet, @@ -1435,16 +1445,17 @@ impl Default for BindgenOptions { fn default() -> BindgenOptions { let rust_target = RustTarget::default(); BindgenOptions { rust_target: rust_target, rust_features: rust_target.into(), blacklisted_types: Default::default(), opaque_types: Default::default(), + rustfmt_path: Default::default(), whitelisted_types: Default::default(), whitelisted_functions: Default::default(), whitelisted_vars: Default::default(), bitfield_enums: Default::default(), rustified_enums: Default::default(), constified_enum_modules: Default::default(), builtins: false, links: vec![], @@ -1677,25 +1688,25 @@ impl Bindings { writer.write(line.as_bytes())?; writer.write("\n".as_bytes())?; } if !self.options.raw_lines.is_empty() { 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) => { writer.write(rustfmt_bindings.as_bytes())?; }, Err(err) => { eprintln!("{:?}", err); - writer.write(bindings.as_str().as_bytes())?; + writer.write(bindings.as_bytes())?; }, } Ok(()) } /// Checks if rustfmt_bindings is set and runs rustfmt on the string fn rustfmt_generated_string<'a>( &self, @@ -1703,20 +1714,29 @@ impl Bindings { ) -> io::Result> { let _t = time::Timer::new("rustfmt_generated_string") .with_output(self.options.time_phases); if !self.options.rustfmt_bindings { return Ok(Cow::Borrowed(source)); } - let rustfmt = which::which("rustfmt") - .map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_owned()))?; + let rustfmt = match self.options.rustfmt_path { + Some(ref p) => Cow::Borrowed(p), + None => { + let path = which::which("rustfmt") + .map_err(|e| { + io::Error::new(io::ErrorKind::Other, e.to_owned()) + })?; - let mut cmd = Command::new(rustfmt); + Cow::Owned(path) + } + }; + + let mut cmd = Command::new(&*rustfmt); cmd .stdin(Stdio::piped()) .stdout(Stdio::piped()); if let Some(path) = self.options .rustfmt_configuration_file .as_ref() diff --git a/third_party/rust/proc-macro2/.cargo-checksum.json b/third_party/rust/proc-macro2/.cargo-checksum.json --- a/third_party/rust/proc-macro2/.cargo-checksum.json +++ b/third_party/rust/proc-macro2/.cargo-checksum.json @@ -1,1 +1,1 @@ -{"files":{"Cargo.toml":"0b700f1e7b8ba76ce4678d36b6906d38455e88f51085ea9f120d6ca63f13d5d7","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"adf2e822923878c2ebf4a0a782898c598fc6f57a3af905b85d57fc716c836687","src/lib.rs":"fbae25504264b185d877fb8784d4d88333ea34a7cbeddca3277dc8421f179933","src/macros.rs":"414505e520b8d705b4ce5a64ec2e82d6d1af0b88567454169486a668fbc1e9c8","src/stable.rs":"6363c4c0ef989c2ec81aa75be71c69a103d45a1de439f3f3bcb6806d8a78a172","src/strnom.rs":"1baded8543a9930798fb16092fe51e9074591902e327e0f94eb1c908a6370de9","src/unstable.rs":"110d27103e37427b3d1dcb45b6ba9dc9f5641a255766a43d5db0f4fd10a341ed","tests/test.rs":"9e75d5289abc1dc58c1df00ae051d8c3cd2c0d7830cca5ad689007c05acffe26"},"package":"d1cb7aaaa4bf022ec2b14ff2f2ba1643a22f3cee88df014a85e14b392282c61d"} \ No newline at end of file +{"files":{"Cargo.toml":"7f7d39bd76cae6c2b2cfc69755a967dc3a19e927234c9e163c134f9c11722634","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"adf2e822923878c2ebf4a0a782898c598fc6f57a3af905b85d57fc716c836687","src/lib.rs":"4d3ab4306ea77ba7c2abe1ba8fc635af8708f25b2481383435db1e45f7a50fa8","src/macros.rs":"414505e520b8d705b4ce5a64ec2e82d6d1af0b88567454169486a668fbc1e9c8","src/stable.rs":"0df1eddeaa481eec6f268bec11bff047c7000084517527045df8656c22fa8ff2","src/strnom.rs":"6e6973a4b17ba764e10129789f07f106c7e790333f112855b9a9948b4b4de436","src/unstable.rs":"110d27103e37427b3d1dcb45b6ba9dc9f5641a255766a43d5db0f4fd10a341ed","tests/test.rs":"5d1c7c5a7f55264d814548c330cb56ba7735852982bf73495b7aa38358f7589e"},"package":"cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0"} \ No newline at end of file diff --git a/third_party/rust/proc-macro2/Cargo.toml b/third_party/rust/proc-macro2/Cargo.toml --- a/third_party/rust/proc-macro2/Cargo.toml +++ b/third_party/rust/proc-macro2/Cargo.toml @@ -7,25 +7,27 @@ # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "proc-macro2" -version = "0.2.2" +version = "0.2.3" authors = ["Alex Crichton "] description = "A stable implementation of the upcoming new `proc_macro` API. Comes with an\noption, off by default, to also reimplement itself in terms of the upstream\nunstable API.\n" homepage = "https://github.com/alexcrichton/proc-macro2" documentation = "https://docs.rs/proc-macro2" readme = "README.md" keywords = ["macros"] license = "MIT/Apache-2.0" repository = "https://github.com/alexcrichton/proc-macro2" [lib] doctest = false [dependencies.unicode-xid] version = "0.1" [features] -nightly = [] +default = ["proc-macro"] +nightly = ["proc-macro"] +proc-macro = [] diff --git a/third_party/rust/proc-macro2/src/lib.rs b/third_party/rust/proc-macro2/src/lib.rs --- a/third_party/rust/proc-macro2/src/lib.rs +++ b/third_party/rust/proc-macro2/src/lib.rs @@ -1,34 +1,39 @@ -//! A "shim crate" intended to multiplex the `proc_macro` API on to stable Rust. +//! A "shim crate" intended to multiplex the [`proc_macro`] API on to stable +//! Rust. //! //! Procedural macros in Rust operate over the upstream -//! `proc_macro::TokenStream` type. This type currently is quite conservative -//! and exposed no internal implementation details. Nightly compilers, however, -//! contain a much richer interface. This richer interface allows fine-grained -//! inspection of the token stream which avoids stringification/re-lexing and -//! also preserves span information. +//! [`proc_macro::TokenStream`][ts] type. This type currently is quite +//! conservative and exposed no internal implementation details. Nightly +//! compilers, however, contain a much richer interface. This richer interface +//! allows fine-grained inspection of the token stream which avoids +//! stringification/re-lexing and also preserves span information. //! -//! The upcoming APIs added to `proc_macro` upstream are the foundation for +//! The upcoming APIs added to [`proc_macro`] upstream are the foundation for //! productive procedural macros in the ecosystem. To help prepare the ecosystem //! for using them this crate serves to both compile on stable and nightly and //! mirrors the API-to-be. The intention is that procedural macros which switch //! to use this crate will be trivially able to switch to the upstream //! `proc_macro` crate once its API stabilizes. //! //! In the meantime this crate also has a `nightly` Cargo feature which -//! enables it to reimplement itself with the unstable API of `proc_macro`. +//! enables it to reimplement itself with the unstable API of [`proc_macro`]. //! This'll allow immediate usage of the beneficial upstream API, particularly //! around preserving span information. +//! +//! [`proc_macro`]: https://doc.rust-lang.org/proc_macro/ +//! [ts]: https://doc.rust-lang.org/proc_macro/struct.TokenStream.html // Proc-macro2 types in rustdoc of other crates get linked to here. -#![doc(html_root_url = "https://docs.rs/proc-macro2/0.2.2")] +#![doc(html_root_url = "https://docs.rs/proc-macro2/0.2.3")] #![cfg_attr(feature = "nightly", feature(proc_macro))] +#[cfg(feature = "proc-macro")] extern crate proc_macro; #[cfg(not(feature = "nightly"))] extern crate unicode_xid; use std::fmt; use std::str::FromStr; use std::iter::FromIterator; @@ -58,22 +63,24 @@ impl FromStr for TokenStream { fn from_str(src: &str) -> Result { match src.parse() { Ok(e) => Ok(TokenStream(e)), Err(e) => Err(LexError(e)), } } } +#[cfg(feature = "proc-macro")] impl From for TokenStream { fn from(inner: proc_macro::TokenStream) -> TokenStream { TokenStream(inner.into()) } } +#[cfg(feature = "proc-macro")] impl From for proc_macro::TokenStream { fn from(inner: TokenStream) -> proc_macro::TokenStream { inner.0.into() } } impl From for TokenStream { fn from(tree: TokenTree) -> TokenStream { @@ -166,17 +173,17 @@ impl Span { /// Creates a new span with the same name resolution behavior as `self` but /// with the line/column information of `other`. pub fn located_at(&self, other: Span) -> Span { Span(self.0.located_at(other.0)) } /// This method is only available when the `"nightly"` feature is enabled. - #[cfg(feature = "nightly")] + #[cfg(all(feature = "nightly", feature = "proc-macro"))] pub fn unstable(self) -> proc_macro::Span { self.0.unstable() } #[cfg(procmacro2_semver_exempt)] pub fn source_file(&self) -> SourceFile { SourceFile(self.0.source_file()) } diff --git a/third_party/rust/proc-macro2/src/stable.rs b/third_party/rust/proc-macro2/src/stable.rs --- a/third_party/rust/proc-macro2/src/stable.rs +++ b/third_party/rust/proc-macro2/src/stable.rs @@ -6,17 +6,16 @@ use std::cmp; use std::collections::HashMap; use std::fmt; use std::iter; use std::marker::PhantomData; use std::rc::Rc; use std::str::FromStr; use std::vec; -use proc_macro; use unicode_xid::UnicodeXID; use strnom::{Cursor, PResult, skip_whitespace, block_comment, whitespace, word_break}; use {TokenTree, TokenNode, Delimiter, Spacing}; #[derive(Clone, Debug)] pub struct TokenStream { inner: Vec, @@ -115,24 +114,26 @@ impl fmt::Display for TokenStream { } } } Ok(()) } } -impl From for TokenStream { - fn from(inner: proc_macro::TokenStream) -> TokenStream { +#[cfg(feature = "proc-macro")] +impl From<::proc_macro::TokenStream> for TokenStream { + fn from(inner: ::proc_macro::TokenStream) -> TokenStream { inner.to_string().parse().expect("compiler token stream parse failed") } } -impl From for proc_macro::TokenStream { - fn from(inner: TokenStream) -> proc_macro::TokenStream { +#[cfg(feature = "proc-macro")] +impl From for ::proc_macro::TokenStream { + fn from(inner: TokenStream) -> ::proc_macro::TokenStream { inner.to_string().parse().expect("failed to parse to compiler tokens") } } impl From for TokenStream { fn from(tree: TokenTree) -> TokenStream { TokenStream { inner: vec![tree] } @@ -1174,31 +1175,31 @@ fn op_char(input: Cursor) -> PResult (), alt!( do_parse!( punct!("//!") >> - take_until!("\n") >> + take_until_newline_or_eof!() >> (()) ) | do_parse!( option!(whitespace) >> peek!(tag!("/*!")) >> block_comment >> (()) ) | do_parse!( punct!("///") >> not!(tag!("/")) >> - take_until!("\n") >> + take_until_newline_or_eof!() >> (()) ) | do_parse!( option!(whitespace) >> peek!(tuple!(tag!("/**"), not!(tag!("*")))) >> block_comment >> (()) diff --git a/third_party/rust/proc-macro2/src/strnom.rs b/third_party/rust/proc-macro2/src/strnom.rs --- a/third_party/rust/proc-macro2/src/strnom.rs +++ b/third_party/rust/proc-macro2/src/strnom.rs @@ -258,44 +258,24 @@ macro_rules! option { ($i:expr, $f:expr) => { match $f($i) { Ok((i, o)) => Ok((i, Some(o))), Err(LexError) => Ok(($i, None)), } }; } -macro_rules! take_until { - ($i:expr, $substr:expr) => {{ - if $substr.len() > $i.len() { - Err(LexError) +macro_rules! take_until_newline_or_eof { + ($i:expr,) => {{ + if $i.len() == 0 { + Ok(($i, "")) } else { - let substr_vec: Vec = $substr.chars().collect(); - let mut window: Vec = vec![]; - let mut offset = $i.len(); - let mut parsed = false; - for (o, c) in $i.char_indices() { - window.push(c); - if window.len() > substr_vec.len() { - window.remove(0); - } - if window == substr_vec { - parsed = true; - window.pop(); - let window_len: usize = window.iter() - .map(|x| x.len_utf8()) - .fold(0, |x, y| x + y); - offset = o - window_len; - break; - } - } - if parsed { - Ok(($i.advance(offset), &$i.rest[..offset])) - } else { - Err(LexError) + match $i.find('\n') { + Some(i) => Ok(($i.advance(i), &$i.rest[..i])), + None => Ok(($i.advance($i.len()), "")) } } }}; } macro_rules! tuple { ($i:expr, $($rest:tt)*) => { tuple_parser!($i, (), $($rest)*) diff --git a/third_party/rust/proc-macro2/tests/test.rs b/third_party/rust/proc-macro2/tests/test.rs --- a/third_party/rust/proc-macro2/tests/test.rs +++ b/third_party/rust/proc-macro2/tests/test.rs @@ -170,10 +170,18 @@ fn no_panic() { assert!(s.parse::().is_err()); } #[test] fn tricky_doc_commaent() { let stream = "/**/".parse::().unwrap(); let tokens = stream.into_iter().collect::>(); assert!(tokens.is_empty(), "not empty -- {:?}", tokens); + + let stream = "/// doc".parse::().unwrap(); + let tokens = stream.into_iter().collect::>(); + assert!(tokens.len() == 1, "not length 1 -- {:?}", tokens); + match tokens[0].kind { + proc_macro2::TokenNode::Literal(_) => {} + _ => panic!("wrong token {:?}", tokens[0]), + } }