Skip to content

Commit 56bbbb0

Browse files
author
bors-servo
authored
Auto merge of #1235 - Eijebong:quote, r=fitzgen
Bump quote to 0.4
2 parents 6300067 + 6899c27 commit 56bbbb0

17 files changed

+142
-139
lines changed

Cargo.lock

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

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ 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.3.15"
50+
quote = "0.4"
5151
regex = "0.2"
5252
which = "1.0.2"
53+
proc-macro2 = "0.2"
5354

5455
[dependencies.env_logger]
5556
optional = true

src/codegen/helpers.rs

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

89
pub mod attributes {
910
use quote;
11+
use proc_macro2;
1012

1113
pub fn repr(which: &str) -> quote::Tokens {
12-
let which = quote::Ident::new(which);
14+
let which = proc_macro2::Term::intern(which);
1315
quote! {
1416
#[repr( #which )]
1517
}
1618
}
1719

1820
pub fn repr_list(which_ones: &[&str]) -> quote::Tokens {
19-
let which_ones = which_ones.iter().cloned().map(quote::Ident::new);
21+
let which_ones = which_ones.iter().cloned().map(proc_macro2::Term::intern);
2022
quote! {
2123
#[repr( #( #which_ones ),* )]
2224
}
2325
}
2426

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

4948
pub fn link_name(name: &str) -> quote::Tokens {
@@ -73,7 +72,7 @@ pub fn blob(layout: Layout) -> quote::Tokens {
7372
}
7473
};
7574

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

7877
let data_len = opaque.array_size().unwrap_or(layout.size);
7978

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

105104
if ctx.options().enable_cxx_namespaces {
106-
tokens.append(quote! { root:: });
105+
tokens.append_all(quote! { root:: });
107106
}
108107

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

116115
let size = layout.size;
117-
tokens.append(quote! {
116+
tokens.append_all(quote! {
118117
__BindgenBitfieldUnit<[u8; #size], #align>
119118
});
120119

@@ -126,6 +125,7 @@ pub mod ast_ty {
126125
use ir::function::FunctionSig;
127126
use ir::ty::FloatKind;
128127
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,29 +166,25 @@ 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 mut tokens = quote! {};
170-
tokens.append(val.to_string());
171-
tokens
169+
let val = proc_macro2::Literal::integer(val);
170+
quote!(#val)
172171
}
173172

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

181179
pub fn byte_array_expr(bytes: &[u8]) -> quote::Tokens {
182180
let mut bytes: Vec<_> = bytes.iter().cloned().collect();
183181
bytes.push(0);
184-
quote! {
185-
#bytes
186-
}
182+
quote! { [ #(#bytes),* ] }
187183
}
188184

189185
pub fn cstr_expr(mut string: String) -> quote::Tokens {
190186
string.push('\0');
191-
let b = quote::ByteStr(&string);
187+
let b = proc_macro2::Literal::byte_string(&string.as_bytes());
192188
quote! {
193189
#b
194190
}
@@ -199,16 +195,9 @@ pub mod ast_ty {
199195
f: f64,
200196
) -> Result<quote::Tokens, ()> {
201197
if f.is_finite() {
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-
}
198+
let val = proc_macro2::Literal::float(f);
208199

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

214203
let prefix = ctx.trait_prefix();

src/codegen/impl_partialeq.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ 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;
78

89
/// Generate a manual implementation of `PartialEq` trait for the
910
/// specified compound type.
@@ -71,7 +72,7 @@ pub fn gen_partialeq_impl(
7172
}
7273

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

0 commit comments

Comments
 (0)