2
2
3
3
use ir:: context:: BindgenContext ;
4
4
use ir:: layout:: Layout ;
5
- use proc_macro2:: { self , Ident , Span } ;
5
+ use proc_macro2:: { Ident , Span , TokenStream } ;
6
6
use quote:: TokenStreamExt ;
7
7
8
8
pub mod attributes {
9
- use proc_macro2:: { self , Ident , Span } ;
9
+ use proc_macro2:: { Ident , Span , TokenStream } ;
10
10
11
- pub fn repr ( which : & str ) -> proc_macro2 :: TokenStream {
11
+ pub fn repr ( which : & str ) -> TokenStream {
12
12
let which = Ident :: new ( which, Span :: call_site ( ) ) ;
13
13
quote ! {
14
14
#[ repr( #which ) ]
15
15
}
16
16
}
17
17
18
- pub fn repr_list ( which_ones : & [ & str ] ) -> proc_macro2 :: TokenStream {
18
+ pub fn repr_list ( which_ones : & [ & str ] ) -> TokenStream {
19
19
let which_ones = which_ones. iter ( ) . cloned ( ) . map ( |one| Ident :: new ( one, Span :: call_site ( ) ) ) ;
20
20
quote ! {
21
21
#[ repr( #( #which_ones ) , * ) ]
22
22
}
23
23
}
24
24
25
- pub fn derives ( which_ones : & [ & str ] ) -> proc_macro2 :: TokenStream {
25
+ pub fn derives ( which_ones : & [ & str ] ) -> TokenStream {
26
26
let which_ones = which_ones. iter ( ) . cloned ( ) . map ( |one| Ident :: new ( one, Span :: call_site ( ) ) ) ;
27
27
quote ! {
28
28
#[ derive( #( #which_ones ) , * ) ]
29
29
}
30
30
}
31
31
32
- pub fn inline ( ) -> proc_macro2 :: TokenStream {
32
+ pub fn inline ( ) -> TokenStream {
33
33
quote ! {
34
34
#[ inline]
35
35
}
36
36
}
37
37
38
- pub fn must_use ( ) -> proc_macro2 :: TokenStream {
38
+ pub fn must_use ( ) -> TokenStream {
39
39
quote ! {
40
40
#[ must_use]
41
41
}
42
42
}
43
43
44
- pub fn doc ( comment : String ) -> proc_macro2 :: TokenStream {
44
+ pub fn doc ( comment : String ) -> TokenStream {
45
45
use std:: str:: FromStr ;
46
46
47
47
// NOTE(emilio): By this point comments are already preprocessed and in
48
48
// `///` form. Quote turns them into `#[doc]` comments, but oh well.
49
- proc_macro2 :: TokenStream :: from_str ( & comment) . unwrap ( )
49
+ TokenStream :: from_str ( & comment) . unwrap ( )
50
50
}
51
51
52
- pub fn link_name ( name : & str ) -> proc_macro2 :: TokenStream {
52
+ pub fn link_name ( name : & str ) -> TokenStream {
53
53
// LLVM mangles the name by default but it's already mangled.
54
54
// Prefixing the name with \u{1} should tell LLVM to not mangle it.
55
55
let name = format ! ( "\u{1} {}" , name) ;
@@ -61,7 +61,7 @@ pub mod attributes {
61
61
62
62
/// Generates a proper type for a field or type with a given `Layout`, that is,
63
63
/// a type with the correct size and alignment restrictions.
64
- pub fn blob ( ctx : & BindgenContext , layout : Layout ) -> proc_macro2 :: TokenStream {
64
+ pub fn blob ( ctx : & BindgenContext , layout : Layout ) -> TokenStream {
65
65
let opaque = layout. opaque ( ) ;
66
66
67
67
// FIXME(emilio, #412): We fall back to byte alignment, but there are
@@ -92,14 +92,14 @@ pub fn blob(ctx: &BindgenContext, layout: Layout) -> proc_macro2::TokenStream {
92
92
}
93
93
94
94
/// Integer type of the same size as the given `Layout`.
95
- pub fn integer_type ( ctx : & BindgenContext , layout : Layout ) -> Option < proc_macro2 :: TokenStream > {
95
+ pub fn integer_type ( ctx : & BindgenContext , layout : Layout ) -> Option < TokenStream > {
96
96
let name = Layout :: known_type_for_size ( ctx, layout. size ) ?;
97
97
let name = Ident :: new ( name, Span :: call_site ( ) ) ;
98
98
Some ( quote ! { #name } )
99
99
}
100
100
101
101
/// Generates a bitfield allocation unit type for a type with the given `Layout`.
102
- pub fn bitfield_unit ( ctx : & BindgenContext , layout : Layout ) -> proc_macro2 :: TokenStream {
102
+ pub fn bitfield_unit ( ctx : & BindgenContext , layout : Layout ) -> TokenStream {
103
103
let mut tokens = quote ! { } ;
104
104
105
105
if ctx. options ( ) . enable_cxx_namespaces {
@@ -126,13 +126,14 @@ pub mod ast_ty {
126
126
use ir:: function:: FunctionSig ;
127
127
use ir:: layout:: Layout ;
128
128
use ir:: ty:: FloatKind ;
129
- use proc_macro2;
129
+ use std:: str:: FromStr ;
130
+ use proc_macro2:: { self , TokenStream } ;
130
131
131
- pub fn raw_type ( ctx : & BindgenContext , name : & str ) -> proc_macro2 :: TokenStream {
132
+ pub fn raw_type ( ctx : & BindgenContext , name : & str ) -> TokenStream {
132
133
let ident = ctx. rust_ident_raw ( name) ;
133
134
match ctx. options ( ) . ctypes_prefix {
134
135
Some ( ref prefix) => {
135
- let prefix = ctx . rust_ident_raw ( prefix. as_str ( ) ) ;
136
+ let prefix = TokenStream :: from_str ( prefix. as_str ( ) ) . unwrap ( ) ;
136
137
quote ! {
137
138
#prefix:: #ident
138
139
}
@@ -147,7 +148,7 @@ pub mod ast_ty {
147
148
ctx : & BindgenContext ,
148
149
fk : FloatKind ,
149
150
layout : Option < Layout > ,
150
- ) -> proc_macro2 :: TokenStream {
151
+ ) -> TokenStream {
151
152
// TODO: we probably should take the type layout into account more
152
153
// often?
153
154
//
@@ -187,25 +188,25 @@ pub mod ast_ty {
187
188
}
188
189
}
189
190
190
- pub fn int_expr ( val : i64 ) -> proc_macro2 :: TokenStream {
191
+ pub fn int_expr ( val : i64 ) -> TokenStream {
191
192
// Don't use quote! { #val } because that adds the type suffix.
192
193
let val = proc_macro2:: Literal :: i64_unsuffixed ( val) ;
193
194
quote ! ( #val)
194
195
}
195
196
196
- pub fn uint_expr ( val : u64 ) -> proc_macro2 :: TokenStream {
197
+ pub fn uint_expr ( val : u64 ) -> TokenStream {
197
198
// Don't use quote! { #val } because that adds the type suffix.
198
199
let val = proc_macro2:: Literal :: u64_unsuffixed ( val) ;
199
200
quote ! ( #val)
200
201
}
201
202
202
- pub fn byte_array_expr ( bytes : & [ u8 ] ) -> proc_macro2 :: TokenStream {
203
+ pub fn byte_array_expr ( bytes : & [ u8 ] ) -> TokenStream {
203
204
let mut bytes: Vec < _ > = bytes. iter ( ) . cloned ( ) . collect ( ) ;
204
205
bytes. push ( 0 ) ;
205
206
quote ! { [ #( #bytes) , * ] }
206
207
}
207
208
208
- pub fn cstr_expr ( mut string : String ) -> proc_macro2 :: TokenStream {
209
+ pub fn cstr_expr ( mut string : String ) -> TokenStream {
209
210
string. push ( '\0' ) ;
210
211
let b = proc_macro2:: Literal :: byte_string ( & string. as_bytes ( ) ) ;
211
212
quote ! {
@@ -216,7 +217,7 @@ pub mod ast_ty {
216
217
pub fn float_expr (
217
218
ctx : & BindgenContext ,
218
219
f : f64 ,
219
- ) -> Result < proc_macro2 :: TokenStream , ( ) > {
220
+ ) -> Result < TokenStream , ( ) > {
220
221
if f. is_finite ( ) {
221
222
let val = proc_macro2:: Literal :: f64_unsuffixed ( f) ;
222
223
@@ -250,7 +251,7 @@ pub mod ast_ty {
250
251
pub fn arguments_from_signature (
251
252
signature : & FunctionSig ,
252
253
ctx : & BindgenContext ,
253
- ) -> Vec < proc_macro2 :: TokenStream > {
254
+ ) -> Vec < TokenStream > {
254
255
let mut unnamed_arguments = 0 ;
255
256
signature
256
257
. argument_types ( )
0 commit comments