Skip to content
12 changes: 8 additions & 4 deletions src/librustc/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ use syntax::ast;
use syntax::ptr::P;

use hir::{self, PatKind};
use hir::def_id::DefId;

struct CFGBuilder<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
owner_def_id: DefId,
tables: &'a ty::TypeckTables<'tcx>,
graph: CFGGraph,
fn_exit: CFGIndex,
Expand Down Expand Up @@ -56,6 +58,7 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

let mut cfg_builder = CFGBuilder {
tcx: tcx,
owner_def_id,
tables: tables,
graph: graph,
fn_exit: fn_exit,
Expand Down Expand Up @@ -583,11 +586,12 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
scope_id: ast::NodeId,
to_index: CFGIndex) {
let mut data = CFGEdgeData { exiting_scopes: vec![] };
let mut scope = self.tcx.region_maps.node_extent(from_expr.id);
let target_scope = self.tcx.region_maps.node_extent(scope_id);
let mut scope = self.tcx.node_extent(from_expr.id);
let target_scope = self.tcx.node_extent(scope_id);
let region_maps = self.tcx.region_maps(self.owner_def_id);
while scope != target_scope {
data.exiting_scopes.push(scope.node_id(&self.tcx.region_maps));
scope = self.tcx.region_maps.encl_scope(scope);
data.exiting_scopes.push(scope.node_id());
scope = region_maps.encl_scope(scope);
}
self.graph.add_edge(from_index, to_index, data);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum DepNode<D: Clone + Debug> {
WorkProduct(Arc<WorkProductId>),

// Represents different phases in the compiler.
RegionResolveCrate,
RegionMaps(D),
Coherence,
Resolve,
CoherenceCheckTrait(D),
Expand Down Expand Up @@ -197,7 +197,6 @@ impl<D: Clone + Debug> DepNode<D> {
BorrowCheckKrate => Some(BorrowCheckKrate),
MirKrate => Some(MirKrate),
TypeckBodiesKrate => Some(TypeckBodiesKrate),
RegionResolveCrate => Some(RegionResolveCrate),
Coherence => Some(Coherence),
Resolve => Some(Resolve),
Variance => Some(Variance),
Expand All @@ -223,6 +222,7 @@ impl<D: Clone + Debug> DepNode<D> {
def_ids.map(MirShim)
}
BorrowCheck(ref d) => op(d).map(BorrowCheck),
RegionMaps(ref d) => op(d).map(RegionMaps),
RvalueCheck(ref d) => op(d).map(RvalueCheck),
TransCrateItem(ref d) => op(d).map(TransCrateItem),
TransInlinedItem(ref d) => op(d).map(TransInlinedItem),
Expand Down
19 changes: 18 additions & 1 deletion src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use syntax::codemap::Spanned;
use syntax_pos::Span;
use hir::*;
use hir::def::Def;
use hir::map::Map;
use hir::map::{self, Map};
use super::itemlikevisit::DeepVisitor;

use std::cmp;
Expand Down Expand Up @@ -140,6 +140,23 @@ impl<'this, 'tcx> NestedVisitorMap<'this, 'tcx> {
/// to monitor future changes to `Visitor` in case a new method with a
/// new default implementation gets introduced.)
pub trait Visitor<'v> : Sized {
/// Invokes the suitable visitor method for the given `Node`
/// extracted from the hir map.
fn visit_hir_map_node(&mut self, node: map::Node<'v>) {
match node {
map::NodeItem(a) => self.visit_item(a),
map::NodeForeignItem(a) => self.visit_foreign_item(a),
map::NodeTraitItem(a) => self.visit_trait_item(a),
map::NodeImplItem(a) => self.visit_impl_item(a),
map::NodeExpr(a) => self.visit_expr(a),
map::NodeStmt(a) => self.visit_stmt(a),
map::NodeTy(a) => self.visit_ty(a),
map::NodePat(a) => self.visit_pat(a),
map::NodeBlock(a) => self.visit_block(a),
_ => bug!("Visitor::visit_hir_map_node() not yet impl for node `{:?}`", node)
}
}

///////////////////////////////////////////////////////////////////////////
// Nested items.

Expand Down
15 changes: 2 additions & 13 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::subst::Kind<'t
}
}

impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::Region {
impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::RegionKind<'tcx> {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a, 'tcx>,
hasher: &mut StableHasher<W>) {
Expand Down Expand Up @@ -432,17 +432,6 @@ impl_stable_hash_for!(enum ty::cast::CastKind {
FnPtrAddrCast
});

impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ::middle::region::CodeExtent
{
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a, 'tcx>,
hasher: &mut StableHasher<W>) {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
hcx.tcx().region_maps.code_extent_data(*self).hash_stable(hcx, hasher);
});
}
}

impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ::middle::region::CodeExtentData
{
fn hash_stable<W: StableHasherResult>(&self,
Expand Down Expand Up @@ -477,7 +466,7 @@ impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
custom_kind
});

impl_stable_hash_for!(struct ty::FreeRegion {
impl_stable_hash_for!(struct ty::FreeRegion<'tcx> {
scope,
bound_region
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl<'cx, 'gcx, 'tcx> ty::fold::TypeFolder<'gcx, 'tcx> for Generalizer<'cx, 'gcx
}
}

fn fold_region(&mut self, r: &'tcx ty::Region) -> &'tcx ty::Region {
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r {
// Never make variables for regions bound within the type itself,
// nor for erased regions.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/equate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
}
}

fn regions(&mut self, a: &'tcx ty::Region, b: &'tcx ty::Region)
-> RelateResult<'tcx, &'tcx ty::Region> {
fn regions(&mut self, a: ty::Region<'tcx>, b: ty::Region<'tcx>)
-> RelateResult<'tcx, ty::Region<'tcx>> {
debug!("{}.regions({:?}, {:?})",
self.tag(),
a,
Expand Down
20 changes: 11 additions & 9 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ use traits::{ObligationCause, ObligationCauseCode};
use ty::{self, TyCtxt, TypeFoldable};
use ty::{Region, Issue32330};
use ty::error::TypeError;
use syntax::ast::DUMMY_NODE_ID;
use syntax_pos::{Pos, Span};
use errors::{DiagnosticBuilder, DiagnosticStyledString};

Expand All @@ -78,7 +79,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn note_and_explain_region(self,
err: &mut DiagnosticBuilder,
prefix: &str,
region: &'tcx ty::Region,
region: ty::Region<'tcx>,
suffix: &str) {
fn item_scope_tag(item: &hir::Item) -> &'static str {
match item.node {
Expand Down Expand Up @@ -123,14 +124,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
format!("{}unknown scope: {:?}{}. Please report a bug.",
prefix, scope, suffix)
};
let span = match scope.span(&self.region_maps, &self.hir) {
let span = match scope.span(&self.hir) {
Some(s) => s,
None => {
err.note(&unknown_scope());
return;
}
};
let tag = match self.hir.find(scope.node_id(&self.region_maps)) {
let tag = match self.hir.find(scope.node_id()) {
Some(hir_map::NodeBlock(_)) => "block",
Some(hir_map::NodeExpr(expr)) => match expr.node {
hir::ExprCall(..) => "call",
Expand All @@ -150,7 +151,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
return;
}
};
let scope_decorated_tag = match self.region_maps.code_extent_data(scope) {
let scope_decorated_tag = match *scope {
region::CodeExtentData::Misc(_) => tag,
region::CodeExtentData::CallSiteScope { .. } => {
"scope of call-site for function"
Expand Down Expand Up @@ -183,7 +184,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
};

let node = fr.scope.node_id(&self.region_maps);
let node = fr.scope.map(|s| s.node_id())
.unwrap_or(DUMMY_NODE_ID);
let unknown;
let tag = match self.hir.find(node) {
Some(hir_map::NodeBlock(_)) |
Expand Down Expand Up @@ -515,7 +517,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
values.1.push_normal("<");
}

fn lifetime_display(lifetime: &Region) -> String {
fn lifetime_display(lifetime: Region) -> String {
let s = format!("{}", lifetime);
if s.is_empty() {
"'_".to_string()
Expand Down Expand Up @@ -767,7 +769,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
fn report_generic_bound_failure(&self,
origin: SubregionOrigin<'tcx>,
bound_kind: GenericKind<'tcx>,
sub: &'tcx Region)
sub: Region<'tcx>)
{
// FIXME: it would be better to report the first error message
// with the span of the parameter itself, rather than the span
Expand Down Expand Up @@ -846,9 +848,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
fn report_sub_sup_conflict(&self,
var_origin: RegionVariableOrigin,
sub_origin: SubregionOrigin<'tcx>,
sub_region: &'tcx Region,
sub_region: Region<'tcx>,
sup_origin: SubregionOrigin<'tcx>,
sup_region: &'tcx Region) {
sup_region: Region<'tcx>) {
let mut err = self.report_inference_failure(var_origin);

self.tcx.note_and_explain_region(&mut err,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {

pub(super) fn report_concrete_failure(&self,
origin: SubregionOrigin<'tcx>,
sub: &'tcx Region,
sup: &'tcx Region)
sub: Region<'tcx>,
sup: Region<'tcx>)
-> DiagnosticBuilder<'tcx> {
match origin {
infer::Subtype(trace) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
self.infcx.tcx
}

fn fold_region(&mut self, r: &'tcx ty::Region) -> &'tcx ty::Region {
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r {
ty::ReEarlyBound(..) |
ty::ReLateBound(..) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/fudge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionFudger<'a, 'gcx, 'tcx> {
}
}

fn fold_region(&mut self, r: &'tcx ty::Region) -> &'tcx ty::Region {
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r {
ty::ReVar(v) if self.region_vars.contains(&v) => {
self.infcx.next_region_var(self.origin.clone())
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/glb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
lattice::super_lattice_tys(self, a, b)
}

fn regions(&mut self, a: &'tcx ty::Region, b: &'tcx ty::Region)
-> RelateResult<'tcx, &'tcx ty::Region> {
fn regions(&mut self, a: ty::Region<'tcx>, b: ty::Region<'tcx>)
-> RelateResult<'tcx, ty::Region<'tcx>> {
debug!("{}.regions({:?}, {:?})",
self.tag(),
a,
Expand Down
32 changes: 16 additions & 16 deletions src/librustc/infer/higher_ranked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
snapshot: &CombinedSnapshot,
debruijn: ty::DebruijnIndex,
new_vars: &[ty::RegionVid],
a_map: &FxHashMap<ty::BoundRegion, &'tcx ty::Region>,
r0: &'tcx ty::Region)
-> &'tcx ty::Region {
a_map: &FxHashMap<ty::BoundRegion, ty::Region<'tcx>>,
r0: ty::Region<'tcx>)
-> ty::Region<'tcx> {
// Regions that pre-dated the LUB computation stay as they are.
if !is_var_in_set(new_vars, r0) {
assert!(!r0.is_bound());
Expand All @@ -284,7 +284,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
// Variables created during LUB computation which are
// *related* to regions that pre-date the LUB computation
// stay as they are.
if !tainted.iter().all(|r| is_var_in_set(new_vars, *r)) {
if !tainted.iter().all(|&r| is_var_in_set(new_vars, r)) {
debug!("generalize_region(r0={:?}): \
non-new-variables found in {:?}",
r0, tainted);
Expand Down Expand Up @@ -365,11 +365,11 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
snapshot: &CombinedSnapshot,
debruijn: ty::DebruijnIndex,
new_vars: &[ty::RegionVid],
a_map: &FxHashMap<ty::BoundRegion, &'tcx ty::Region>,
a_map: &FxHashMap<ty::BoundRegion, ty::Region<'tcx>>,
a_vars: &[ty::RegionVid],
b_vars: &[ty::RegionVid],
r0: &'tcx ty::Region)
-> &'tcx ty::Region {
r0: ty::Region<'tcx>)
-> ty::Region<'tcx> {
if !is_var_in_set(new_vars, r0) {
assert!(!r0.is_bound());
return r0;
Expand Down Expand Up @@ -434,8 +434,8 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {

fn rev_lookup<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
span: Span,
a_map: &FxHashMap<ty::BoundRegion, &'tcx ty::Region>,
r: &'tcx ty::Region) -> &'tcx ty::Region
a_map: &FxHashMap<ty::BoundRegion, ty::Region<'tcx>>,
r: ty::Region<'tcx>) -> ty::Region<'tcx>
{
for (a_br, a_r) in a_map {
if *a_r == r {
Expand All @@ -450,14 +450,14 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {

fn fresh_bound_variable<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
debruijn: ty::DebruijnIndex)
-> &'tcx ty::Region {
-> ty::Region<'tcx> {
infcx.region_vars.new_bound(debruijn)
}
}
}

fn var_ids<'a, 'gcx, 'tcx>(fields: &CombineFields<'a, 'gcx, 'tcx>,
map: &FxHashMap<ty::BoundRegion, &'tcx ty::Region>)
map: &FxHashMap<ty::BoundRegion, ty::Region<'tcx>>)
-> Vec<ty::RegionVid> {
map.iter()
.map(|(_, &r)| match *r {
Expand All @@ -472,7 +472,7 @@ fn var_ids<'a, 'gcx, 'tcx>(fields: &CombineFields<'a, 'gcx, 'tcx>,
.collect()
}

fn is_var_in_set(new_vars: &[ty::RegionVid], r: &ty::Region) -> bool {
fn is_var_in_set(new_vars: &[ty::RegionVid], r: ty::Region) -> bool {
match *r {
ty::ReVar(ref v) => new_vars.iter().any(|x| x == v),
_ => false
Expand All @@ -484,7 +484,7 @@ fn fold_regions_in<'a, 'gcx, 'tcx, T, F>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
mut fldr: F)
-> T
where T: TypeFoldable<'tcx>,
F: FnMut(&'tcx ty::Region, ty::DebruijnIndex) -> &'tcx ty::Region,
F: FnMut(ty::Region<'tcx>, ty::DebruijnIndex) -> ty::Region<'tcx>,
{
tcx.fold_regions(unbound_value, &mut false, |region, current_depth| {
// we should only be encountering "escaping" late-bound regions here,
Expand All @@ -502,9 +502,9 @@ fn fold_regions_in<'a, 'gcx, 'tcx, T, F>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
fn tainted_regions(&self,
snapshot: &CombinedSnapshot,
r: &'tcx ty::Region,
r: ty::Region<'tcx>,
directions: TaintDirections)
-> FxHashSet<&'tcx ty::Region> {
-> FxHashSet<ty::Region<'tcx>> {
self.region_vars.tainted(&snapshot.region_vars_snapshot, r, directions)
}

Expand Down Expand Up @@ -731,7 +731,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// region back to the `ty::BoundRegion` that it originally
// represented. Because `leak_check` passed, we know that
// these taint sets are mutually disjoint.
let inv_skol_map: FxHashMap<&'tcx ty::Region, ty::BoundRegion> =
let inv_skol_map: FxHashMap<ty::Region<'tcx>, ty::BoundRegion> =
skol_map
.iter()
.flat_map(|(&skol_br, &skol)| {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/lub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
lattice::super_lattice_tys(self, a, b)
}

fn regions(&mut self, a: &'tcx ty::Region, b: &'tcx ty::Region)
-> RelateResult<'tcx, &'tcx ty::Region> {
fn regions(&mut self, a: ty::Region<'tcx>, b: ty::Region<'tcx>)
-> RelateResult<'tcx, ty::Region<'tcx>> {
debug!("{}.regions({:?}, {:?})",
self.tag(),
a,
Expand Down
Loading