1
Fork 0

make mk_closure take a ClosureSubsts

This commit is contained in:
Niko Matsakis 2017-11-08 08:50:44 -05:00
parent 3349e7bb45
commit 0ac8542abc
4 changed files with 19 additions and 16 deletions

View file

@ -256,7 +256,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
let closure_sig = this.infcx.fn_sig(def_id); let closure_sig = this.infcx.fn_sig(def_id);
(tcx.mk_fn_ptr(closure_sig.fold_with(this)), tcx.types.char) (tcx.mk_fn_ptr(closure_sig.fold_with(this)), tcx.types.char)
}, },
|substs| tcx.mk_closure(def_id, substs) |substs| tcx.mk_closure(def_id, ty::ClosureSubsts { substs })
) )
} }

View file

@ -1981,11 +1981,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn mk_closure(self, pub fn mk_closure(self,
closure_id: DefId, closure_id: DefId,
substs: &'tcx Substs<'tcx>) substs: ClosureSubsts<'tcx>)
-> Ty<'tcx> { -> Ty<'tcx> {
self.mk_closure_from_closure_substs(closure_id, ClosureSubsts { self.mk_closure_from_closure_substs(closure_id, substs)
substs,
})
} }
pub fn mk_closure_from_closure_substs(self, pub fn mk_closure_from_closure_substs(self,

View file

@ -103,11 +103,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
.next_ty_var(TypeVariableOrigin::ClosureSynthetic(expr.span)) .next_ty_var(TypeVariableOrigin::ClosureSynthetic(expr.span))
}, },
); );
let substs = ty::ClosureSubsts { substs };
let closure_type = self.tcx.mk_closure(expr_def_id, substs); let closure_type = self.tcx.mk_closure(expr_def_id, substs);
if let Some(interior) = interior { if let Some(interior) = interior {
let closure_substs = ty::ClosureSubsts { substs: substs }; return self.tcx.mk_generator(expr_def_id, substs, interior);
return self.tcx.mk_generator(expr_def_id, closure_substs, interior);
} }
debug!( debug!(

View file

@ -1163,14 +1163,19 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
return tcx.typeck_tables_of(def_id).node_id_to_type(hir_id); return tcx.typeck_tables_of(def_id).node_id_to_type(hir_id);
} }
tcx.mk_closure(def_id, Substs::for_item( let substs = ty::ClosureSubsts {
tcx, def_id, substs: Substs::for_item(
|def, _| { tcx,
let region = def.to_early_bound_region_data(); def_id,
tcx.mk_region(ty::ReEarlyBound(region)) |def, _| {
}, let region = def.to_early_bound_region_data();
|def, _| tcx.mk_param_from_def(def) tcx.mk_region(ty::ReEarlyBound(region))
)) },
|def, _| tcx.mk_param_from_def(def)
)
};
tcx.mk_closure(def_id, substs)
} }
NodeExpr(_) => match tcx.hir.get(tcx.hir.get_parent_node(node_id)) { NodeExpr(_) => match tcx.hir.get(tcx.hir.get_parent_node(node_id)) {