Skip to content

Commit

Permalink
rustc: don't keep a second reference to the HIR map in middle::region.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed May 13, 2017
1 parent ea1c6df commit 6da4123
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1170,37 +1168,38 @@ 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
// lifetime parameters free in this body.
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)
}
Expand Down

0 comments on commit 6da4123

Please sign in to comment.