Skip to content

Commit c0bbc39

Browse files
committed
Auto merge of #55517 - nikomatsakis:universes, r=scalexm
Universes This PR transitions the compiler to use **universes** instead of the **leak-check**. It is marked as [WIP] for a few reasons: - The diagnostics at present are terrible =) - This changes the behavior of coherence, regressing some things that used to compile The goals of this PR at present are: - To start getting some eyes on the code - To do a crater run - To see the full travis results (due to #52452, I am not able to run the full test suite locally anymore at present) The first few commits in the PR are changing how `evaluate` treats regions. We now track whether region comparisons occurred, reverting the "staticized" query approach that @arielb1 put in. The problem with "staticized" queries is that it relied on the leak-check to get higher-ranked things correct, and we are removing the leak-check in this PR series, so that caused problems. You can see at the end a collection of test updates. Mostly we behave the same but with atrocious diagnostics, but there are a number of cases where we used to error and now no longer do, as well as single case where we used to **not** error but we now do (the coherence-subtyping change). (Note: it would be possible to do a version of leak-check that propagates universe information and recover the old behavior. I am reluctant to do so because I'd like to leave us room to get more precise -- e.g., I want to eventually handle things like `exists<'a> { for<'b> { if ('a: 'b) { 'a: 'b } } }` which presently the leak-check cannot cope with etc. Also because it seems more consistent to me: most folks I've talked to expect the new behavior and are surprised to learn that binding sites were so significant before when it comes to coherence. One question is, though, to what extent are people relying on this in the wild?)
2 parents 2442823 + 8e89184 commit c0bbc39

File tree

115 files changed

+1563
-1777
lines changed

Some content is hidden

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

115 files changed

+1563
-1777
lines changed

src/librustc/infer/error_reporting/mod.rs

+48-12
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
132132

133133
ty::ReEmpty => ("the empty lifetime".to_owned(), None),
134134

135+
ty::RePlaceholder(_) => (format!("any other region"), None),
136+
135137
// FIXME(#13998) RePlaceholder should probably print like
136138
// ReFree rather than dumping Debug output on the user.
137139
//
138140
// We shouldn't really be having unification failures with ReVar
139141
// and ReLateBound though.
140-
ty::RePlaceholder(..) | ty::ReVar(_) | ty::ReLateBound(..) | ty::ReErased => {
142+
ty::ReVar(_) | ty::ReLateBound(..) | ty::ReErased => {
141143
(format!("lifetime {:?}", region), None)
142144
}
143145

@@ -324,8 +326,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
324326
// the error. If all of these fails, we fall back to a rather
325327
// general bit of code that displays the error information
326328
RegionResolutionError::ConcreteFailure(origin, sub, sup) => {
327-
self.report_concrete_failure(region_scope_tree, origin, sub, sup)
328-
.emit();
329+
if sub.is_placeholder() || sup.is_placeholder() {
330+
self.report_placeholder_failure(region_scope_tree, origin, sub, sup)
331+
.emit();
332+
} else {
333+
self.report_concrete_failure(region_scope_tree, origin, sub, sup)
334+
.emit();
335+
}
329336
}
330337

331338
RegionResolutionError::GenericBoundFailure(origin, param_ty, sub) => {
@@ -339,20 +346,39 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
339346
}
340347

341348
RegionResolutionError::SubSupConflict(
349+
_,
342350
var_origin,
343351
sub_origin,
344352
sub_r,
345353
sup_origin,
346354
sup_r,
347355
) => {
348-
self.report_sub_sup_conflict(
349-
region_scope_tree,
350-
var_origin,
351-
sub_origin,
352-
sub_r,
353-
sup_origin,
354-
sup_r,
355-
);
356+
if sub_r.is_placeholder() {
357+
self.report_placeholder_failure(
358+
region_scope_tree,
359+
sub_origin,
360+
sub_r,
361+
sup_r,
362+
)
363+
.emit();
364+
} else if sup_r.is_placeholder() {
365+
self.report_placeholder_failure(
366+
region_scope_tree,
367+
sup_origin,
368+
sub_r,
369+
sup_r,
370+
)
371+
.emit();
372+
} else {
373+
self.report_sub_sup_conflict(
374+
region_scope_tree,
375+
var_origin,
376+
sub_origin,
377+
sub_r,
378+
sup_origin,
379+
sup_r,
380+
);
381+
}
356382
}
357383
}
358384
}
@@ -407,7 +433,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
407433
errors.sort_by_key(|u| match *u {
408434
RegionResolutionError::ConcreteFailure(ref sro, _, _) => sro.span(),
409435
RegionResolutionError::GenericBoundFailure(ref sro, _, _) => sro.span(),
410-
RegionResolutionError::SubSupConflict(ref rvo, _, _, _, _) => rvo.span(),
436+
RegionResolutionError::SubSupConflict(_, ref rvo, _, _, _, _) => rvo.span(),
411437
});
412438
errors
413439
}
@@ -1306,6 +1332,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13061332

