Skip to content

Commit b678c8a

Browse files
committed
Bump quote to 0.5 and proc_macro2 to 0.3
1 parent 6dae67e commit b678c8a

File tree

79 files changed

+630
-984
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+630
-984
lines changed

Cargo.lock

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

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +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.4"
53+
quote = { version = "0.5", default-features = false }
5454
regex = "0.2"
5555
which = "1.0.2"
56-
proc-macro2 = "0.2"
56+
proc-macro2 = { version = "0.3.2", default-features = false }
5757

5858
[dependencies.env_logger]
5959
optional = true

src/codegen/helpers.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
use ir::context::BindgenContext;
44
use ir::layout::Layout;
55
use quote;
6-
use proc_macro2;
76
use std::mem;
7+
use proc_macro2::{Term, Span};
88

99
pub mod attributes {
1010
use quote;
11-
use proc_macro2;
11+
use proc_macro2::{Term, Span};
1212

1313
pub fn repr(which: &str) -> quote::Tokens {
14-
let which = proc_macro2::Term::intern(which);
14+
let which = Term::new(which, Span::call_site());
1515
quote! {
1616
#[repr( #which )]
1717
}
1818
}
1919

2020
pub fn repr_list(which_ones: &[&str]) -> quote::Tokens {
21-
let which_ones = which_ones.iter().cloned().map(proc_macro2::Term::intern);
21+
let which_ones = which_ones.iter().cloned().map(|one| Term::new(one, Span::call_site()));
2222
quote! {
2323
#[repr( #( #which_ones ),* )]
2424
}
2525
}
2626

2727
pub fn derives(which_ones: &[&str]) -> quote::Tokens {
28-
let which_ones = which_ones.iter().cloned().map(proc_macro2::Term::intern);
28+
let which_ones = which_ones.iter().cloned().map(|one| Term::new(one, Span::call_site()));
2929
quote! {
3030
#[derive( #( #which_ones ),* )]
3131
}
@@ -38,11 +38,7 @@ pub mod attributes {
3838
}
3939

4040
pub fn doc(comment: String) -> quote::Tokens {
41-
// Doc comments are already preprocessed into nice `///` formats by the
42-
// time they get here. Just make sure that we have newlines around it so
43-
// that nothing else gets wrapped into the comment.
44-
let comment = proc_macro2::Literal::doccomment(&comment);
45-
quote! {#comment}
41+
quote!(#[doc=#comment])
4642
}
4743

4844
pub fn link_name(name: &str) -> quote::Tokens {
@@ -72,7 +68,7 @@ pub fn blob(layout: Layout) -> quote::Tokens {
7268
}
7369
};
7470

75-
let ty_name = proc_macro2::Term::intern(ty_name);
71+
let ty_name = Term::new(ty_name, Span::call_site());
7672

7773
let data_len = opaque.array_size().unwrap_or(layout.size);
7874

@@ -166,13 +162,13 @@ pub mod ast_ty {
166162

167163
pub fn int_expr(val: i64) -> quote::Tokens {
168164
// Don't use quote! { #val } because that adds the type suffix.
169-
let val = proc_macro2::Literal::integer(val);
165+
let val = proc_macro2::Literal::i64_unsuffixed(val);
170166
quote!(#val)
171167
}
172168

173169
pub fn uint_expr(val: u64) -> quote::Tokens {
174170
// Don't use quote! { #val } because that adds the type suffix.
175-
let val = proc_macro2::Term::intern(&val.to_string());
171+
let val = proc_macro2::Literal::u64_unsuffixed(val);
176172
quote!(#val)
177173
}
178174

@@ -195,7 +191,7 @@ pub mod ast_ty {
195191
f: f64,
196192
) -> Result<quote::Tokens, ()> {
197193
if f.is_finite() {
198-
let val = proc_macro2::Literal::float(f);
194+
let val = proc_macro2::Literal::f64_unsuffixed(f);
199195

200196
return Ok(quote!(#val));
201197
}

src/codegen/mod.rs

+21-19
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use ir::ty::{Type, TypeKind};
3838
use ir::var::Var;
3939

4040
use quote;
41-
use proc_macro2;
41+
use proc_macro2::{self, Term, Span};
4242

4343
use std::borrow::Cow;
4444
use std::cell::Cell;
@@ -75,7 +75,7 @@ fn root_import(ctx: &BindgenContext, module: &Item) -> quote::Tokens {
7575

7676

7777
let mut tokens = quote! {};
78-
tokens.append_separated(path, proc_macro2::Term::intern("::"));
78+
tokens.append_separated(path, Term::new("::", Span::call_site()));
7979

8080
quote! {
8181
#[allow(unused_imports)]
@@ -706,7 +706,7 @@ impl CodeGenerator for Type {
706706
pub use
707707
});
708708
let path = top_level_path(ctx, item);
709-
tokens.append_separated(path, proc_macro2::Term::intern("::"));
709+
tokens.append_separated(path, Term::new("::", Span::call_site()));
710710
tokens.append_all(quote! {
711711
:: #inner_rust_type as #rust_name ;
712712
});
@@ -1123,7 +1123,7 @@ impl<'a> FieldCodegen<'a> for FieldData {
11231123
impl BitfieldUnit {
11241124
/// Get the constructor name for this bitfield unit.
11251125
fn ctor_name(&self) -> quote::Tokens {
1126-
let ctor_name = proc_macro2::Term::intern(&format!("new_bitfield_{}", self.nth()));
1126+
let ctor_name = Term::new(&format!("new_bitfield_{}", self.nth()), Span::call_site());
11271127
quote! {
11281128
#ctor_name
11291129
}
@@ -1322,7 +1322,7 @@ impl<'a> FieldCodegen<'a> for Bitfield {
13221322
let prefix = ctx.trait_prefix();
13231323
let getter_name = bitfield_getter_name(ctx, self);
13241324
let setter_name = bitfield_setter_name(ctx, self);
1325-
let unit_field_ident = proc_macro2::Term::intern(unit_field_name);
1325+
let unit_field_ident = Term::new(unit_field_name, Span::call_site());
13261326

13271327
let bitfield_ty_item = ctx.resolve_item(self.ty());
13281328
let bitfield_ty = bitfield_ty_item.expect_type();
@@ -2147,7 +2147,7 @@ enum EnumBuilder<'a> {
21472147
Rust {
21482148
codegen_depth: usize,
21492149
attrs: Vec<quote::Tokens>,
2150-
ident: proc_macro2::Term,
2150+
ident: Term,
21512151
tokens: quote::Tokens,
21522152
emitted_any_variants: bool,
21532153
},
@@ -2187,7 +2187,7 @@ impl<'a> EnumBuilder<'a> {
21872187
enum_variation: EnumVariation,
21882188
enum_codegen_depth: usize,
21892189
) -> Self {
2190-
let ident = proc_macro2::Term::intern(name);
2190+
let ident = Term::new(name, Span::call_site());
21912191

21922192
match enum_variation {
21932193
EnumVariation::Bitfield => {
@@ -2225,7 +2225,7 @@ impl<'a> EnumBuilder<'a> {
22252225
}
22262226

22272227
EnumVariation::ModuleConsts => {
2228-
let ident = proc_macro2::Term::intern(CONSTIFIED_ENUM_MODULE_REPR_NAME);
2228+
let ident = Term::new(CONSTIFIED_ENUM_MODULE_REPR_NAME, Span::call_site());
22292229
let type_definition = quote! {
22302230
#( #attrs )*
22312231
pub type #ident = #repr;
@@ -2514,12 +2514,12 @@ impl CodeGenerator for Enum {
25142514
ctx: &BindgenContext,
25152515
enum_: &Type,
25162516
// Only to avoid recomputing every time.
2517-
enum_canonical_name: &proc_macro2::Term,
2517+
enum_canonical_name: &Term,
25182518
// May be the same as "variant" if it's because the
25192519
// enum is unnamed and we still haven't seen the
25202520
// value.
25212521
variant_name: &str,
2522-
referenced_name: &proc_macro2::Term,
2522+
referenced_name: &Term,
25232523
enum_rust_ty: quote::Tokens,
25242524
result: &mut CodegenResult<'a>,
25252525
) {
@@ -2554,7 +2554,7 @@ impl CodeGenerator for Enum {
25542554
);
25552555

25562556
// A map where we keep a value -> variant relation.
2557-
let mut seen_values = HashMap::<_, proc_macro2::Term>::new();
2557+
let mut seen_values = HashMap::<_, Term>::new();
25582558
let enum_rust_ty = item.to_rust_ty_or_opaque(ctx, &());
25592559
let is_toplevel = item.is_toplevel(ctx);
25602560

@@ -2652,12 +2652,13 @@ impl CodeGenerator for Enum {
26522652
let parent_name =
26532653
parent_canonical_name.as_ref().unwrap();
26542654

2655-
proc_macro2::Term::intern(
2655+
Term::new(
26562656
&format!(
26572657
"{}_{}",
26582658
parent_name,
26592659
variant_name.as_str()
2660-
)
2660+
),
2661+
Span::call_site()
26612662
)
26622663
};
26632664

@@ -3000,7 +3001,7 @@ impl TryToRustTy for Type {
30003001
}
30013002
TypeKind::Enum(..) => {
30023003
let path = item.namespace_aware_canonical_path(ctx);
3003-
let path = proc_macro2::Term::intern(&path.join("::"));
3004+
let path = Term::new(&path.join("::"), Span::call_site());
30043005
Ok(quote!(#path))
30053006
}
30063007
TypeKind::TemplateInstantiation(ref inst) => {
@@ -3123,7 +3124,7 @@ impl TryToRustTy for TemplateInstantiation {
31233124

31243125
let mut ty = quote! {};
31253126
let def_path = def.namespace_aware_canonical_path(ctx);
3126-
ty.append_separated(def_path.into_iter().map(|p| ctx.rust_ident(p)), proc_macro2::Term::intern("::"));
3127+
ty.append_separated(def_path.into_iter().map(|p| ctx.rust_ident(p)), Term::new("::", Span::call_site()));
31273128

31283129
let def_params = match def.self_template_params(ctx) {
31293130
Some(params) => params,
@@ -3462,11 +3463,11 @@ mod utils {
34623463
use ir::item::{Item, ItemCanonicalPath};
34633464
use ir::ty::TypeKind;
34643465
use quote;
3465-
use proc_macro2;
3466+
use proc_macro2::{Term, Span};
34663467
use std::mem;
34673468

34683469
pub fn prepend_bitfield_unit_type(result: &mut Vec<quote::Tokens>) {
3469-
let bitfield_unit_type = proc_macro2::Term::intern(include_str!("./bitfield_unit.rs"));
3470+
let bitfield_unit_type = Term::new(include_str!("./bitfield_unit.rs"), Span::call_site());
34703471
let bitfield_unit_type = quote!(#bitfield_unit_type);
34713472

34723473
let items = vec![bitfield_unit_type];
@@ -3693,9 +3694,10 @@ mod utils {
36933694
item: &Item,
36943695
ctx: &BindgenContext,
36953696
) -> error::Result<quote::Tokens> {
3696-
use proc_macro2;
3697+
use proc_macro2::{Term, Span};
3698+
36973699
let path = item.namespace_aware_canonical_path(ctx);
3698-
let path = proc_macro2::Term::intern(&path.join("::"));
3700+
let path = Term::new(&path.join("::"), Span::call_site());
36993701
let tokens = quote! {#path};
37003702
//tokens.append_separated(path, "::");
37013703

src/codegen/struct_layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use ir::context::BindgenContext;
77
use ir::layout::Layout;
88
use ir::ty::{Type, TypeKind};
99
use quote;
10-
use proc_macro2;
10+
use proc_macro2::{Term, Span};
1111
use std::cmp;
1212

1313
/// Trace the layout of struct.
@@ -311,7 +311,7 @@ impl<'a> StructLayoutTracker<'a> {
311311

312312
self.padding_count += 1;
313313

314-
let padding_field_name = proc_macro2::Term::intern(&format!("__bindgen_padding_{}", padding_count));
314+
let padding_field_name = Term::new(&format!("__bindgen_padding_{}", padding_count), Span::call_site());
315315

316316
self.max_field_align = cmp::max(self.max_field_align, layout.align);
317317

src/ir/comment.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn preprocess_single_lines(comment: &str, indent: usize) -> String {
5454
let indent = if is_first { "" } else { &*indent };
5555
is_first = false;
5656
let maybe_space = if l.is_empty() { "" } else { " " };
57-
format!("{}///{}{}", indent, maybe_space, l)
57+
format!("{}{}{}", indent, maybe_space, l)
5858
})
5959
.collect();
6060
lines.join("\n")
@@ -79,7 +79,7 @@ fn preprocess_multi_line(comment: &str, indent: usize) -> String {
7979
let indent = if is_first { "" } else { &*indent };
8080
is_first = false;
8181
let maybe_space = if line.is_empty() { "" } else { " " };
82-
format!("{}///{}{}", indent, maybe_space, line)
82+
format!("{}{}{}", indent, maybe_space, line)
8383
})
8484
.collect();
8585

@@ -105,20 +105,20 @@ mod test {
105105

106106
#[test]
107107
fn processes_single_lines_correctly() {
108-
assert_eq!(preprocess("/// hello", 0), "/// hello");
109-
assert_eq!(preprocess("// hello", 0), "/// hello");
108+
assert_eq!(preprocess("/// hello", 0), " hello");
109+
assert_eq!(preprocess("// hello", 0), " hello");
110110
}
111111

112112
#[test]
113113
fn processes_multi_lines_correctly() {
114114
assert_eq!(
115115
preprocess("/** hello \n * world \n * foo \n */", 0),
116-
"/// hello\n/// world\n/// foo"
116+
" hello\n world\n foo"
117117
);
118118

119119
assert_eq!(
120120
preprocess("/**\nhello\n*world\n*foo\n*/", 0),
121-
"/// hello\n/// world\n/// foo"
121+
" hello\n world\n foo"
122122
);
123123
}
124124
}

src/ir/context.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use cexpr;
2424
use clang::{self, Cursor};
2525
use clang_sys;
2626
use parse::ClangItemParser;
27-
use proc_macro2;
27+
use proc_macro2::{Term, Span};
2828
use std::borrow::Cow;
2929
use std::cell::Cell;
3030
use std::collections::{HashMap, HashSet, hash_map};
@@ -905,19 +905,19 @@ impl BindgenContext {
905905
}
906906

907907
/// Returns a mangled name as a rust identifier.
908-
pub fn rust_ident<S>(&self, name: S) -> proc_macro2::Term
908+
pub fn rust_ident<S>(&self, name: S) -> Term
909909
where
910910
S: AsRef<str>
911911
{
912912
self.rust_ident_raw(self.rust_mangle(name.as_ref()))
913913
}
914914

915915
/// Returns a mangled name as a rust identifier.
916-
pub fn rust_ident_raw<T>(&self, name: T) -> proc_macro2::Term
916+
pub fn rust_ident_raw<T>(&self, name: T) -> Term
917917
where
918918
T: AsRef<str>
919919
{
920-
proc_macro2::Term::intern(name.as_ref())
920+
Term::new(name.as_ref(), Span::call_site())
921921
}
922922

923923
/// Iterate over all items that have been defined.
@@ -2341,7 +2341,7 @@ impl BindgenContext {
23412341

23422342
/// Convenient method for getting the prefix to use for most traits in
23432343
/// codegen depending on the `use_core` option.
2344-
pub fn trait_prefix(&self) -> proc_macro2::Term {
2344+
pub fn trait_prefix(&self) -> Term {
23452345
if self.options().use_core {
23462346
self.rust_ident_raw("core")
23472347
} else {

0 commit comments

Comments
 (0)