Skip to content

Commit eb415c7

Browse files
committed
Revert "Bump quote to 0.4"
This reverts commit 6899c27. The `proc_macro2` crate depends on rustc internal crates, which means that `bindgen` would need to be run under `rustup`. We can follow rust-lang/rust#47931 to get updates on when this issue might be resolved and we can update `quote` again. Fixes #1248
1 parent a09a8ff commit eb415c7

17 files changed

+108
-115
lines changed

Cargo.lock

+3-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ clap = "2"
4747
clang-sys = { version = "0.21.0", features = ["runtime", "clang_3_9"] }
4848
lazy_static = "1"
4949
peeking_take_while = "0.1.2"
50-
quote = "0.4"
50+
quote = "0.3.15"
5151
regex = "0.2"
5252
which = "1.0.2"
53-
proc-macro2 = "0.2"
5453

5554
[dependencies.env_logger]
5655
optional = true

src/codegen/helpers.rs

+30-19
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,27 @@
33
use ir::context::BindgenContext;
44
use ir::layout::Layout;
55
use quote;
6-
use proc_macro2;
76
use std::mem;
87

98
pub mod attributes {
109
use quote;
11-
use proc_macro2;
1210

1311
pub fn repr(which: &str) -> quote::Tokens {
14-
let which = proc_macro2::Term::intern(which);
12+
let which = quote::Ident::new(which);
1513
quote! {
1614
#[repr( #which )]
1715
}
1816
}
1917

2018
pub fn repr_list(which_ones: &[&str]) -> quote::Tokens {
21-
let which_ones = which_ones.iter().cloned().map(proc_macro2::Term::intern);
19+
let which_ones = which_ones.iter().cloned().map(quote::Ident::new);
2220
quote! {
2321
#[repr( #( #which_ones ),* )]
2422
}
2523
}
2624

2725
pub fn derives(which_ones: &[&str]) -> quote::Tokens {
28-
let which_ones = which_ones.iter().cloned().map(proc_macro2::Term::intern);
26+
let which_ones = which_ones.iter().cloned().map(quote::Ident::new);
2927
quote! {
3028
#[derive( #( #which_ones ),* )]
3129
}
@@ -41,8 +39,11 @@ pub mod attributes {
4139
// Doc comments are already preprocessed into nice `///` formats by the
4240
// time they get here. Just make sure that we have newlines around it so
4341
// that nothing else gets wrapped into the comment.
44-
let comment = proc_macro2::Literal::doccomment(&comment);
45-
quote! {#comment}
42+
let mut tokens = quote! {};
43+
tokens.append("\n");
44+
tokens.append(comment);
45+
tokens.append("\n");
46+
tokens
4647
}
4748

4849
pub fn link_name(name: &str) -> quote::Tokens {
@@ -72,7 +73,7 @@ pub fn blob(layout: Layout) -> quote::Tokens {
7273
}
7374
};
7475

75-
let ty_name = proc_macro2::Term::intern(ty_name);
76+
let ty_name = quote::Ident::new(ty_name);
7677

7778
let data_len = opaque.array_size().unwrap_or(layout.size);
7879

@@ -102,7 +103,7 @@ pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> quote::Tokens {
102103
let mut tokens = quote! {};
103104

104105
if ctx.options().enable_cxx_namespaces {
105-
tokens.append_all(quote! { root:: });
106+
tokens.append(quote! { root:: });
106107
}
107108

108109
let align = match layout.align {
@@ -113,7 +114,7 @@ pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> quote::Tokens {
113114
};
114115

115116
let size = layout.size;
116-
tokens.append_all(quote! {
117+
tokens.append(quote! {
117118
__BindgenBitfieldUnit<[u8; #size], #align>
118119
});
119120

@@ -125,7 +126,6 @@ pub mod ast_ty {
125126
use ir::function::FunctionSig;
126127
use ir::ty::FloatKind;
127128
use quote;
128-
use proc_macro2;
129129

130130
pub fn raw_type(ctx: &BindgenContext, name: &str) -> quote::Tokens {
131131
let ident = ctx.rust_ident_raw(name);
@@ -166,25 +166,29 @@ pub mod ast_ty {
166166

167167
pub fn int_expr(val: i64) -> quote::Tokens {
168168
// Don't use quote! { #val } because that adds the type suffix.
169-
let val = proc_macro2::Literal::integer(val);
170-
quote!(#val)
169+
let mut tokens = quote! {};
170+
tokens.append(val.to_string());
171+
tokens
171172
}
172173

173174
pub fn uint_expr(val: u64) -> quote::Tokens {
174175
// Don't use quote! { #val } because that adds the type suffix.
175-
let val = proc_macro2::Term::intern(&val.to_string());
176-
quote!(#val)
176+
let mut tokens = quote! {};
177+
tokens.append(val.to_string());
178+
tokens
177179
}
178180

179181
pub fn byte_array_expr(bytes: &[u8]) -> quote::Tokens {
180182
let mut bytes: Vec<_> = bytes.iter().cloned().collect();
181183
bytes.push(0);
182-
quote! { [ #(#bytes),* ] }
184+
quote! {
185+
#bytes
186+
}
183187
}
184188

185189
pub fn cstr_expr(mut string: String) -> quote::Tokens {
186190
string.push('\0');
187-
let b = proc_macro2::Literal::byte_string(&string.as_bytes());
191+
let b = quote::ByteStr(&string);
188192
quote! {
189193
#b
190194
}
@@ -195,9 +199,16 @@ pub mod ast_ty {
195199
f: f64,
196200
) -> Result<quote::Tokens, ()> {
197201
if f.is_finite() {
198-
let val = proc_macro2::Literal::float(f);
202+
let mut string = f.to_string();
203+
204+
// So it gets properly recognised as a floating point constant.
205+
if !string.contains('.') {
206+
string.push('.');
207+
}
199208

200-
return Ok(quote!(#val));
209+
let mut tokens = quote! {};
210+
tokens.append(string);
211+
return Ok(tokens);
201212
}
202213

203214
let prefix = ctx.trait_prefix();

src/codegen/impl_partialeq.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use ir::context::BindgenContext;
44
use ir::item::{IsOpaque, Item};
55
use ir::ty::{TypeKind, RUST_DERIVE_IN_ARRAY_LIMIT};
66
use quote;
7-
use proc_macro2;
87

98
/// Generate a manual implementation of `PartialEq` trait for the
109
/// specified compound type.
@@ -72,7 +71,7 @@ pub fn gen_partialeq_impl(
7271
}
7372

7473
fn gen_field(ctx: &BindgenContext, ty_item: &Item, name: &str) -> quote::Tokens {
75-
fn quote_equals(name_ident: proc_macro2::Term) -> quote::Tokens {
74+
fn quote_equals(name_ident: quote::Ident) -> quote::Tokens {
7675
quote! { self.#name_ident == other.#name_ident }
7776
}
7877

0 commit comments

Comments
 (0)