Skip to content

Commit 33e952d

Browse files
committed
Merge branch 'nll-factor-region-inference' into nll-master
2 parents c0d326f + edf4328 commit 33e952d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+4772
-3609
lines changed

src/librustc/infer/README.md

Lines changed: 213 additions & 225 deletions
Large diffs are not rendered by default.

src/librustc/infer/equate.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
104104
a,
105105
b);
106106
let origin = Subtype(self.fields.trace.clone());
107-
self.fields.infcx.region_vars.make_eqregion(origin, a, b);
107+
self.fields.infcx.borrow_region_constraints()
108+
.make_eqregion(origin, a, b);
108109
Ok(a)
109110
}
110111

src/librustc/infer/error_reporting/different_lifetimes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
use hir;
1414
use infer::InferCtxt;
1515
use ty::{self, Region};
16-
use infer::region_inference::RegionResolutionError::*;
17-
use infer::region_inference::RegionResolutionError;
16+
use infer::lexical_region_resolve::RegionResolutionError::*;
17+
use infer::lexical_region_resolve::RegionResolutionError;
1818
use hir::map as hir_map;
1919
use middle::resolve_lifetime as rl;
2020
use hir::intravisit::{self, Visitor, NestedVisitorMap};

src/librustc/infer/error_reporting/mod.rs

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
5858
use infer;
5959
use super::{InferCtxt, TypeTrace, SubregionOrigin, RegionVariableOrigin, ValuePairs};
60-
use super::region_inference::{RegionResolutionError, ConcreteFailure, SubSupConflict,
61-
GenericBoundFailure, GenericKind};
60+
use super::region_constraints::GenericKind;
61+
use super::lexical_region_resolve::RegionResolutionError;
6262

6363
use std::fmt;
6464
use hir;
@@ -177,13 +177,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
177177

178178
ty::ReEarlyBound(_) |
179179
ty::ReFree(_) => {
180-
let scope = match *region {
181-
ty::ReEarlyBound(ref br) => {
182-
self.parent_def_id(br.def_id).unwrap()
183-
}
184-
ty::ReFree(ref fr) => fr.scope,
185-
_ => bug!()
186-
};
180+
let scope = region.free_region_binding_scope(self);
187181
let prefix = match *region {
188182
ty::ReEarlyBound(ref br) => {
189183
format!("the lifetime {} as defined on", br.name)
@@ -293,33 +287,37 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
293287
debug!("report_region_errors: error = {:?}", error);
294288

295289
if !self.try_report_named_anon_conflict(&error) &&
296-
!self.try_report_anon_anon_conflict(&error) {
297-
298-
match error.clone() {
299-
// These errors could indicate all manner of different
300-
// problems with many different solutions. Rather
301-
// than generate a "one size fits all" error, what we
302-
// attempt to do is go through a number of specific
303-
// scenarios and try to find the best way to present
304-
// the error. If all of these fails, we fall back to a rather
305-
// general bit of code that displays the error information
306-
ConcreteFailure(origin, sub, sup) => {
307-
self.report_concrete_failure(region_scope_tree, origin, sub, sup).emit();
308-
}
309-
310-
GenericBoundFailure(kind, param_ty, sub) => {
311-
self.report_generic_bound_failure(region_scope_tree, kind, param_ty, sub);
312-
}
313-
314-
SubSupConflict(var_origin, sub_origin, sub_r, sup_origin, sup_r) => {
290+
!self.try_report_anon_anon_conflict(&error)
291+
{
292+
match error.clone() {
293+
// These errors could indicate all manner of different
294+
// problems with many different solutions. Rather
295+
// than generate a "one size fits all" error, what we
296+
// attempt to do is go through a number of specific
297+
// scenarios and try to find the best way to present
298+
// the error. If all of these fails, we fall back to a rather
299+
// general bit of code that displays the error information
300+
RegionResolutionError::ConcreteFailure(origin, sub, sup) => {
301+
self.report_concrete_failure(region_scope_tree, origin, sub, sup).emit();
302+
}
303+
304+
RegionResolutionError::GenericBoundFailure(kind, param_ty, sub) => {
305+
self.report_generic_bound_failure(region_scope_tree, kind, param_ty, sub);
306+
}
307+
308+
RegionResolutionError::SubSupConflict(var_origin,
309+
sub_origin,
310+
sub_r,
311+
sup_origin,
312+
sup_r) => {
315313
self.report_sub_sup_conflict(region_scope_tree,
316314
var_origin,
317315
sub_origin,
318316
sub_r,
319317
sup_origin,
320318
sup_r);
321-
}
322-
}
319+
}
320+
}
323321
}
324322
}
325323
}
@@ -351,9 +349,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
351349
// the only thing in the list.
352350

353351
let is_bound_failure = |e: &RegionResolutionError<'tcx>| match *e {
354-
ConcreteFailure(..) => false,
355-
SubSupConflict(..) => false,
356-
GenericBoundFailure(..) => true,
352+
RegionResolutionError::GenericBoundFailure(..) => true,
353+
RegionResolutionError::ConcreteFailure(..) |
354+
RegionResolutionError::SubSupConflict(..) => false,
357355
};
358356

359357

@@ -365,9 +363,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
365363

366364
// sort the errors by span, for better error message stability.
367365
errors.sort_by_key(|u| match *u {
368-
ConcreteFailure(ref sro, _, _) => sro.span(),
369-
GenericBoundFailure(ref sro, _, _) => sro.span(),
370-
SubSupConflict(ref rvo, _, _, _, _) => rvo.span(),
366+
RegionResolutionError::ConcreteFailure(ref sro, _, _) => sro.span(),
367+
RegionResolutionError::GenericBoundFailure(ref sro, _, _) => sro.span(),
368+
RegionResolutionError::SubSupConflict(ref rvo, _, _, _, _) => rvo.span(),
371369
});
372370
errors
373371
}
@@ -880,14 +878,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
880878
};
881879

