33use ir:: context:: BindgenContext ;
44use ir:: layout:: Layout ;
55use quote;
6- use proc_macro2;
76use std:: mem;
87
98pub 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 ( ) ;
0 commit comments