Merge pull request #1256 from fitzgen/fix-missing-dylibs. r=emilio

Fix missing dylibs
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bbce20a..637b26f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,25 +9,38 @@
   - [Removed](#removed)
   - [Fixed](#fixed)
   - [Security](#security)
-- [0.32.0](#0320)
+- [0.33.1](#0331)
+  - [Fixed](#fixed-1)
+- [0.33.0](#0330)
   - [Added](#added-1)
   - [Changed](#changed-1)
-  - [Fixed](#fixed-1)
-- [0.31.0](#0310)
-  - [Added](#added-2)
-  - [Changed](#changed-2)
   - [Deprecated](#deprecated-1)
   - [Removed](#removed-1)
   - [Fixed](#fixed-2)
-- [0.30.0](#0300)
+  - [Security](#security-1)
+- [0.32.2](#0322)
+  - [Fixed](#fixed-3)
+- [0.32.1](#0321)
+  - [Fixed](#fixed-4)
+- [0.32.0](#0320)
+  - [Added](#added-2)
+  - [Changed](#changed-2)
+  - [Fixed](#fixed-5)
+- [0.31.0](#0310)
   - [Added](#added-3)
   - [Changed](#changed-3)
   - [Deprecated](#deprecated-2)
-  - [Fixed](#fixed-3)
-- [0.29.0](#0290)
+  - [Removed](#removed-2)
+  - [Fixed](#fixed-6)
+- [0.30.0](#0300)
   - [Added](#added-4)
   - [Changed](#changed-4)
-  - [Fixed](#fixed-4)
+  - [Deprecated](#deprecated-3)
+  - [Fixed](#fixed-7)
+- [0.29.0](#0290)
+  - [Added](#added-5)
+  - [Changed](#changed-5)
+  - [Fixed](#fixed-8)
 
 <!-- END doctoc generated TOC please keep comment here to allow auto update -->
 
@@ -63,6 +76,51 @@
 
 --------------------------------------------------------------------------------
 
+# 0.33.1
+
+Released 2018/02/14
+
+## Fixed
+
+* Reverted the dependency update to `quote = "0.4"` and addition of the
+  `proc_macro2` dependency. The `proc_macro2` crate depends on `rustc` internal
+  libraries, which means that CLIs which use it must be run under `rustup`,
+  which is not acceptable for `bindgen`. [#1248][]
+
+[#1248]: https://github.com/rust-lang-nursery/rust-bindgen/issues/1248
+
+--------------------------------------------------------------------------------
+
+# 0.33.0
+
+Released YYYY/MM/DD
+
+## Added
+
+* TODO (or remove section if none)
+
+## Changed
+
+* TODO (or remove section if none)
+
+## Deprecated
+
+* TODO (or remove section if none)
+
+## Removed
+
+* TODO (or remove section if none)
+
+## Fixed
+
+* TODO (or remove section if none)
+
+## Security
+
+* TODO (or remove section if none)
+
+--------------------------------------------------------------------------------
+
 # 0.32.2
 
 Released 2018/01/22
diff --git a/Cargo.lock b/Cargo.lock
index e4f4ad5..637bc3e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -23,7 +23,7 @@
 
 [[package]]
 name = "bindgen"
-version = "0.33.0"
+version = "0.33.1"
 dependencies = [
  "cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -34,8 +34,7 @@
  "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)",
- "proc-macro2 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 0.3.15 (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)",
@@ -203,20 +202,9 @@
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
-name = "proc-macro2"
-version = "0.2.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.4.2"
+version = "0.3.15"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "proc-macro2 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
-]
 
 [[package]]
 name = "redox_syscall"
@@ -307,11 +295,6 @@
 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"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -404,8 +387,7 @@
 "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 proc-macro2 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d1cb7aaaa4bf022ec2b14ff2f2ba1643a22f3cee88df014a85e14b392282c61d"
-"checksum quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1eca14c727ad12702eb4b6bfb5a232287dcf8385cb8ca83a3eeaf6519c44c408"
+"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
 "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"
@@ -418,7 +400,6 @@
 "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 c3a0582..630f197 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
 readme = "README.md"
 repository = "https://github.com/rust-lang-nursery/rust-bindgen"
 documentation = "https://docs.rs/bindgen"
-version = "0.33.0"
+version = "0.33.1"
 build = "build.rs"
 
 include = [
@@ -47,10 +47,9 @@
 clang-sys = { version = "0.21.0", features = ["runtime", "clang_3_9"] }
 lazy_static = "1"
 peeking_take_while = "0.1.2"
-quote = "0.4"
+quote = "0.3.15"
 regex = "0.2"
 which = "1.0.2"
-proc-macro2 = "0.2"
 
 [dependencies.env_logger]
 optional = true
diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs
index ca93b51..9905430 100644
--- a/src/codegen/helpers.rs
+++ b/src/codegen/helpers.rs
@@ -3,29 +3,27 @@
 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 = proc_macro2::Term::intern(which);
+        let which = quote::Ident::new(which);
         quote! {
             #[repr( #which )]
         }
     }
 
     pub fn repr_list(which_ones: &[&str]) -> quote::Tokens {
-        let which_ones = which_ones.iter().cloned().map(proc_macro2::Term::intern);
+        let which_ones = which_ones.iter().cloned().map(quote::Ident::new);
         quote! {
             #[repr( #( #which_ones ),* )]
         }
     }
 
     pub fn derives(which_ones: &[&str]) -> quote::Tokens {
-        let which_ones = which_ones.iter().cloned().map(proc_macro2::Term::intern);
+        let which_ones = which_ones.iter().cloned().map(quote::Ident::new);
         quote! {
             #[derive( #( #which_ones ),* )]
         }
@@ -41,8 +39,11 @@
         // 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 comment = proc_macro2::Literal::doccomment(&comment);
-        quote! {#comment}
+        let mut tokens = quote! {};
+        tokens.append("\n");
+        tokens.append(comment);
+        tokens.append("\n");
+        tokens
     }
 
     pub fn link_name(name: &str) -> quote::Tokens {
@@ -72,7 +73,7 @@
         }
     };
 
-    let ty_name = proc_macro2::Term::intern(ty_name);
+    let ty_name = quote::Ident::new(ty_name);
 
     let data_len = opaque.array_size().unwrap_or(layout.size);
 
@@ -102,7 +103,7 @@
     let mut tokens = quote! {};
 
     if ctx.options().enable_cxx_namespaces {
-        tokens.append_all(quote! { root:: });
+        tokens.append(quote! { root:: });
     }
 
     let align = match layout.align {
@@ -113,7 +114,7 @@
     };
 
     let size = layout.size;
-    tokens.append_all(quote! {
+    tokens.append(quote! {
         __BindgenBitfieldUnit<[u8; #size], #align>
     });
 
@@ -125,7 +126,6 @@
     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,25 +166,29 @@
 
     pub fn int_expr(val: i64) -> quote::Tokens {
         // Don't use quote! { #val } because that adds the type suffix.
-        let val = proc_macro2::Literal::integer(val);
-        quote!(#val)
+        let mut tokens = quote! {};
+        tokens.append(val.to_string());
+        tokens
     }
 
     pub fn uint_expr(val: u64) -> quote::Tokens {
         // Don't use quote! { #val } because that adds the type suffix.
-        let val = proc_macro2::Term::intern(&val.to_string());
-        quote!(#val)
+        let mut tokens = quote! {};
+        tokens.append(val.to_string());
+        tokens
     }
 
     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 = proc_macro2::Literal::byte_string(&string.as_bytes());
+        let b = quote::ByteStr(&string);
         quote! {
             #b
         }
@@ -195,9 +199,16 @@
         f: f64,
     ) -> Result<quote::Tokens, ()> {
         if f.is_finite() {
-            let val = proc_macro2::Literal::float(f);
+            let mut string = f.to_string();
 
-            return Ok(quote!(#val));
+            // 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);
         }
 
         let prefix = ctx.trait_prefix();
diff --git a/src/codegen/impl_partialeq.rs b/src/codegen/impl_partialeq.rs
index 155f874..0278380 100644
--- a/src/codegen/impl_partialeq.rs
+++ b/src/codegen/impl_partialeq.rs
@@ -4,7 +4,6 @@
 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.
@@ -72,7 +71,7 @@
 }
 
 fn gen_field(ctx: &BindgenContext, ty_item: &Item, name: &str) -> quote::Tokens {
-    fn quote_equals(name_ident: proc_macro2::Term) -> quote::Tokens {
+    fn quote_equals(name_ident: quote::Ident) -> quote::Tokens {
         quote! { self.#name_ident == other.#name_ident }
     }
 
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 493a1ce..b21c0dc 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -38,7 +38,6 @@
 use ir::var::Var;
 
 use quote;
-use proc_macro2;
 
 use std::borrow::Cow;
 use std::cell::Cell;
@@ -76,7 +75,7 @@
 
 
     let mut tokens = quote! {};
-    tokens.append_separated(path, proc_macro2::Term::intern("::"));
+    tokens.append_separated(path, "::");
 
     quote! {
         #[allow(unused_imports)]
@@ -310,7 +309,7 @@
                     .expect("template params cannot fail to be a rust type")
             });
 
-            self.append_all(quote! {
+            self.append(quote! {
                 < #( #params ),* >
             });
         }
@@ -692,7 +691,7 @@
 
                 // We prefer using `pub use` over `pub type` because of:
                 // https://github.com/rust-lang/rust/issues/26264
-                if inner_rust_type.to_string()
+                if inner_rust_type.as_str()
                     .chars()
                     .all(|c| match c {
                         // These are the only characters allowed in simple
@@ -703,19 +702,19 @@
                     outer_params.is_none() &&
                     inner_item.expect_type().canonical_type(ctx).is_enum()
                 {
-                    tokens.append_all(quote! {
+                    tokens.append(quote! {
                         pub use
                     });
                     let path = top_level_path(ctx, item);
-                    tokens.append_separated(path, proc_macro2::Term::intern("::"));
-                    tokens.append_all(quote! {
+                    tokens.append_separated(path, "::");
+                    tokens.append(quote! {
                         :: #inner_rust_type  as #rust_name ;
                     });
                     result.push(tokens);
                     return;
                 }
 
-                tokens.append_all(quote! {
+                tokens.append(quote! {
                     pub type #rust_name
                 });
 
@@ -738,12 +737,12 @@
                                 .expect("type parameters can always convert to rust ty OK")
                         });
 
-                    tokens.append_all(quote! {
+                    tokens.append(quote! {
                         < #( #params ),* >
                     });
                 }
 
-                tokens.append_all(quote! {
+                tokens.append(quote! {
                     = #inner_rust_type ;
                 });
 
@@ -1060,11 +1059,11 @@
             self.annotations().accessor_kind().unwrap_or(accessor_kind);
 
         if is_private {
-            field.append_all(quote! {
+            field.append(quote! {
                 #field_ident : #ty ,
             });
         } else {
-            field.append_all(quote! {
+            field.append(quote! {
                 pub #field_ident : #ty ,
             });
         }
@@ -1124,7 +1123,7 @@
 impl BitfieldUnit {
     /// Get the constructor name for this bitfield unit.
     fn ctor_name(&self) -> quote::Tokens {
-        let ctor_name = proc_macro2::Term::intern(&format!("new_bitfield_{}", self.nth()));
+        let ctor_name = quote::Ident::new(format!("new_bitfield_{}", self.nth()));
         quote! {
             #ctor_name
         }
@@ -1155,7 +1154,7 @@
         let width = self.width() as u8;
         let prefix = ctx.trait_prefix();
 
-        ctor_impl.append_all(quote! {
+        ctor_impl.append(quote! {
             __bindgen_bitfield_unit.set(
                 #offset,
                 #width,
@@ -1323,7 +1322,7 @@
         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 = proc_macro2::Term::intern(unit_field_name);
+        let unit_field_ident = quote::Ident::new(unit_field_name);
 
         let bitfield_ty_item = ctx.resolve_item(self.ty());
         let bitfield_ty = bitfield_ty_item.expect_type();
@@ -1712,7 +1711,7 @@
             }
         };
 
-        tokens.append_all(quote! {
+        tokens.append(quote! {
             #generics {
                 #( #fields )*
             }
@@ -1735,7 +1734,7 @@
         if self.found_unknown_attr() {
             warn!(
                 "Type {} has an unkown attribute that may affect layout",
-                canonical_ident.as_str()
+                canonical_ident
             );
         }
 
@@ -1749,7 +1748,7 @@
             if ctx.options().layout_tests && !self.is_forward_declaration() {
                 if let Some(layout) = layout {
                     let fn_name =
-                        format!("bindgen_test_layout_{}", canonical_ident.as_str());
+                        format!("bindgen_test_layout_{}", canonical_ident);
                     let fn_name = ctx.rust_ident_raw(fn_name);
                     let prefix = ctx.trait_prefix();
                     let size_of_expr = quote! {
@@ -2131,7 +2130,7 @@
     Rust {
         codegen_depth: usize,
         attrs: Vec<quote::Tokens>,
-        ident: proc_macro2::Term,
+        ident: quote::Ident,
         tokens: quote::Tokens,
         emitted_any_variants: bool,
     },
@@ -2171,7 +2170,7 @@
         enum_variation: EnumVariation,
         enum_codegen_depth: usize,
     ) -> Self {
-        let ident = proc_macro2::Term::intern(name);
+        let ident = quote::Ident::new(name);
 
         match enum_variation {
             EnumVariation::Bitfield => {
@@ -2186,7 +2185,7 @@
             }
 
             EnumVariation::Rust => {
-                let tokens = quote!();
+                let tokens = quote!{};
                 EnumBuilder::Rust {
                     codegen_depth: enum_codegen_depth + 1,
                     attrs,
@@ -2209,7 +2208,7 @@
             }
 
             EnumVariation::ModuleConsts => {
-                let ident = proc_macro2::Term::intern(CONSTIFIED_ENUM_MODULE_REPR_NAME);
+                let ident = quote::Ident::new(CONSTIFIED_ENUM_MODULE_REPR_NAME);
                 let type_definition = quote! {
                     #( #attrs )*
                     pub type #ident = #repr;
@@ -2496,18 +2495,18 @@
             ctx: &BindgenContext,
             enum_: &Type,
             // Only to avoid recomputing every time.
-            enum_canonical_name: &proc_macro2::Term,
+            enum_canonical_name: &quote::Ident,
             // 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: &proc_macro2::Term,
+            referenced_name: &quote::Ident,
             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.as_str(), variant_name)
+                    format!("{}_{}", enum_canonical_name, variant_name)
                 } else {
                     variant_name.into()
                 }
@@ -2536,7 +2535,7 @@
         );
 
         // A map where we keep a value -> variant relation.
-        let mut seen_values = HashMap::<_, proc_macro2::Term>::new();
+        let mut seen_values = HashMap::<_, quote::Ident>::new();
         let enum_rust_ty = item.to_rust_ty_or_opaque(ctx, &());
         let is_toplevel = item.is_toplevel(ctx);
 
@@ -2634,11 +2633,11 @@
                             let parent_name =
                                 parent_canonical_name.as_ref().unwrap();
 
-                            proc_macro2::Term::intern(
-                                &format!(
+                            quote::Ident::new(
+                                format!(
                                     "{}_{}",
                                     parent_name,
-                                    variant_name.as_str()
+                                    variant_name
                                 )
                             )
                         };
@@ -2647,14 +2646,14 @@
                             ctx,
                             enum_ty,
                             &ident,
-                            mangled_name.as_str(),
+                            mangled_name.as_ref(),
                             &variant_name,
                             enum_rust_ty.clone(),
                             result,
                         );
                     }
 
-                    entry.insert(variant_name);
+                    entry.insert(quote::Ident::new(variant_name));
                 }
             }
         }
@@ -2982,9 +2981,10 @@
                 })
             }
             TypeKind::Enum(..) => {
+                let mut tokens = quote! {};
                 let path = item.namespace_aware_canonical_path(ctx);
-                let path = proc_macro2::Term::intern(&path.join("::"));
-                Ok(quote!(#path))
+                tokens.append_separated(path.into_iter().map(quote::Ident::new), "::");
+                Ok(tokens)
             }
             TypeKind::TemplateInstantiation(ref inst) => {
                 inst.try_to_rust_ty(ctx, item)
@@ -3106,7 +3106,7 @@
 
         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)), proc_macro2::Term::intern("::"));
+        ty.append_separated(def_path.into_iter().map(|p| ctx.rust_ident(p)), "::");
 
         let def_params = match def.self_template_params(ctx) {
             Some(params) => params,
@@ -3319,7 +3319,7 @@
         let class_name = class_name
             .expect("Generating a class method without class name?")
             .to_owned();
-        let expect_msg = proc_macro2::Literal::string(&format!("Couldn't find {}", class_name));
+        let expect_msg = format!("Couldn't find {}", class_name);
         quote! {
             msg_send!(objc::runtime::Class::get(#class_name).expect(#expect_msg), #methods_and_args)
         }
@@ -3445,12 +3445,11 @@
     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<quote::Tokens>) {
-        let bitfield_unit_type = proc_macro2::Term::intern(include_str!("./bitfield_unit.rs"));
-        let bitfield_unit_type = quote!(#bitfield_unit_type);
+        let mut bitfield_unit_type = quote! {};
+        bitfield_unit_type.append(include_str!("./bitfield_unit.rs"));
 
         let items = vec![bitfield_unit_type];
         let old_items = mem::replace(result, items);
@@ -3676,11 +3675,10 @@
         item: &Item,
         ctx: &BindgenContext,
     ) -> error::Result<quote::Tokens> {
-        use proc_macro2;
         let path = item.namespace_aware_canonical_path(ctx);
-        let path = proc_macro2::Term::intern(&path.join("::"));
-        let tokens = quote! {#path};
-        //tokens.append_separated(path, "::");
+
+        let mut tokens = quote! {};
+        tokens.append_separated(path.into_iter().map(quote::Ident::new), "::");
 
         Ok(tokens)
     }
diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs
index 92ba49f..32b4896 100644
--- a/src/codegen/struct_layout.rs
+++ b/src/codegen/struct_layout.rs
@@ -7,7 +7,6 @@
 use ir::layout::Layout;
 use ir::ty::{Type, TypeKind};
 use quote;
-use proc_macro2;
 use std::cmp;
 use std::mem;
 
@@ -307,7 +306,7 @@
 
         self.padding_count += 1;
 
-        let padding_field_name = proc_macro2::Term::intern(&format!("__bindgen_padding_{}", padding_count));
+        let padding_field_name = quote::Ident::new(format!("__bindgen_padding_{}", padding_count));
 
         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 21801c9..0a91452 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -24,7 +24,7 @@
 use clang::{self, Cursor};
 use clang_sys;
 use parse::ClangItemParser;
-use proc_macro2;
+use quote;
 use std::borrow::Cow;
 use std::cell::Cell;
 use std::collections::{HashMap, HashSet, hash_map};
@@ -880,7 +880,7 @@
     }
 
     /// Returns a mangled name as a rust identifier.
-    pub fn rust_ident<S>(&self, name: S) -> proc_macro2::Term
+    pub fn rust_ident<S>(&self, name: S) -> quote::Ident
     where
         S: AsRef<str>
     {
@@ -888,11 +888,11 @@
     }
 
     /// Returns a mangled name as a rust identifier.
-    pub fn rust_ident_raw<T>(&self, name: T) -> proc_macro2::Term
+    pub fn rust_ident_raw<T>(&self, name: T) -> quote::Ident
     where
-        T: AsRef<str>
+        T: Into<quote::Ident>
     {
-        proc_macro2::Term::intern(name.as_ref())
+        name.into()
     }
 
     /// Iterate over all items that have been defined.
@@ -2320,7 +2320,7 @@
 
     /// Convenient method for getting the prefix to use for most traits in
     /// codegen depending on the `use_core` option.
-    pub fn trait_prefix(&self) -> proc_macro2::Term {
+    pub fn trait_prefix(&self) -> quote::Ident {
         if self.options().use_core {
             self.rust_ident_raw("core")
         } else {
diff --git a/src/ir/function.rs b/src/ir/function.rs
index f027e47..481ab9f 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -193,7 +193,7 @@
 
 impl quote::ToTokens for Abi {
     fn to_tokens(&self, tokens: &mut quote::Tokens) {
-        tokens.append_all(match *self {
+        tokens.append(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 18b5197..0f72c39 100644
--- a/src/ir/objc.rs
+++ b/src/ir/objc.rs
@@ -13,7 +13,6 @@
 use clang_sys::CXCursor_ObjCProtocolDecl;
 use clang_sys::CXCursor_ObjCProtocolRef;
 use quote;
-use proc_macro2;
 
 /// Objective C interface as used in TypeKind
 ///
@@ -217,7 +216,7 @@
         let split_name: Vec<_> = self.name
             .split(':')
             .filter(|p| !p.is_empty())
-            .map(proc_macro2::Term::intern)
+            .map(quote::Ident::new)
             .collect();
 
         // No arguments
@@ -240,10 +239,9 @@
         // Get arguments without type signatures to pass to `msg_send!`
         let mut args_without_types = vec![];
         for arg in args.iter() {
-            let arg = arg.to_string();
-            let name_and_sig: Vec<&str> = arg.split(' ').collect();
+            let name_and_sig: Vec<&str> = arg.as_str().split(' ').collect();
             let name = name_and_sig[0];
-            args_without_types.push(proc_macro2::Term::intern(name))
+            args_without_types.push(quote::Ident::new(name))
         };
 
         let args = split_name
diff --git a/src/lib.rs b/src/lib.rs
index d4c6907..1cd64b2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -23,7 +23,6 @@
 extern crate peeking_take_while;
 #[macro_use]
 extern crate quote;
-extern crate proc_macro2;
 extern crate regex;
 extern crate which;
 
@@ -1697,7 +1696,7 @@
             writer.write("\n".as_bytes())?;
         }
 
-        let bindings = self.module.to_string();
+        let bindings = self.module.as_str().to_string();
 
         match self.rustfmt_generated_string(&bindings) {
             Ok(rustfmt_bindings) => {
@@ -1705,7 +1704,7 @@
             },
             Err(err) => {
                 eprintln!("{:?}", err);
-                writer.write(bindings.as_bytes())?;
+                writer.write(bindings.as_str().as_bytes())?;
             },
         }
         Ok(())
diff --git a/tests/expectations/tests/comment-indent.rs b/tests/expectations/tests/comment-indent.rs
index a7705d4..f00b023 100644
--- a/tests/expectations/tests/comment-indent.rs
+++ b/tests/expectations/tests/comment-indent.rs
@@ -1,7 +1,9 @@
 /* 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)]
@@ -109,6 +111,7 @@
                 concat!("Alignment of ", stringify!(InInlineNS))
             );
         }
+
         #[repr(C)]
         #[derive(Debug, Default, Copy, Clone)]
         pub struct Bazz {
diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs
index 3bce0ff..d105c58 100644
--- a/tests/expectations/tests/derive-bitfield-method-same-name.rs
+++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs
@@ -1,7 +1,9 @@
 /* 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<Storage, Align>
@@ -81,6 +83,7 @@
         }
     }
 }
+
 /// Because this struct have array larger than 32 items
 /// and --with-derive-partialeq --impl-partialeq --impl-debug is provided,
 /// this struct should manually implement `Debug` and `PartialEq`.
diff --git a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs
index 159dba7..096bc18 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 const k: EasyToOverflow = 2147483648;
 pub const k_expr: EasyToOverflow = 0;
 pub const BAZ: ::std::os::raw::c_longlong = 24;
-pub const fuzz: f64 = 51.0;
+pub const fuzz: f64 = 51.;
 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 045710f..51365df 100644
--- a/tests/expectations/tests/libclang-4/constant-evaluate.rs
+++ b/tests/expectations/tests/libclang-4/constant-evaluate.rs
@@ -14,7 +14,7 @@
 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.0;
+pub const fuzz: f64 = 51.;
 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 2c5a326..a10a1fc 100644
--- a/tests/expectations/tests/objc_class_method.rs
+++ b/tests/expectations/tests/objc_class_method.rs
@@ -1,5 +1,6 @@
 /* automatically generated by rust-bindgen */
 
+
 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
 #![cfg(target_os = "macos")]
 
@@ -22,31 +23,31 @@
 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
         )
     }
@@ -55,6 +56,6 @@
         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 158a044..f57951b 100644
--- a/tests/expectations/tests/objc_method_clash.rs
+++ b/tests/expectations/tests/objc_method_clash.rs
@@ -1,5 +1,6 @@
 /* automatically generated by rust-bindgen */
 
+
 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
 #![cfg(target_os = "macos")]
 
@@ -17,7 +18,7 @@
     }
     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 7a6e20f..38881ad 100644
--- a/tests/expectations/tests/objc_whitelist.rs
+++ b/tests/expectations/tests/objc_whitelist.rs
@@ -1,5 +1,6 @@
 /* automatically generated by rust-bindgen */
 
+
 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
 #![cfg(target_os = "macos")]
 
@@ -17,7 +18,7 @@
     }
     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
         )
     }
@@ -32,7 +33,7 @@
     }
     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
         )
     }