Skip to content

Commit 8fe4d63

Browse files
author
bors-servo
authored
Auto merge of #1303 - Eijebong:bump, r=emilio
Bump quote to 0.5
2 parents 0a601d6 + 3258c5a commit 8fe4d63

18 files changed

+120
-106
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
@@ -50,9 +50,10 @@ clap = "2"
5050
clang-sys = { version = "0.22.0", features = ["runtime", "clang_6_0"] }
5151
lazy_static = "1"
5252
peeking_take_while = "0.1.2"
53-
quote = "0.3.15"
53+
quote = { version = "0.5", default-features = false }
5454
regex = "0.2"
5555
which = "1.0.2"
56+
proc-macro2 = { version = "0.3.2", default-features = false }
5657

5758
[dependencies.env_logger]
5859
optional = true

src/codegen/helpers.rs

+20-28
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,28 @@ use ir::context::BindgenContext;
44
use ir::layout::Layout;
55
use quote;
66
use std::mem;
7+
use proc_macro2::{Term, Span};
78

89
pub mod attributes {
910
use quote;
11+
use proc_macro2::{Term, Span};
1012

1113
pub fn repr(which: &str) -> quote::Tokens {
12-
let which = quote::Ident::new(which);
14+
let which = Term::new(which, Span::call_site());
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(|one| Term::new(one, Span::call_site()));
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(|one| Term::new(one, Span::call_site()));
2729
quote! {
2830
#[derive( #( #which_ones ),* )]
2931
}
@@ -40,9 +42,9 @@ pub mod attributes {
4042
// time they get here. Just make sure that we have newlines around it so
4143
// that nothing else gets wrapped into the comment.
4244
let mut tokens = quote! {};
43-
tokens.append("\n");
44-
tokens.append(comment);
45-
tokens.append("\n");
45+
tokens.append(Term::new("\n", Span::call_site()));
46+
tokens.append(Term::new(&comment, Span::call_site()));
47+
tokens.append(Term::new("\n", Span::call_site()));
4648
tokens
4749
}
4850

@@ -73,7 +75,7 @@ pub fn blob(layout: Layout) -> quote::Tokens {
7375
}
7476
};
7577

76-
let ty_name = quote::Ident::new(ty_name);
78+
let ty_name = Term::new(ty_name, Span::call_site());
7779

7880
let data_len = opaque.array_size().unwrap_or(layout.size);
7981

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

105107
if ctx.options().enable_cxx_namespaces {
106-
tokens.append(quote! { root:: });
108+
tokens.append_all(quote! { root:: });
107109
}
108110

109111
let align = match layout.align {
@@ -114,7 +116,7 @@ pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> quote::Tokens {
114116
};
115117

116118
let size = layout.size;
117-
tokens.append(quote! {
119+
tokens.append_all(quote! {
118120
__BindgenBitfieldUnit<[u8; #size], #align>
119121
});
120122

@@ -126,6 +128,7 @@ pub mod ast_ty {
126128
use ir::function::FunctionSig;
127129
use ir::ty::FloatKind;
128130
use quote;
131+
use proc_macro2;
129132

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

167170
pub fn int_expr(val: i64) -> quote::Tokens {
168171
// Don't use quote! { #val } because that adds the type suffix.
169-
let mut tokens = quote! {};
170-
tokens.append(val.to_string());
171-
tokens
172+
let val = proc_macro2::Literal::i64_unsuffixed(val);
173+
quote!(#val)
172174
}
173175

174176
pub fn uint_expr(val: u64) -> quote::Tokens {
175177
// Don't use quote! { #val } because that adds the type suffix.
176-
let mut tokens = quote! {};
177-
tokens.append(val.to_string());
178-
tokens
178+
let val = proc_macro2::Literal::u64_unsuffixed(val);
179+
quote!(#val)
179180
}
180181

181182
pub fn byte_array_expr(bytes: &[u8]) -> quote::Tokens {
182183
let mut bytes: Vec<_> = bytes.iter().cloned().collect();
183184
bytes.push(0);
184-
quote! {
185-
#bytes
186-
}
185+
quote! { [ #(#bytes),* ] }
187186
}
188187

189188
pub fn cstr_expr(mut string: String) -> quote::Tokens {
190189
string.push('\0');
191-
let b = quote::ByteStr(&string);
190+
let b = proc_macro2::Literal::byte_string(&string.as_bytes());
192191
quote! {
193192
#b
194193
}
@@ -199,16 +198,9 @@ pub mod ast_ty {
199198
f: f64,
200199
) -> Result<quote::Tokens, ()> {
201200
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-
}
201+
let val = proc_macro2::Literal::f64_unsuffixed(f);
208202

209-
let mut tokens = quote! {};
210-
tokens.append(string);
211-
return Ok(tokens);
203+
return Ok(quote!(#val));
212204
}
213205

214206
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)