Skip to content

Commit 2eddfa7

Browse files
committed
Fix all errors except error_reporting and cfg construction
1 parent b95e875 commit 2eddfa7

File tree

6 files changed

+78
-43
lines changed

6 files changed

+78
-43
lines changed

src/librustc/infer/region_inference/graphviz.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,11 @@ impl<'a, 'gcx, 'tcx> ConstraintGraph<'a, 'gcx, 'tcx> {
159159
add_node(n2);
160160
}
161161

162-
tcx.region_maps().each_encl_scope(|sub, sup| {
163-
add_node(Node::Region(ty::ReScope(*sub)));
164-
add_node(Node::Region(ty::ReScope(*sup)));
162+
tcx.with_each_region_map(|_fn_id, region_maps| {
163+
region_maps.each_encl_scope(|sub, sup| {
164+
add_node(Node::Region(ty::ReScope(*sub)));
165+
add_node(Node::Region(ty::ReScope(*sup)));
166+
});
165167
});
166168
}
167169

@@ -245,7 +247,9 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
245247
fn edges(&self) -> dot::Edges<Edge<'tcx>> {
246248
debug!("constraint graph has {} edges", self.map.len());
247249
let mut v: Vec<_> = self.map.keys().map(|e| Edge::Constraint(*e)).collect();
248-
self.tcx.region_maps().each_encl_scope(|sub, sup| v.push(Edge::EnclScope(*sub, *sup)));
250+
self.tcx.with_each_region_map(|_fn_id, region_maps| {
251+
region_maps.each_encl_scope(|sub, sup| v.push(Edge::EnclScope(*sub, *sup)));
252+
});
249253
debug!("region graph has {} edges", v.len());
250254
Cow::Owned(v)
251255
}

src/librustc/infer/region_inference/mod.rs

+37-24
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,8 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
905905
fn lub_concrete_regions(&self,
906906
free_regions: &FreeRegionMap,
907907
a: &'tcx Region,
908-
b: &'tcx Region)
908+
b: &'tcx Region,
909+
node_id: ast::NodeId)
909910
-> &'tcx Region {
910911
match (a, b) {
911912
(&ReLateBound(..), _) |
@@ -938,7 +939,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
938939
// A "free" region can be interpreted as "some region
939940
// at least as big as the block fr.scope_id". So, we can
940941
// reasonably compare free regions and scopes:
941-
let r_id = self.tcx.region_maps()
942+
let r_id = self.tcx.region_maps(node_id)
942943
.nearest_common_ancestor(fr.scope, s_id);
943944

944945
if r_id == fr.scope {
@@ -958,7 +959,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
958959
// subtype of the region corresponding to an inner
959960
// block.
960961
self.tcx.mk_region(ReScope(
961-
self.tcx.region_maps().nearest_common_ancestor(a_id, b_id)))
962+
self.tcx.region_maps(node_id).nearest_common_ancestor(a_id, b_id)))
962963
}
963964

964965
(&ReFree(a_fr), &ReFree(b_fr)) => {
@@ -1011,9 +1012,9 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
10111012

10121013
let graph = self.construct_graph();
10131014
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);
1015+
self.expansion(free_regions, &mut var_data, subject);
1016+
self.collect_errors(free_regions, &mut var_data, errors, subject);
1017+
self.collect_var_errors(free_regions, &var_data, &graph, errors, subject);
10171018
var_data
10181019
}
10191020

@@ -1056,21 +1057,25 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
10561057
}
10571058
}
10581059

