From 0ac8542abc0a2497cda02dcc0544c0da6f46644f Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 8 Nov 2017 08:50:44 -0500 Subject: [PATCH] make `mk_closure` take a `ClosureSubsts` --- src/librustc/infer/freshen.rs | 2 +- src/librustc/ty/context.rs | 8 +++----- src/librustc_typeck/check/closure.rs | 4 ++-- src/librustc_typeck/collect.rs | 21 +++++++++++++-------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/librustc/infer/freshen.rs b/src/librustc/infer/freshen.rs index 6d1ede8f1a5..c4727c820b1 100644 --- a/src/librustc/infer/freshen.rs +++ b/src/librustc/infer/freshen.rs @@ -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); (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 }) ) } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 22a3edd200c..a3fe8398de2 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1981,11 +1981,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn mk_closure(self, closure_id: DefId, - substs: &'tcx Substs<'tcx>) - -> Ty<'tcx> { - self.mk_closure_from_closure_substs(closure_id, ClosureSubsts { - substs, - }) + substs: ClosureSubsts<'tcx>) + -> Ty<'tcx> { + self.mk_closure_from_closure_substs(closure_id, substs) } pub fn mk_closure_from_closure_substs(self, diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 90c4654dac9..1f96afe3ac8 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -103,11 +103,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { .next_ty_var(TypeVariableOrigin::ClosureSynthetic(expr.span)) }, ); + let substs = ty::ClosureSubsts { substs }; let closure_type = self.tcx.mk_closure(expr_def_id, substs); if let Some(interior) = interior { - let closure_substs = ty::ClosureSubsts { substs: substs }; - return self.tcx.mk_generator(expr_def_id, closure_substs, interior); + return self.tcx.mk_generator(expr_def_id, substs, interior); } debug!( diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 9ee3300e753..8365081f5a7 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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); } - tcx.mk_closure(def_id, Substs::for_item( - tcx, def_id, - |def, _| { - let region = def.to_early_bound_region_data(); - tcx.mk_region(ty::ReEarlyBound(region)) - }, - |def, _| tcx.mk_param_from_def(def) - )) + let substs = ty::ClosureSubsts { + substs: Substs::for_item( + tcx, + def_id, + |def, _| { + let region = def.to_early_bound_region_data(); + 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)) {