@@ -331,16 +331,21 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
331
331
let fcx = FunctionContext :: new ( ccx, lloncefn, fn_ty) ;
332
332
let mut bcx = fcx. get_entry_block ( ) ;
333
333
334
+ let callee = Callee {
335
+ data : Fn ( llreffn) ,
336
+ ty : llref_fn_ty
337
+ } ;
338
+
334
339
// the first argument (`self`) will be the (by value) closure env.
335
340
336
341
let mut llargs = get_params ( fcx. llfn ) ;
337
- let mut self_idx = fcx. fn_ty . ret . is_indirect ( ) as usize ;
342
+ let idx = fcx. fn_ty . ret . is_indirect ( ) as usize ;
338
343
let env_arg = & fcx. fn_ty . args [ 0 ] ;
339
344
let llenv = if env_arg. is_indirect ( ) {
340
- llargs[ self_idx ]
345
+ llargs[ idx ]
341
346
} else {
342
347
let scratch = alloc_ty ( & bcx, closure_ty, "self" ) ;
343
- let mut llarg_idx = self_idx ;
348
+ let mut llarg_idx = idx ;
344
349
env_arg. store_fn_arg ( & bcx, & mut llarg_idx, scratch) ;
345
350
scratch
346
351
} ;
@@ -349,35 +354,24 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
349
354
// Adjust llargs such that llargs[self_idx..] has the call arguments.
350
355
// For zero-sized closures that means sneaking in a new argument.
351
356
if env_arg. is_ignore ( ) {
352
- if self_idx > 0 {
353
- self_idx -= 1 ;
354
- llargs[ self_idx] = llenv;
357
+ if fcx. fn_ty . ret . is_indirect ( ) {
358
+ llargs[ 0 ] = llenv;
355
359
} else {
356
360
llargs. insert ( 0 , llenv) ;
357
361
}
358
362
} else {
359
- llargs[ self_idx ] = llenv;
363
+ llargs[ idx ] = llenv;
360
364
}
361
365
362
- let callee = Callee {
363
- data : Fn ( llreffn) ,
364
- ty : llref_fn_ty
365
- } ;
366
-
367
366
// Call the by-ref closure body with `self` in a cleanup scope,
368
367
// to drop `self` when the body returns, or in case it unwinds.
369
368
let self_scope = fcx. schedule_drop_mem ( llenv, closure_ty) ;
370
369
let fn_ret = callee. ty . fn_ret ( ) ;
371
370
let fn_ty = callee. direct_fn_type ( bcx. ccx , & [ ] ) ;
372
371
373
- let first_llarg = if fn_ty. ret . is_indirect ( ) && !fcx. fn_ty . ret . is_ignore ( ) {
374
- Some ( get_param ( fcx. llfn , 0 ) )
375
- } else {
376
- None
377
- } ;
378
- let llargs = first_llarg. into_iter ( ) . chain ( llargs[ self_idx..] . iter ( ) . cloned ( ) )
379
- . collect :: < Vec < _ > > ( ) ;
380
-
372
+ if fn_ty. ret . is_indirect ( ) {
373
+ llargs. insert ( 0 , get_param ( fcx. llfn , 0 ) ) ;
374
+ }
381
375
let llfn = callee. reify ( bcx. ccx ) ;
382
376
let llret;
383
377
if let Some ( landing_pad) = self_scope. landing_pad {
0 commit comments