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