@@ -2430,21 +2430,19 @@ pub fn get_fn_llvm_attributes<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<
2430
2430
use middle:: ty:: { BrAnon , ReLateBound } ;
2431
2431
2432
2432
let function_type;
2433
- let ( fn_sig, abi, has_env ) = match fn_ty. sty {
2434
- ty:: ty_bare_fn( _, ref f) => ( & f. sig , f. abi , false ) ,
2433
+ let ( fn_sig, abi, env_ty ) = match fn_ty. sty {
2434
+ ty:: ty_bare_fn( _, ref f) => ( & f. sig , f. abi , None ) ,
2435
2435
ty:: ty_closure( closure_did, _, substs) => {
2436
2436
let typer = common:: NormalizingClosureTyper :: new ( ccx. tcx ( ) ) ;
2437
2437
function_type = typer. closure_type ( closure_did, substs) ;
2438
- ( & function_type. sig , RustCall , true )
2438
+ let self_type = self_type_for_closure ( ccx, closure_did, fn_ty) ;
2439
+ ( & function_type. sig , RustCall , Some ( self_type) )
2439
2440
}
2440
2441
_ => ccx. sess ( ) . bug ( "expected closure or function." )
2441
2442
} ;
2442
2443
2443
2444
let fn_sig = ty:: erase_late_bound_regions ( ccx. tcx ( ) , fn_sig) ;
2444
2445
2445
- // Since index 0 is the return value of the llvm func, we start
2446
- // at either 1 or 2 depending on whether there's an env slot or not
2447
- let mut first_arg_offset = if has_env { 2 } else { 1 } ;
2448
2446
let mut attrs = llvm:: AttrBuilder :: new ( ) ;
2449
2447
let ret_ty = fn_sig. output ;
2450
2448
@@ -2455,7 +2453,11 @@ pub fn get_fn_llvm_attributes<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<
2455
2453
assert ! ( abi == RustCall ) ;
2456
2454
2457
2455
match fn_sig. inputs [ 0 ] . sty {
2458
- ty:: ty_tup( ref inputs) => inputs. clone ( ) ,
2456
+ ty:: ty_tup( ref inputs) => {
2457
+ let mut full_inputs = vec ! [ env_ty. expect( "Missing closure environment" ) ] ;
2458
+ full_inputs. push_all ( inputs) ;
2459
+ full_inputs
2460
+ }
2459
2461
_ => ccx. sess ( ) . bug ( "expected tuple'd inputs" )
2460
2462
}
2461
2463
} ,
@@ -2473,6 +2475,8 @@ pub fn get_fn_llvm_attributes<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<
2473
2475
_ => fn_sig. inputs . clone ( )
2474
2476
} ;
2475
2477
2478
+ // Index 0 is the return value of the llvm func, so we start at 1
2479
+ let mut first_arg_offset = 1 ;
2476
2480
if let ty:: FnConverging ( ret_ty) = ret_ty {
2477
2481
// A function pointer is called without the declaration
2478
2482
// available, so we have to apply any attributes with ABI
0 commit comments