882880
if let SubregionOrigin::CompareImplMethodObligation {
883-
span, item_name, impl_item_def_id, trait_item_def_id, lint_id
881+
span, item_name, impl_item_def_id, trait_item_def_id,
884882
} = origin {
885883
self.report_extra_impl_obligation(span,
886884
item_name,
887885
impl_item_def_id,
888886
trait_item_def_id,
889-
&format!("`{}: {}`", bound_kind, sub),
890-
lint_id)
887+
&format!("`{}: {}`", bound_kind, sub))
891888
.emit();
892889
return;
893890
}
@@ -1026,6 +1023,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10261023
let var_name = self.tcx.hir.name(var_node_id);
10271024
format!(" for capture of `{}` by closure", var_name)
10281025
}
1026+
infer::NLL(..) => bug!("NLL variable found in lexical phase"),
10291027
};
10301028

10311029
struct_span_err!(self.tcx.sess, var_origin.span(), E0495,

src/librustc/infer/error_reporting/named_anon_conflict.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
//! Error Reporting for Anonymous Region Lifetime Errors
1212
//! where one region is named and the other is anonymous.
1313
use infer::InferCtxt;
14-
use infer::region_inference::RegionResolutionError::*;
15-
use infer::region_inference::RegionResolutionError;
14+
use infer::lexical_region_resolve::RegionResolutionError::*;
15+
use infer::lexical_region_resolve::RegionResolutionError;
1616
use ty;
1717

1818
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {

src/librustc/infer/error_reporting/note.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
445445
infer::CompareImplMethodObligation { span,
446446
item_name,
447447
impl_item_def_id,
448-
trait_item_def_id,
449-
lint_id } => {
448+
trait_item_def_id } => {
450449
self.report_extra_impl_obligation(span,
451450
item_name,
452451
impl_item_def_id,
453452
trait_item_def_id,
454-
&format!("`{}: {}`", sup, sub),
455-
lint_id)
453+
&format!("`{}: {}`", sup, sub))
456454
}
457455
}
458456
}

