@@ -150,21 +150,17 @@ fn enum_name(ctx: &GenCtx, name: &str) -> String {
150
150
fn gen_unmangle_method ( ctx : & mut GenCtx ,
151
151
v : & VarInfo ,
152
152
counts : & mut HashMap < String , isize > ,
153
- self_kind : ast:: SelfKind )
153
+ self_kind : Option < ast:: Mutability > )
154
154
-> ast:: ImplItem {
155
- let fndecl;
155
+ let mut fndecl;
156
156
let mut args = vec ! [ ] ;
157
157
158
- match self_kind {
159
- ast:: SelfKind :: Static => ( ) ,
160
- ast:: SelfKind :: Region ( _, mutable, _) => {
161
- let selfexpr = match mutable {
162
- ast:: Mutability :: Immutable => quote_expr ! ( & ctx. ext_cx, & * self ) ,
163
- ast:: Mutability :: Mutable => quote_expr ! ( & ctx. ext_cx, & mut * self ) ,
164
- } ;
165
- args. push ( selfexpr) ;
166
- } ,
167
- _ => unreachable ! ( )
158
+ if let Some ( mutability) = self_kind {
159
+ let selfexpr = match mutability {
160
+ ast:: Mutability :: Immutable => quote_expr ! ( & ctx. ext_cx, & * self ) ,
161
+ ast:: Mutability :: Mutable => quote_expr ! ( & ctx. ext_cx, & mut * self ) ,
162
+ } ;
163
+ args. push ( selfexpr) ;
168
164
}
169
165
170
166
match v. ty {
@@ -173,13 +169,12 @@ fn gen_unmangle_method(ctx: &mut GenCtx,
173
169
& * sig. ret_ty , sig. args . as_slice ( ) ,
174
170
false ) ;
175
171
let mut unnamed: usize = 0 ;
176
- let iter = if args. len ( ) > 0 {
172
+ let iter = if ! args. is_empty ( ) {
177
173
sig. args [ 1 ..] . iter ( )
178
174
} else {
179
175
sig. args . iter ( )
180
176
} ;
181
- for arg in iter {
182
- let ( ref n, _) = * arg;
177
+ for & ( ref n, _) in iter {
183
178
let argname = if n. is_empty ( ) {
184
179
unnamed += 1 ;
185
180
format ! ( "arg{}" , unnamed)
@@ -197,46 +192,79 @@ fn gen_unmangle_method(ctx: &mut GenCtx,
197
192
} )
198
193
} ) ,
199
194
span : ctx. span ,
200
- attrs : None ,
195
+ attrs : ast :: ThinVec :: new ( ) ,
201
196
} ;
202
197
args. push ( P ( expr) ) ;
203
198
}
204
199
} ,
205
200
_ => unreachable ! ( )
206
201
} ;
207
202
203
+
204
+ if let Some ( mutability) = self_kind {
205
+ assert ! ( !fndecl. inputs. is_empty( ) ) ;
206
+ fndecl. inputs [ 0 ] = ast:: Arg {
207
+ ty : P ( ast:: Ty {
208
+ id : ast:: DUMMY_NODE_ID ,
209
+ node : ast:: TyKind :: Rptr ( None , ast:: MutTy {
210
+ ty : P ( ast:: Ty {
211
+ id : ast:: DUMMY_NODE_ID ,
212
+ node : ast:: TyKind :: ImplicitSelf ,
213
+ span : ctx. span
214
+ } ) ,
215
+ mutbl : mutability,
216
+ } ) ,
217
+ span : ctx. span ,
218
+ } ) ,
219
+ pat : P ( ast:: Pat {
220
+ id : ast:: DUMMY_NODE_ID ,
221
+ node : ast:: PatKind :: Ident ( ast:: BindingMode :: ByValue ( ast:: Mutability :: Immutable ) ,
222
+ respan ( ctx. span , ctx. ext_cx . ident_of ( "self" ) ) ,
223
+ None ) ,
224
+ span : ctx. span ,
225
+ } ) ,
226
+ id : ast:: DUMMY_NODE_ID ,
227
+ } ;
228
+ }
229
+
208
230
let sig = ast:: MethodSig {
209
231
unsafety : ast:: Unsafety :: Unsafe ,
210
232
abi : Abi :: Rust ,
211
233
decl : P ( fndecl) ,
212
234
generics : empty_generics ( ) ,
213
- explicit_self : respan ( ctx. span , self_kind) ,
214
235
constness : ast:: Constness :: NotConst ,
215
236
} ;
216
237
217
- let block = ast:: Block {
218
- stmts : vec ! [ ] ,
219
- expr : Some ( P ( ast:: Expr {
220
- id : ast:: DUMMY_NODE_ID ,
221
- node : ast:: ExprKind :: Call (
222
- P ( ast:: Expr {
223
- id : ast:: DUMMY_NODE_ID ,
224
- node : ast:: ExprKind :: Path ( None , ast:: Path {
225
- span : ctx. span ,
226
- global : false ,
227
- segments : vec ! ( ast:: PathSegment {
228
- identifier: ctx. ext_cx. ident_of( & v. mangled) ,
229
- parameters: ast:: PathParameters :: none( )
230
- } )
231
- } ) ,
238
+ let call = P ( ast:: Expr {
239
+ id : ast:: DUMMY_NODE_ID ,
240
+ node : ast:: ExprKind :: Call (
241
+ P ( ast:: Expr {
242
+ id : ast:: DUMMY_NODE_ID ,
243
+ node : ast:: ExprKind :: Path ( None , ast:: Path {
232
244
span : ctx. span ,
233
- attrs : None ,
245
+ global : false ,
246
+ segments : vec ! [ ast:: PathSegment {
247
+ identifier: ctx. ext_cx. ident_of( & v. mangled) ,
248
+ parameters: ast:: PathParameters :: none( )
249
+ } ]
234
250
} ) ,
235
- args
236
- ) ,
237
- span : ctx. span ,
238
- attrs : None ,
239
- } ) ) ,
251
+ span : ctx. span ,
252
+ attrs : ast:: ThinVec :: new ( ) ,
253
+ } ) ,
254
+ args
255
+ ) ,
256
+ span : ctx. span ,
257
+ attrs : ast:: ThinVec :: new ( ) ,
258
+ } ) ;
259
+
260
+ let block = ast:: Block {
261
+ stmts : vec ! [
262
+ ast:: Stmt {
263
+ id: ast:: DUMMY_NODE_ID ,
264
+ node: ast:: StmtKind :: Expr ( call) ,
265
+ span: ctx. span,
266
+ }
267
+ ] ,
240
268
id : ast:: DUMMY_NODE_ID ,
241
269
rules : ast:: BlockCheckMode :: Default ,
242
270
span : ctx. span
@@ -282,16 +310,12 @@ pub fn gen_mods(links: &[(String, LinkType)],
282
310
// Create a dummy ExtCtxt. We only need this for string interning and that uses TLS.
283
311
let mut features = Features :: new ( ) ;
284
312
features. quote = true ;
285
- let cfg = ExpansionConfig {
286
- crate_name : "xxx" . to_owned ( ) ,
287
- features : Some ( & features) ,
288
- recursion_limit : 64 ,
289
- trace_mac : false ,
290
- } ;
291
- let sess = & parse:: ParseSess :: new ( ) ;
292
- let mut feature_gated_cfgs = vec ! [ ] ;
313
+
314
+ let cfg = ExpansionConfig :: default ( "xxx" . to_owned ( ) ) ;
315
+ let sess = parse:: ParseSess :: new ( ) ;
316
+ let mut loader = base:: DummyMacroLoader ;
293
317
let mut ctx = GenCtx {
294
- ext_cx : base:: ExtCtxt :: new ( sess, vec ! [ ] , cfg, & mut feature_gated_cfgs ) ,
318
+ ext_cx : base:: ExtCtxt :: new ( & sess, vec ! [ ] , cfg, & mut loader ) ,
295
319
options : options,
296
320
span : span,
297
321
module_map : map,
@@ -1220,11 +1244,11 @@ fn cstruct_to_rs(ctx: &mut GenCtx, name: &str, ci: CompInfo) -> Vec<P<ast::Item>
1220
1244
TFuncPtr ( ref sig) => {
1221
1245
let name = v. mangled . clone ( ) ;
1222
1246
let explicit_self = if v. is_static {
1223
- ast :: SelfKind :: Static
1247
+ None
1224
1248
} else if v. is_const {
1225
- ast :: SelfKind :: Region ( None , ast:: Mutability :: Immutable , ctx . ext_cx . ident_of ( "self" ) )
1249
+ Some ( ast:: Mutability :: Immutable )
1226
1250
} else {
1227
- ast :: SelfKind :: Region ( None , ast:: Mutability :: Mutable , ctx . ext_cx . ident_of ( "self" ) )
1251
+ Some ( ast:: Mutability :: Mutable )
1228
1252
} ;
1229
1253
unmangledlist. push ( gen_unmangle_method ( ctx, & v, & mut unmangle_count, explicit_self) ) ;
1230
1254
mangledlist. push ( cfunc_to_rs ( ctx, name, String :: new ( ) , String :: new ( ) ,
@@ -1698,8 +1722,6 @@ fn gen_fullbitfield_method(ctx: &mut GenCtx, bindgen_name: &String,
1698
1722
variadic : false
1699
1723
} ;
1700
1724
1701
- let stmts = Vec :: with_capacity ( bitfields. len ( ) + 1 ) ;
1702
-
1703
1725
let mut offset = 0 ;
1704
1726
1705
1727
let mut exprs = quote_expr ! ( & ctx. ext_cx, 0 ) ;
@@ -1721,8 +1743,13 @@ fn gen_fullbitfield_method(ctx: &mut GenCtx, bindgen_name: &String,
1721
1743
}
1722
1744
1723
1745
let block = ast:: Block {
1724
- stmts : stmts,
1725
- expr : Some ( exprs) ,
1746
+ stmts : vec ! [
1747
+ ast:: Stmt {
1748
+ id: ast:: DUMMY_NODE_ID ,
1749
+ node: ast:: StmtKind :: Expr ( exprs) ,
1750
+ span: ctx. span,
1751
+ }
1752
+ ] ,
1726
1753
id : ast:: DUMMY_NODE_ID ,
1727
1754
rules : ast:: BlockCheckMode :: Default ,
1728
1755
span : ctx. span
@@ -1734,7 +1761,6 @@ fn gen_fullbitfield_method(ctx: &mut GenCtx, bindgen_name: &String,
1734
1761
abi : Abi :: Rust ,
1735
1762
decl : P ( fndecl) ,
1736
1763
generics : empty_generics ( ) ,
1737
- explicit_self : respan ( ctx. span , ast:: SelfKind :: Static ) ,
1738
1764
constness : ast:: Constness :: Const ,
1739
1765
} , P ( block)
1740
1766
) ;
@@ -2151,7 +2177,7 @@ fn mk_arrty(ctx: &GenCtx, base: &ast::Ty, n: usize) -> ast::Ty {
2151
2177
id : ast:: DUMMY_NODE_ID ,
2152
2178
node : sz,
2153
2179
span : ctx. span ,
2154
- attrs : None ,
2180
+ attrs : ast :: ThinVec :: new ( ) ,
2155
2181
} )
2156
2182
) ;
2157
2183
0 commit comments