Skip to content

Commit be0ef94

Browse files
cramertjnikomatsakis
authored andcommitted
Fix all errors except error_reporting and cfg construction
1 parent 30df69e commit be0ef94

File tree

4 files changed

+48
-29
lines changed

4 files changed

+48
-29
lines changed

src/librustc/infer/region_inference/mod.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
958958
// subtype of the region corresponding to an inner
959959
// block.
960960
self.tcx.mk_region(ReScope(
961-
self.tcx.region_maps().nearest_common_ancestor(a_id, b_id)))
961+
self.tcx.region_maps(node_id).nearest_common_ancestor(a_id, b_id)))
962962
}
963963

964964
(&ReFree(_), &ReFree(_)) => {
@@ -1011,9 +1011,9 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
10111011

10121012
let graph = self.construct_graph();
10131013
self.expand_givens(&graph);
1014-
self.expansion(free_regions, &mut var_data);
1015-
self.collect_errors(free_regions, &mut var_data, errors);
1016-
self.collect_var_errors(free_regions, &var_data, &graph, errors);
1014+
self.expansion(free_regions, &mut var_data, subject);
1015+
self.collect_errors(free_regions, &mut var_data, errors, subject);
1016+
self.collect_var_errors(free_regions, &var_data, &graph, errors, subject);
10171017
var_data
10181018
}
10191019

