diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2017-05-11 17:18:23 +0300 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2017-05-13 17:43:32 +0300 |
| commit | 6da4123f5f819608fce49258bfa4f74fe195806b (patch) | |
| tree | 85d40def54bccac6a6d7bf5c177fc9f0888115f3 /src | |
| parent | ea1c6df81eecad62ca25191042b7871291162933 (diff) | |
| download | rust-6da4123f5f819608fce49258bfa4f74fe195806b.tar.gz rust-6da4123f5f819608fce49258bfa4f74fe195806b.zip | |
rustc: don't keep a second reference to the HIR map in middle::region.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/middle/region.rs | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 331683381a4..2d632e3feb5 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -264,12 +264,10 @@ struct RegionResolutionVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, // Generated maps: - region_maps: &'a mut RegionMaps, + region_maps: RegionMaps, cx: Context, - map: &'a hir_map::Map<'tcx>, - /// `terminating_scopes` is a set containing the ids of each /// statement, or conditional/repeating expression. These scopes /// are calling "terminating scopes" because, when attempting to @@ -1105,7 +1103,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> { fn visit_body(&mut self, body: &'tcx hir::Body) { let body_id = body.id(); - let owner_id = self.map.body_owner(body_id); + let owner_id = self.tcx.hir.body_owner(body_id); debug!("visit_body(id={:?}, span={:?}, body.id={:?}, cx.parent={:?})", owner_id, @@ -1170,11 +1168,20 @@ fn region_maps<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) return tcx.region_maps(closure_base_def_id); } - let mut maps = RegionMaps::new(); - let id = tcx.hir.as_local_node_id(def_id).unwrap(); - if let Some(body) = tcx.hir.maybe_body_owned_by(id) { - maps.root_body = Some(body); + let maps = if let Some(body) = tcx.hir.maybe_body_owned_by(id) { + let mut visitor = RegionResolutionVisitor { + tcx, + region_maps: RegionMaps::new(), + cx: Context { + root_id: None, + parent: None, + var_parent: None, + }, + terminating_scopes: NodeSet(), + }; + + visitor.region_maps.root_body = Some(body); // If the item is an associated const or a method, // record its impl/trait parent, as it can also have @@ -1182,25 +1189,17 @@ fn region_maps<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) match tcx.hir.get(id) { hir::map::NodeImplItem(_) | hir::map::NodeTraitItem(_) => { - maps.root_parent = Some(tcx.hir.get_parent(id)); + visitor.region_maps.root_parent = Some(tcx.hir.get_parent(id)); } _ => {} } - let mut visitor = RegionResolutionVisitor { - tcx: tcx, - region_maps: &mut maps, - map: &tcx.hir, - cx: Context { - root_id: None, - parent: None, - var_parent: None, - }, - terminating_scopes: NodeSet(), - }; - visitor.visit_body(tcx.hir.body(body)); - } + + visitor.region_maps + } else { + RegionMaps::new() + }; Rc::new(maps) } |
