Skip to content

Commit 24b4922

Browse files
author
Jorge Aparicio
committed
rustc_trans: unbox closures used in function arguments
1 parent 5de9f47 commit 24b4922

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/librustc_trans/trans/expr.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,16 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
299299
// into a type to be destructed. If we want to end up with a Box pointer,
300300
// then mk_ty should make a Box pointer (T -> Box<T>), if we want a
301301
// borrowed reference then it should be T -> &T.
302-
// FIXME(#19596) unbox `mk_ty`
303-
fn unsized_info<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
304-
kind: &ty::UnsizeKind<'tcx>,
305-
id: ast::NodeId,
306-
unadjusted_ty: Ty<'tcx>,
307-
mk_ty: |Ty<'tcx>| -> Ty<'tcx>) -> ValueRef {
302+
fn unsized_info<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
303+
kind: &ty::UnsizeKind<'tcx>,
304+
id: ast::NodeId,
305+
unadjusted_ty: Ty<'tcx>,
306+
mk_ty: F) -> ValueRef where
307+
F: FnOnce(Ty<'tcx>) -> Ty<'tcx>,
308+
{
309+
// FIXME(#19596) workaround: `|t| t` causes monomorphization recursion
310+
fn identity<T>(t: T) -> T { t }
311+
308312
debug!("unsized_info(kind={}, id={}, unadjusted_ty={})",
309313
kind, id, unadjusted_ty.repr(bcx.tcx()));
310314
match kind {
@@ -314,7 +318,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
314318
let ty_substs = substs.types.get_slice(subst::TypeSpace);
315319
// The dtor for a field treats it like a value, so mk_ty
316320
// should just be the identity function.
317-
unsized_info(bcx, k, id, ty_substs[tp_index], |t| t)
321+
unsized_info(bcx, k, id, ty_substs[tp_index], identity)
318322
}
319323
_ => bcx.sess().bug(format!("UnsizeStruct with bad sty: {}",
320324
bcx.ty_to_string(unadjusted_ty))[])

0 commit comments

Comments
 (0)