@@ -1063,14 +1063,14 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
10631063
match *constraint {
10641064
ConstrainRegSubVar(a_region, b_vid) => {
10651065
let b_data = &mut var_values[b_vid.index as usize];
1066-
self.expand_node(free_regions, a_region, b_vid, b_data)
1066+
self.expand_node(free_regions, a_region, b_vid, b_data, node_id)
10671067
}
10681068
ConstrainVarSubVar(a_vid, b_vid) => {
10691069
match var_values[a_vid.index as usize] {
10701070
ErrorValue => false,
10711071
Value(a_region) => {
10721072
let b_node = &mut var_values[b_vid.index as usize];
1073-
self.expand_node(free_regions, a_region, b_vid, b_node)
1073+
self.expand_node(free_regions, a_region, b_vid, b_node, node_id)
10741074
}
10751075
}
10761076
}
@@ -1088,7 +1088,8 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
10881088
free_regions: &FreeRegionMap<'tcx>,
10891089
a_region: Region<'tcx>,
10901090
b_vid: RegionVid,
1091-
b_data: &mut VarValue<'tcx>)
1091+
b_data: &mut VarValue<'tcx>,
1092+
node_id: ast::NodeId)
10921093
-> bool {
10931094
debug!("expand_node({:?}, {:?} == {:?})",
10941095
a_region,
@@ -1108,7 +1109,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
11081109

11091110
match *b_data {
11101111
Value(cur_region) => {
1111-
let lub = self.lub_concrete_regions(free_regions, a_region, cur_region);
1112+
let lub = self.lub_concrete_regions(free_regions, a_region, cur_region, node_id);
11121113
if lub == cur_region {
11131114
return false;
11141115
}
@@ -1134,7 +1135,8 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
11341135
fn collect_errors(&self,
11351136
free_regions: &FreeRegionMap<'tcx>,
11361137
var_data: &mut Vec<VarValue<'tcx>>,
1137-
errors: &mut Vec<RegionResolutionError<'tcx>>) {
1138+
errors: &mut Vec<RegionResolutionError<'tcx>>,
1139+
node_id: ast::NodeId) {
11381140
let constraints = self.constraints.borrow();
11391141
for (constraint, origin) in constraints.iter() {
11401142
debug!("collect_errors: constraint={:?} origin={:?}",
@@ -1146,7 +1148,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
11461148
}
11471149

11481150
ConstrainRegSubReg(sub, sup) => {
1149-
if free_regions.is_subregion_of(self.tcx, sub, sup) {
1151+
if free_regions.is_subregion_of(self.tcx, sub, sup, node_id) {
11501152
continue;
11511153
}
11521154

@@ -1174,7 +1176,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
11741176
// Do not report these errors immediately:
11751177
// instead, set the variable value to error and
11761178
// collect them later.
1177-
if !free_regions.is_subregion_of(self.tcx, a_region, b_region) {
1179+
if !free_regions.is_subregion_of(self.tcx, a_region, b_region, node_id) {
11781180
debug!("collect_errors: region error at {:?}: \
11791181
cannot verify that {:?}={:?} <= {:?}",
11801182
origin,
@@ -1190,7 +1192,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
11901192
for verify in self.verifys.borrow().iter() {
11911193
debug!("collect_errors: verify={:?}", verify);
11921194
let sub = normalize(self.tcx, var_data, verify.region);
1193-
if verify.bound.is_met(self.tcx, free_regions, var_data, sub) {
1195+
if verify.bound.is_met(self.tcx, free_regions, var_data, sub, node_id) {
11941196
continue;
11951197
}
11961198

@@ -1212,7 +1214,8 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
12121214
free_regions: &FreeRegionMap<'tcx>,
12131215
var_data: &[VarValue<'tcx>],
12141216
graph: &RegionGraph<'tcx>,
1215-
errors: &mut Vec<RegionResolutionError<'tcx>>) {
1217+
errors: &mut Vec<RegionResolutionError<'tcx>>,
1218+
node_id: ast::NodeId) {
12161219
debug!("collect_var_errors");
12171220

12181221
// This is the best way that I have found to suppress
@@ -1262,7 +1265,8 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
12621265
graph,
12631266
&mut dup_vec,
12641267
node_vid,
1265-
errors);
1268+
errors,
1269+
node_id);
12661270
}
12671271
}
12681272
}
@@ -1315,7 +1319,8 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
13151319
graph: &RegionGraph<'tcx>,
13161320
dup_vec: &mut [u32],
13171321
node_idx: RegionVid,
1318-
errors: &mut Vec<RegionResolutionError<'tcx>>) {
1322+
errors: &mut Vec<RegionResolutionError<'tcx>>,
1323+
node_id: ast::NodeId) {
13191324
// Errors in expanding nodes result from a lower-bound that is
13201325
// not contained by an upper-bound.
13211326
let (mut lower_bounds, lower_dup) = self.collect_concrete_regions(graph,
@@ -1347,7 +1352,9 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
13471352

13481353
for lower_bound in &lower_bounds {
13491354
for upper_bound in &upper_bounds {
1350-
if !free_regions.is_subregion_of(self.tcx, lower_bound.region, upper_bound.region) {
1355+
if !free_regions.is_subregion_of(
1356+
self.tcx, lower_bound.region, upper_bound.region, node_id)
1357+
{
13511358
let origin = (*self.var_origins.borrow())[node_idx.index as usize].clone();
13521359
debug!("region inference error at {:?} for {:?}: SubSupConflict sub: {:?} \
13531360
sup: {:?}",
@@ -1600,20 +1607,20 @@ impl<'a, 'gcx, 'tcx> VerifyBound<'tcx> {
16001607
&VerifyBound::AnyRegion(ref rs) =>
16011608
rs.iter()
16021609
.map(|&r| normalize(tcx, var_values, r))
1603-
.any(|r| free_regions.is_subregion_of(tcx, min, r)),
1610+
.any(|r| free_regions.is_subregion_of(tcx, min, r, node_id)),
16041611

16051612
&VerifyBound::AllRegions(ref rs) =>
16061613
rs.iter()
16071614
.map(|&r| normalize(tcx, var_values, r))
1608-
.all(|r| free_regions.is_subregion_of(tcx, min, r)),
1615+
.all(|r| free_regions.is_subregion_of(tcx, min, r, node_id)),
16091616

16101617
&VerifyBound::AnyBound(ref bs) =>
16111618
bs.iter()
1612-
.any(|b| b.is_met(tcx, free_regions, var_values, min)),
1619+
.any(|b| b.is_met(tcx, free_regions, var_values, min, node_id)),
16131620

16141621
&VerifyBound::AllBounds(ref bs) =>
16151622
bs.iter()
1616-
.all(|b| b.is_met(tcx, free_regions, var_values, min)),
1623+
.all(|b| b.is_met(tcx, free_regions, var_values, min, node_id)),
16171624
}
16181625
}
16191626
}

src/librustc/middle/free_region.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ty::{self, Lift, TyCtxt, Region};
1919
use ty::wf::ImpliedBound;
2020
use rustc_data_structures::transitive_relation::TransitiveRelation;
21+
use syntax::ast::NodeId;
2122

2223
#[derive(Clone, RustcEncodable, RustcDecodable)]
2324
pub struct FreeRegionMap<'tcx> {
@@ -131,7 +132,7 @@ impl<'tcx> FreeRegionMap<'tcx> {
131132
true,
132133

133134
(&ty::ReScope(sub_scope), &ty::ReScope(super_scope)) =>
134-
tcx.region_maps().is_subscope_of(sub_scope, super_scope),
135+
tcx.region_maps(node_id).is_subscope_of(sub_scope, super_scope),
135136

136137
(&ty::ReScope(sub_scope), &ty::ReFree(fr)) => {
137138
// 1. It is safe to unwrap `fr.scope` because we

src/librustc/middle/region.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,23 +1170,29 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> {
11701170
}
11711171
}
11721172

1173-
pub fn resolve_crate<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
1174-
1175-
struct CrateResolutionVisitor<'a, 'tcx: 'a>(TyCtxt<'a, 'tcx, 'tcx>);
1173+
pub fn resolve_crate<'a, 'gcx: 'a+'tcx, 'tcx: 'a, F>(tcx: TyCtxt<'a, 'gcx, 'tcx>, f: F)
1174+
where F: FnMut(DefId, Rc<RegionMaps>) -> ()
1175+
{
1176+
struct CrateResolutionVisitor<'a, 'gcx: 'a+'tcx, 'tcx: 'a, F>(TyCtxt<'a, 'gcx, 'tcx>, F)
1177+
where F: FnMut(DefId, Rc<RegionMaps>) -> ();
11761178

1177-
impl<'a, 'hir: 'a> Visitor<'hir> for CrateResolutionVisitor<'a, 'hir> {
1178-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> {
1179+
impl<'a, 'gcx: 'a+'tcx, 'tcx: 'a, F> Visitor<'gcx> for
1180+
CrateResolutionVisitor<'a, 'gcx, 'tcx, F>
1181+
where F: FnMut(DefId, Rc<RegionMaps>) -> ()
1182+
{
1183+
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'gcx> {
11791184
NestedVisitorMap::OnlyBodies(&self.0.hir)
11801185
}
1181-
fn visit_fn(&mut self, _fk: FnKind<'hir>, _fd: &'hir FnDecl,
1186+
fn visit_fn(&mut self, _fk: FnKind<'tcx>, _fd: &'tcx FnDecl,
11821187
_b: hir::BodyId, _s: Span, fn_id: NodeId)
11831188
{
11841189
let fn_def_id = self.0.hir.local_def_id(fn_id);
1185-
ty::queries::region_resolve_fn::get(self.0, DUMMY_SP, fn_def_id);
1190+
(self.1)(fn_def_id, ty::queries::region_resolve_fn::get(self.0, DUMMY_SP, fn_def_id));
11861191
}
11871192
}
11881193

1189-
tcx.hir.krate().visit_all_item_likes(&mut CrateResolutionVisitor(tcx).as_deep_visitor());
1194+
tcx.hir.krate().visit_all_item_likes(
1195+
&mut CrateResolutionVisitor(tcx, f).as_deep_visitor());
11901196
}
11911197

11921198
fn region_resolve_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn_id: DefId)

src/librustc/ty/context.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
714714
ty::queries::region_resolve_fn::get(self, DUMMY_SP, self.hir.local_def_id(outermost_fn_id))
715715
}
716716

717+
pub fn with_each_region_map<F>(self, f: F) where F: FnMut(DefId, Rc<RegionMaps>) -> ()
718+
{
719+
region::resolve_crate(self, f);
720+
}
721+
717722
/// Create a type context and call the closure with a `TyCtxt` reference
718723
/// to the context. The closure enforces that the type context and any interned
719724
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid

0 commit comments

Comments
 (0)