1059-
fn expansion(&self, free_regions: &FreeRegionMap, var_values: &mut [VarValue<'tcx>]) {
1060+
fn expansion(&self,
1061+
free_regions: &FreeRegionMap,
1062+
var_values: &mut [VarValue<'tcx>],
1063+
node_id: ast::NodeId)
1064+
{
10601065
self.iterate_until_fixed_point("Expansion", |constraint, origin| {
10611066
debug!("expansion: constraint={:?} origin={:?}",
10621067
constraint, origin);
10631068
match *constraint {
10641069
ConstrainRegSubVar(a_region, b_vid) => {
10651070
let b_data = &mut var_values[b_vid.index as usize];
1066-
self.expand_node(free_regions, a_region, b_vid, b_data)
1071+
self.expand_node(free_regions, a_region, b_vid, b_data, node_id)
10671072
}
10681073
ConstrainVarSubVar(a_vid, b_vid) => {
10691074
match var_values[a_vid.index as usize] {
10701075
ErrorValue => false,
10711076
Value(a_region) => {
10721077
let b_node = &mut var_values[b_vid.index as usize];
1073-
self.expand_node(free_regions, a_region, b_vid, b_node)
1078+
self.expand_node(free_regions, a_region, b_vid, b_node, node_id)
10741079
}
10751080
}
10761081
}
@@ -1088,7 +1093,8 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
10881093
free_regions: &FreeRegionMap,
10891094
a_region: &'tcx Region,
10901095
b_vid: RegionVid,
1091-
b_data: &mut VarValue<'tcx>)
1096+
b_data: &mut VarValue<'tcx>,
1097+
node_id: ast::NodeId)
10921098
-> bool {
10931099
debug!("expand_node({:?}, {:?} == {:?})",
10941100
a_region,
@@ -1108,7 +1114,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
11081114

11091115
match *b_data {
11101116
Value(cur_region) => {
1111-
let lub = self.lub_concrete_regions(free_regions, a_region, cur_region);
1117+
let lub = self.lub_concrete_regions(free_regions, a_region, cur_region, node_id);
11121118
if lub == cur_region {
11131119
return false;
11141120
}
@@ -1134,7 +1140,8 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
11341140
fn collect_errors(&self,
11351141
free_regions: &FreeRegionMap,
11361142
var_data: &mut Vec<VarValue<'tcx>>,
1137-
errors: &mut Vec<RegionResolutionError<'tcx>>) {
1143+
errors: &mut Vec<RegionResolutionError<'tcx>>,
1144+
node_id: ast::NodeId) {
11381145
let constraints = self.constraints.borrow();
11391146
for (constraint, origin) in constraints.iter() {
11401147
debug!("collect_errors: constraint={:?} origin={:?}",
@@ -1146,7 +1153,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
11461153
}
11471154

11481155
ConstrainRegSubReg(sub, sup) => {
1149-
if free_regions.is_subregion_of(self.tcx, sub, sup) {
1156+
if free_regions.is_subregion_of(self.tcx, sub, sup, node_id) {
11501157
continue;
11511158
}
11521159

@@ -1174,7 +1181,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
11741181
// Do not report these errors immediately:
11751182
// instead, set the variable value to error and
11761183
// collect them later.
1177-
if !free_regions.is_subregion_of(self.tcx, a_region, b_region) {
1184+
if !free_regions.is_subregion_of(self.tcx, a_region, b_region, node_id) {
11781185
debug!("collect_errors: region error at {:?}: \
11791186
cannot verify that {:?}={:?} <= {:?}",
11801187
origin,
@@ -1190,7 +1197,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
11901197
for verify in self.verifys.borrow().iter() {
11911198
debug!("collect_errors: verify={:?}", verify);
11921199
let sub = normalize(self.tcx, var_data, verify.region);
1193-
if verify.bound.is_met(self.tcx, free_regions, var_data, sub) {
1200+
if verify.bound.is_met(self.tcx, free_regions, var_data, sub, node_id) {
11941201
continue;
11951202
}
11961203

@@ -1212,7 +1219,8 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
12121219
free_regions: &FreeRegionMap,
12131220
var_data: &[VarValue<'tcx>],
12141221
graph: &RegionGraph<'tcx>,
1215-
errors: &mut Vec<RegionResolutionError<'tcx>>) {
1222+
errors: &mut Vec<RegionResolutionError<'tcx>>,
1223+
node_id: ast::NodeId) {
12161224
debug!("collect_var_errors");
12171225

12181226
// This is the best way that I have found to suppress
@@ -1262,7 +1270,8 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
12621270
graph,
12631271
&mut dup_vec,
12641272
node_vid,
1265-
errors);
1273+
errors,
1274+
node_id);
12661275
}
12671276
}
12681277
}
@@ -1315,7 +1324,8 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
13151324
graph: &RegionGraph<'tcx>,
13161325
dup_vec: &mut [u32],
13171326
node_idx: RegionVid,
1318-
errors: &mut Vec<RegionResolutionError<'tcx>>) {
1327+
errors: &mut Vec<RegionResolutionError<'tcx>>,
1328+
node_id: ast::NodeId) {
13191329
// Errors in expanding nodes result from a lower-bound that is
13201330
// not contained by an upper-bound.
13211331
let (mut lower_bounds, lower_dup) = self.collect_concrete_regions(graph,
@@ -1347,7 +1357,9 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
13471357

13481358
for lower_bound in &lower_bounds {
13491359
for upper_bound in &upper_bounds {
1350-
if !free_regions.is_subregion_of(self.tcx, lower_bound.region, upper_bound.region) {
1360+
if !free_regions.is_subregion_of(
1361+
self.tcx, lower_bound.region, upper_bound.region, node_id)
1362+
{
13511363
let origin = (*self.var_origins.borrow())[node_idx.index as usize].clone();
13521364
debug!("region inference error at {:?} for {:?}: SubSupConflict sub: {:?} \
13531365
sup: {:?}",
@@ -1594,26 +1606,27 @@ impl<'a, 'gcx, 'tcx> VerifyBound<'tcx> {
15941606
fn is_met(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
15951607
free_regions: &FreeRegionMap,
15961608
var_values: &Vec<VarValue<'tcx>>,
1597-
min: &'tcx ty::Region)
1609+
min: &'tcx ty::Region,
1610+
node_id: ast::NodeId)
15981611
-> bool {
15991612
match self {
16001613
&VerifyBound::AnyRegion(ref rs) =>
16011614
rs.iter()
16021615
.map(|&r| normalize(tcx, var_values, r))
1603-
.any(|r| free_regions.is_subregion_of(tcx, min, r)),
1616+
.any(|r| free_regions.is_subregion_of(tcx, min, r, node_id)),
16041617

16051618
&VerifyBound::AllRegions(ref rs) =>
16061619
rs.iter()
16071620
.map(|&r| normalize(tcx, var_values, r))
1608-
.all(|r| free_regions.is_subregion_of(tcx, min, r)),
1621+
.all(|r| free_regions.is_subregion_of(tcx, min, r, node_id)),
16091622

16101623
&VerifyBound::AnyBound(ref bs) =>
16111624
bs.iter()
1612-
.any(|b| b.is_met(tcx, free_regions, var_values, min)),
1625+
.any(|b| b.is_met(tcx, free_regions, var_values, min, node_id)),
16131626

16141627
&VerifyBound::AllBounds(ref bs) =>
16151628
bs.iter()
1616-
.all(|b| b.is_met(tcx, free_regions, var_values, min)),
1629+
.all(|b| b.is_met(tcx, free_regions, var_values, min, node_id)),
16171630
}
16181631
}
16191632
}

src/librustc/middle/free_region.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ty::{self, TyCtxt, FreeRegion, 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 {
@@ -124,10 +125,14 @@ impl FreeRegionMap {
124125

125126
/// Determines whether one region is a subregion of another. This is intended to run *after
126127
/// inference* and sadly the logic is somewhat duplicated with the code in infer.rs.
128+
///
129+
/// `node_id` should be the id of a node in one of the regions, or of the function the regions
130+
/// are in
127131
pub fn is_subregion_of(&self,
128132
tcx: TyCtxt,
129133
sub_region: &ty::Region,
130-
super_region: &ty::Region)
134+
super_region: &ty::Region,
135+
node_id: NodeId)
131136
-> bool {
132137
let result = sub_region == super_region || {
133138
match (sub_region, super_region) {
@@ -136,10 +141,10 @@ impl FreeRegionMap {
136141
true,
137142

138143
(&ty::ReScope(sub_scope), &ty::ReScope(super_scope)) =>
139-
tcx.region_maps().is_subscope_of(sub_scope, super_scope),
144+
tcx.region_maps(node_id).is_subscope_of(sub_scope, super_scope),
140145

141146
(&ty::ReScope(sub_scope), &ty::ReFree(fr)) =>
142-
tcx.region_maps().is_subscope_of(sub_scope, fr.scope) ||
147+
tcx.region_maps(node_id).is_subscope_of(sub_scope, fr.scope) ||
143148
self.is_static(fr),
144149

145150
(&ty::ReFree(sub_fr), &ty::ReFree(super_fr)) =>

src/librustc/middle/region.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -1269,23 +1269,29 @@ impl<'hir, 'a> Visitor<'hir> for RegionResolutionVisitor<'hir, 'a> {
12691269
}
12701270
}
12711271

1272-
pub fn resolve_crate<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
1273-
1274-
struct CrateResolutionVisitor<'a, 'tcx: 'a>(TyCtxt<'a, 'tcx, 'tcx>);
1272+
pub fn resolve_crate<'a, 'gcx: 'a+'tcx, 'tcx: 'a, F>(tcx: TyCtxt<'a, 'gcx, 'tcx>, f: F)
1273+
where F: FnMut(DefId, Rc<RegionMaps>) -> ()
1274+
{
1275+
struct CrateResolutionVisitor<'a, 'gcx: 'a+'tcx, 'tcx: 'a, F>(TyCtxt<'a, 'gcx, 'tcx>, F)
1276+
where F: FnMut(DefId, Rc<RegionMaps>) -> ();
12751277

1276-
impl<'a, 'hir: 'a> Visitor<'hir> for CrateResolutionVisitor<'a, 'hir> {
1277-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> {
1278+
impl<'a, 'gcx: 'a+'tcx, 'tcx: 'a, F> Visitor<'gcx> for
1279+
CrateResolutionVisitor<'a, 'gcx, 'tcx, F>
1280+
where F: FnMut(DefId, Rc<RegionMaps>) -> ()
1281+
{
1282+
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'gcx> {
12781283
NestedVisitorMap::OnlyBodies(&self.0.hir)
12791284
}
1280-
fn visit_fn(&mut self, _fk: FnKind<'hir>, _fd: &'hir FnDecl,
1285+
fn visit_fn(&mut self, _fk: FnKind<'tcx>, _fd: &'tcx FnDecl,
12811286
_b: hir::BodyId, _s: Span, fn_id: NodeId)
12821287
{
12831288
let fn_def_id = self.0.hir.local_def_id(fn_id);
1284-
ty::queries::region_resolve_fn::get(self.0, DUMMY_SP, fn_def_id);
1289+
(self.1)(fn_def_id, ty::queries::region_resolve_fn::get(self.0, DUMMY_SP, fn_def_id));
12851290
}
12861291
}
12871292

1288-
tcx.hir.krate().visit_all_item_likes(&mut CrateResolutionVisitor(tcx).as_deep_visitor());
1293+
tcx.hir.krate().visit_all_item_likes(
1294+
&mut CrateResolutionVisitor(tcx, f).as_deep_visitor());
12891295
}
12901296

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

src/librustc/ty/context.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use hir::map as hir_map;
2121
use hir::map::DisambiguatedDefPathData;
2222
use middle::free_region::FreeRegionMap;
2323
use middle::lang_items;
24-
use middle::region::RegionMaps;
24+
use middle::region::{self, RegionMaps};
2525
use middle::resolve_lifetime;
2626
use middle::stability;
2727
use mir::Mir;
@@ -679,6 +679,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
679679
ty::queries::region_resolve_fn::get(self, DUMMY_SP, self.hir.local_def_id(outermost_fn_id))
680680
}
681681

682+
pub fn with_each_region_map<F>(self, f: F) where F: FnMut(DefId, Rc<RegionMaps>) -> ()
683+
{
684+
region::resolve_crate(self, f);
685+
}
686+
682687
/// Create a type context and call the closure with a `TyCtxt` reference
683688
/// to the context. The closure enforces that the type context and any interned
684689
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid

src/librustc/ty/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use ich::StableHashingContext;
2323
use middle::const_val::ConstVal;
2424
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
2525
use middle::privacy::AccessLevels;
26-
use middle::region::{CodeExtent, ROOT_CODE_EXTENT};
26+
use middle::region::{CodeExtent, ROOT_CODE_EXTENT, DUMMY_CODE_EXTENT};
2727
use middle::resolve_lifetime::ObjectLifetimeDefault;
2828
use mir::Mir;
2929
use traits;
@@ -2474,7 +2474,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24742474

24752475
// for an empty parameter environment, there ARE no free
24762476
// regions, so it shouldn't matter what we use for the free id
2477-
let free_id_outlive = self.region_maps().node_extent(ast::DUMMY_NODE_ID);
2477+
let free_id_outlive = DUMMY_CODE_EXTENT;
24782478
ty::ParameterEnvironment {
24792479
free_substs: self.intern_substs(&[]),
24802480
caller_bounds: Vec::new(),
@@ -2556,8 +2556,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
25562556
is_sized_cache: RefCell::new(FxHashMap()),
25572557
};
25582558

2559+
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
25592560
let cause = traits::ObligationCause::misc(span,
2560-
free_id_outlive.node_id(&self.region_maps()));
2561+
free_id_outlive.node_id(
2562+
&self.region_maps(node_id)));
25612563
traits::normalize_param_env_or_error(tcx, unnormalized_env, cause)
25622564
}
25632565

0 commit comments

Comments
 (0)