13071333
match (&sup_origin, &sub_origin) {
13081334
(&infer::Subtype(ref sup_trace), &infer::Subtype(ref sub_trace)) => {
1335+
debug!("report_sub_sup_conflict: var_origin={:?}", var_origin);
1336+
debug!("report_sub_sup_conflict: sub_region={:?}", sub_region);
1337+
debug!("report_sub_sup_conflict: sub_origin={:?}", sub_origin);
1338+
debug!("report_sub_sup_conflict: sup_region={:?}", sup_region);
1339+
debug!("report_sub_sup_conflict: sup_origin={:?}", sup_origin);
1340+
debug!("report_sub_sup_conflict: sup_trace={:?}", sup_trace);
1341+
debug!("report_sub_sup_conflict: sub_trace={:?}", sub_trace);
1342+
debug!("report_sub_sup_conflict: sup_trace.values={:?}", sup_trace.values);
1343+
debug!("report_sub_sup_conflict: sub_trace.values={:?}", sub_trace.values);
1344+
13091345
if let (Some((sup_expected, sup_found)), Some((sub_expected, sub_found))) = (
13101346
self.values_str(&sup_trace.values),
13111347
self.values_str(&sub_trace.values),

src/librustc/infer/error_reporting/nice_region_error/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use util::common::ErrorReported;
88
mod different_lifetimes;
99
mod find_anon_type;
1010
mod named_anon_conflict;
11+
mod placeholder_error;
1112
mod outlives_closure;
1213
mod static_impl_trait;
1314
mod util;
@@ -58,19 +59,20 @@ impl<'cx, 'gcx, 'tcx> NiceRegionError<'cx, 'gcx, 'tcx> {
5859
// Due to the improved diagnostics returned by the MIR borrow checker, only a subset of
5960
// the nice region errors are required when running under the MIR borrow checker.
6061
self.try_report_named_anon_conflict()
62+
.or_else(|| self.try_report_placeholder_conflict())
6163
}
6264

6365
pub fn try_report(&self) -> Option<ErrorReported> {
64-
self.try_report_named_anon_conflict()
66+
self.try_report_from_nll()
6567
.or_else(|| self.try_report_anon_anon_conflict())
6668
.or_else(|| self.try_report_outlives_closure())
6769
.or_else(|| self.try_report_static_impl_trait())
6870
}
6971

7072
pub fn get_regions(&self) -> (Span, ty::Region<'tcx>, ty::Region<'tcx>) {
7173
match (&self.error, self.regions) {
72-
(&Some(ConcreteFailure(ref origin, sub, sup)), None) => (origin.span(), sub, sup),
73-
(&Some(SubSupConflict(_, ref origin, sub, _, sup)), None) => (origin.span(), sub, sup),
74+
(Some(ConcreteFailure(origin, sub, sup)), None) => (origin.span(), sub, sup),
75+
(Some(SubSupConflict(_, _, origin, sub, _, sup)), None) => (origin.span(), sub, sup),
7476
(None, Some((span, sub, sup))) => (span, sub, sup),
7577
(Some(_), Some(_)) => panic!("incorrectly built NiceRegionError"),
7678
_ => panic!("trying to report on an incorrect lifetime failure"),

src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
3636
/// ...because it cannot outlive this closure
3737
/// ```
3838
pub(super) fn try_report_outlives_closure(&self) -> Option<ErrorReported> {
39-
if let Some(SubSupConflict(origin,
39+
if let Some(SubSupConflict(_,
40+
origin,
4041
ref sub_origin,
4142
_,
4243
ref sup_origin,

0 commit comments

Comments
 (0)