src/librustc/infer/fudge.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
7878
self.type_variables.borrow_mut().types_created_since_snapshot(
7979
&snapshot.type_snapshot);
8080
let region_vars =
81-
self.region_vars.vars_created_since_snapshot(
82-
&snapshot.region_vars_snapshot);
81+
self.borrow_region_constraints().vars_created_since_snapshot(
82+
&snapshot.region_constraints_snapshot);
8383

8484
Ok((type_variables, region_vars, value))
8585
}

src/librustc/infer/glb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
6767
b);
6868

6969
let origin = Subtype(self.fields.trace.clone());
70-
Ok(self.fields.infcx.region_vars.glb_regions(origin, a, b))
70+
Ok(self.fields.infcx.borrow_region_constraints().glb_regions(self.tcx(), origin, a, b))
7171
}
7272

7373
fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)

src/librustc/infer/higher_ranked/mod.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use super::{CombinedSnapshot,
1717
SubregionOrigin,
1818
SkolemizationMap};
1919
use super::combine::CombineFields;
20-
use super::region_inference::{TaintDirections};
20+
use super::region_constraints::{TaintDirections};
2121

2222
use ty::{self, TyCtxt, Binder, TypeFoldable};
2323
use ty::error::TypeError;
@@ -176,9 +176,10 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
176176
.filter(|&r| r != representative)
177177
{
178178
let origin = SubregionOrigin::Subtype(self.trace.clone());
179-
self.infcx.region_vars.make_eqregion(origin,
180-
*representative,
181-
*region);
179+
self.infcx.borrow_region_constraints()
180+
.make_eqregion(origin,
181+
*representative,
182+
*region);
182183
}
183184
}
184185

@@ -427,7 +428,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
427428
fn fresh_bound_variable<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
428429
debruijn: ty::DebruijnIndex)
429430
-> ty::Region<'tcx> {
430-
infcx.region_vars.new_bound(debruijn)
431+
infcx.borrow_region_constraints().new_bound(infcx.tcx, debruijn)
431432
}
432433
}
433434
}
@@ -481,7 +482,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
481482
r: ty::Region<'tcx>,
482483
directions: TaintDirections)
483484
-> FxHashSet<ty::Region<'tcx>> {
484-
self.region_vars.tainted(&snapshot.region_vars_snapshot, r, directions)
485+
self.borrow_region_constraints().tainted(
486+
self.tcx,
487+
&snapshot.region_constraints_snapshot,
488+
r,
489+
directions)
485490
}
486491

487492
fn region_vars_confined_to_snapshot(&self,
@@ -539,7 +544,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
539544
*/
540545

541546
let mut region_vars =
542-
self.region_vars.vars_created_since_snapshot(&snapshot.region_vars_snapshot);
547+
self.borrow_region_constraints().vars_created_since_snapshot(
548+
&snapshot.region_constraints_snapshot);
543549

544550
let escaping_types =
545551
self.type_variables.borrow_mut().types_escaping_snapshot(&snapshot.type_snapshot);
@@ -581,7 +587,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
581587
where T : TypeFoldable<'tcx>
582588
{
583589
let (result, map) = self.tcx.replace_late_bound_regions(binder, |br| {
584-
self.region_vars.push_skolemized(br, &snapshot.region_vars_snapshot)
590+
self.borrow_region_constraints()
591+
.push_skolemized(self.tcx, br, &snapshot.region_constraints_snapshot)
585592
});
586593

587594
debug!("skolemize_bound_regions(binder={:?}, result={:?}, map={:?})",
@@ -766,7 +773,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
766773
{
767774
debug!("pop_skolemized({:?})", skol_map);
768775
let skol_regions: FxHashSet<_> = skol_map.values().cloned().collect();
769-
self.region_vars.pop_skolemized(&skol_regions, &snapshot.region_vars_snapshot);
776+
self.borrow_region_constraints()
777+
.pop_skolemized(self.tcx, &skol_regions, &snapshot.region_constraints_snapshot);
770778
if !skol_map.is_empty() {
771779
self.projection_cache.borrow_mut().rollback_skolemized(
772780
&snapshot.projection_cache_snapshot);

0 commit comments

Comments
 (0)