From 9809fe0d021ebed29d13a4f7fa58c660107da384 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 7 May 2017 16:49:03 +0300 Subject: [PATCH] rustc: use call_site_extent for closure environment free regions. --- src/librustc/middle/mem_categorization.rs | 16 +--------------- src/librustc_mir/build/mod.rs | 2 +- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 11a364f92c31..c489689d588f 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -785,26 +785,12 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { cmt_result: cmt_<'tcx>) -> cmt_<'tcx> { - // Look up the node ID of the closure body so we can construct - // a free region within it - let fn_body_id = { - let fn_expr = match self.tcx().hir.find(upvar_id.closure_expr_id) { - Some(hir_map::NodeExpr(e)) => e, - _ => bug!() - }; - - match fn_expr.node { - hir::ExprClosure(.., body_id, _) => body_id, - _ => bug!() - } - }; - // Region of environment pointer let env_region = self.tcx().mk_region(ty::ReFree(ty::FreeRegion { // The environment of a closure is guaranteed to // outlive any bindings introduced in the body of the // closure itself. - scope: Some(self.tcx().item_extent(fn_body_id.node_id)), + scope: Some(self.tcx().call_site_extent(upvar_id.closure_expr_id)), bound_region: ty::BrEnv })); diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 1634aade0bcf..cecfd6e4c242 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -207,7 +207,7 @@ fn closure_self_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let closure_ty = tcx.body_tables(body_id).node_id_to_type(closure_expr_id); let region = ty::ReFree(ty::FreeRegion { - scope: Some(tcx.item_extent(body_id.node_id)), + scope: Some(tcx.call_site_extent(closure_expr_id)), bound_region: ty::BoundRegion::BrEnv, }); let region = tcx.mk_region(region);