Skip to content

Commit 644b931

Browse files
committed
Rollup merge of #22922 - dotdash:closure_env_attr, r=eddyb
2 parents fb28214 + 549be5f commit 644b931

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/librustc_trans/trans/base.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -2435,21 +2435,19 @@ pub fn get_fn_llvm_attributes<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<
24352435
use middle::ty::{BrAnon, ReLateBound};
24362436

24372437
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),
24402440
ty::ty_closure(closure_did, _, substs) => {
24412441
let typer = common::NormalizingClosureTyper::new(ccx.tcx());
24422442
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))
24442445
}
24452446
_ => ccx.sess().bug("expected closure or function.")
24462447
};
24472448

24482449
let fn_sig = ty::erase_late_bound_regions(ccx.tcx(), fn_sig);
24492450

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 };
24532451
let mut attrs = llvm::AttrBuilder::new();
24542452
let ret_ty = fn_sig.output;
24552453

@@ -2460,7 +2458,11 @@ pub fn get_fn_llvm_attributes<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<
24602458
assert!(abi == RustCall);
24612459

24622460
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+
}
24642466
_ => ccx.sess().bug("expected tuple'd inputs")
24652467
}
24662468
},
@@ -2478,6 +2480,8 @@ pub fn get_fn_llvm_attributes<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<
24782480
_ => fn_sig.inputs.clone()
24792481
};
24802482

2483+
// Index 0 is the return value of the llvm func, so we start at 1
2484+
let mut first_arg_offset = 1;
24812485
if let ty::FnConverging(ret_ty) = ret_ty {
24822486
// A function pointer is called without the declaration
24832487
// available, so we have to apply any attributes with ABI

0 commit comments

Comments
 (0)