diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 29811ad6dd5..9814a4ed183 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -669,30 +669,31 @@ pub fn compare_simd_types<'blk, 'tcx>( } } -pub type val_and_ty_fn<'a, 'blk, 'tcx> = - |Block<'blk, 'tcx>, ValueRef, Ty<'tcx>|: 'a -> Block<'blk, 'tcx>; - // Iterates through the elements of a structural type. -pub fn iter_structural_ty<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, - av: ValueRef, - t: Ty<'tcx>, - f: val_and_ty_fn<'a, 'blk, 'tcx>) - -> Block<'blk, 'tcx> { +pub fn iter_structural_ty<'blk, 'tcx, F>(cx: Block<'blk, 'tcx>, + av: ValueRef, + t: Ty<'tcx>, + mut f: F) + -> Block<'blk, 'tcx> where + F: FnMut(Block<'blk, 'tcx>, ValueRef, Ty<'tcx>) -> Block<'blk, 'tcx>, +{ let _icx = push_ctxt("iter_structural_ty"); - fn iter_variant<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, - repr: &adt::Repr<'tcx>, - av: ValueRef, - variant: &ty::VariantInfo<'tcx>, - substs: &subst::Substs<'tcx>, - f: val_and_ty_fn<'a, 'blk, 'tcx>) - -> Block<'blk, 'tcx> { + fn iter_variant<'blk, 'tcx, F>(cx: Block<'blk, 'tcx>, + repr: &adt::Repr<'tcx>, + av: ValueRef, + variant: &ty::VariantInfo<'tcx>, + substs: &subst::Substs<'tcx>, + f: &mut F) + -> Block<'blk, 'tcx> where + F: FnMut(Block<'blk, 'tcx>, ValueRef, Ty<'tcx>) -> Block<'blk, 'tcx>, + { let _icx = push_ctxt("iter_variant"); let tcx = cx.tcx(); let mut cx = cx; for (i, &arg) in variant.args.iter().enumerate() { - cx = f(cx, + cx = (*f)(cx, adt::trans_field_ptr(cx, repr, av, variant.disr_val, i), arg.subst(tcx, substs)); } @@ -764,7 +765,7 @@ pub fn iter_structural_ty<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, match adt::trans_switch(cx, &*repr, av) { (_match::Single, None) => { cx = iter_variant(cx, &*repr, av, &*(*variants)[0], - substs, f); + substs, &mut f); } (_match::Switch, Some(lldiscrim_a)) => { cx = f(cx, lldiscrim_a, cx.tcx().types.int); @@ -793,7 +794,7 @@ pub fn iter_structural_ty<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, data_ptr, &**variant, substs, - |x,y,z| f(x,y,z)); + &mut f); Br(variant_cx, next_cx.llbb); } cx = next_cx; diff --git a/src/librustc_trans/trans/glue.rs b/src/librustc_trans/trans/glue.rs index c0497041813..116ce2bf51d 100644 --- a/src/librustc_trans/trans/glue.rs +++ b/src/librustc_trans/trans/glue.rs @@ -531,13 +531,14 @@ fn declare_generic_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, return (fn_nm, llfn); } -fn make_generic_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, - t: Ty<'tcx>, - llfn: ValueRef, - helper: for<'blk> |Block<'blk, 'tcx>, ValueRef, Ty<'tcx>| - -> Block<'blk, 'tcx>, - name: &str) - -> ValueRef { +fn make_generic_glue<'a, 'tcx, F>(ccx: &CrateContext<'a, 'tcx>, + t: Ty<'tcx>, + llfn: ValueRef, + helper: F, + name: &str) + -> ValueRef where + F: for<'blk> FnOnce(Block<'blk, 'tcx>, ValueRef, Ty<'tcx>) -> Block<'blk, 'tcx>, +{ let _icx = push_ctxt("make_generic_glue"); let glue_name = format!("glue {} {}", name, ty_to_short_str(ccx.tcx(), t)); let _s = StatRecorder::new(ccx, glue_name); diff --git a/src/librustc_trans/trans/tvec.rs b/src/librustc_trans/trans/tvec.rs index de71a1c2217..e3288466aa7 100644 --- a/src/librustc_trans/trans/tvec.rs +++ b/src/librustc_trans/trans/tvec.rs @@ -416,15 +416,14 @@ pub fn get_base_and_len(bcx: Block, } } -pub type iter_vec_block<'a, 'blk, 'tcx> = - |Block<'blk, 'tcx>, ValueRef, Ty<'tcx>|: 'a -> Block<'blk, 'tcx>; - -pub fn iter_vec_loop<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, +pub fn iter_vec_loop<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>, data_ptr: ValueRef, vt: &VecTypes<'tcx>, count: ValueRef, - f: iter_vec_block<'a, 'blk, 'tcx>) - -> Block<'blk, 'tcx> { + f: F) + -> Block<'blk, 'tcx> where + F: FnOnce(Block<'blk, 'tcx>, ValueRef, Ty<'tcx>) -> Block<'blk, 'tcx>, +{ let _icx = push_ctxt("tvec::iter_vec_loop"); let fcx = bcx.fcx; @@ -475,12 +474,14 @@ pub fn iter_vec_loop<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, next_bcx } -pub fn iter_vec_raw<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - data_ptr: ValueRef, - unit_ty: Ty<'tcx>, - len: ValueRef, - f: iter_vec_block<'a, 'blk, 'tcx>) - -> Block<'blk, 'tcx> { +pub fn iter_vec_raw<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>, + data_ptr: ValueRef, + unit_ty: Ty<'tcx>, + len: ValueRef, + f: F) + -> Block<'blk, 'tcx> where + F: FnOnce(Block<'blk, 'tcx>, ValueRef, Ty<'tcx>) -> Block<'blk, 'tcx>, +{ let _icx = push_ctxt("tvec::iter_vec_raw"); let fcx = bcx.fcx;