Skip to content

Commit 3d0774d

Browse files
committed
Auto merge of #86700 - lqd:matthews-nll-hrtb-errors, r=nikomatsakis
Matthew's work on improving NLL's "higher-ranked subtype error"s This PR rebases `@matthewjasper's` [branch](https://github.com/matthewjasper/rust/tree/nll-hrtb-errors) which has great work to fix the obscure higher-ranked subtype errors that are tracked in #57374. These are a blocker to turning full NLLs on, and doing some internal cleanups to remove some of the old region code. The goal is so `@nikomatsakis` can take a look at this early, and I'll then do my best to help do the changes and followup work to land this work, and move closer to turning off the migration mode. I've only updated the branch and made it compile, removed a warning or two. r? `@nikomatsakis` (Here's the [zulip topic to discuss this](https://rust-lang.zulipchat.com/#narrow/stream/122657-t-compiler.2Fwg-nll/topic/.2357374.3A.20improving.20higher-ranked.20subtype.20errors.20via.20.2386700) that Niko wanted)
2 parents 29d6142 + 8343806 commit 3d0774d

File tree

63 files changed

+1043
-345
lines changed

Some content is hidden

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

63 files changed

+1043
-345
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4057,6 +4057,7 @@ dependencies = [
40574057
"rustc_span",
40584058
"rustc_target",
40594059
"rustc_trait_selection",
4060+
"rustc_traits",
40604061
"smallvec",
40614062
"tracing",
40624063
]

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -1180,16 +1180,26 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11801180
// | |
11811181
// | elided as they were the same
11821182
// not elided, they were different, but irrelevant
1183+
//
1184+
// For bound lifetimes, keep the names of the lifetimes,
1185+
// even if they are the same so that it's clear what's happening
1186+
// if we have something like
1187+
//
1188+
// for<'r, 's> fn(Inv<'r>, Inv<'s>)
1189+
// for<'r> fn(Inv<'r>, Inv<'r>)
11831190
let lifetimes = sub1.regions().zip(sub2.regions());
11841191
for (i, lifetimes) in lifetimes.enumerate() {
11851192
let l1 = lifetime_display(lifetimes.0);
11861193
let l2 = lifetime_display(lifetimes.1);
1187-
if lifetimes.0 == lifetimes.1 {
1188-
values.0.push_normal("'_");
1189-
values.1.push_normal("'_");
1190-
} else {
1194+
if lifetimes.0 != lifetimes.1 {
11911195
values.0.push_highlighted(l1);
11921196
values.1.push_highlighted(l2);
1197+
} else if lifetimes.0.is_late_bound() {
1198+
values.0.push_normal(l1);
1199+
values.1.push_normal(l2);
1200+
} else {
1201+
values.0.push_normal("'_");
1202+
values.1.push_normal("'_");
11931203
}
11941204
self.push_comma(&mut values.0, &mut values.1, len, i);
11951205
}

compiler/rustc_infer/src/infer/mod.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub use self::freshen::TypeFreshener;
2+
pub use self::lexical_region_resolve::RegionResolutionError;
23
pub use self::LateBoundRegionConversionTime::*;
34
pub use self::RegionVariableOrigin::*;
45
pub use self::SubregionOrigin::*;
@@ -1110,7 +1111,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11101111
/// etc) this is the root universe U0. For inference variables or
11111112
/// placeholders, however, it will return the universe which which
11121113
/// they are associated.
1113-
fn universe_of_region(&self, r: ty::Region<'tcx>) -> ty::UniverseIndex {
1114+
pub fn universe_of_region(&self, r: ty::Region<'tcx>) -> ty::UniverseIndex {
11141115
self.inner.borrow_mut().unwrap_region_constraints().universe(r)
11151116
}
11161117

@@ -1288,6 +1289,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12881289
op(inner.unwrap_region_constraints().data())
12891290
}
12901291

1292+
pub fn region_var_origin(&self, vid: ty::RegionVid) -> RegionVariableOrigin {
1293+
let mut inner = self.inner.borrow_mut();
1294+
let inner = &mut *inner;
1295+
inner
1296+
.region_constraint_storage
1297+
.as_mut()
1298+
.expect("regions already resolved")
1299+
.with_log(&mut inner.undo_log)
1300+
.var_origin(vid)
1301+
}
1302+
12911303
/// Takes ownership of the list of variable regions. This implies
12921304
/// that all the region constraints have already been taken, and
12931305
/// hence that `resolve_regions_and_report_errors` can never be
@@ -1505,7 +1517,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15051517
self.inner.borrow_mut().projection_cache().clear();
15061518
}
15071519

1508-
fn universe(&self) -> ty::UniverseIndex {
1520+
pub fn universe(&self) -> ty::UniverseIndex {
15091521
self.universe.get()
15101522
}
15111523

compiler/rustc_infer/src/infer/region_constraints/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
445445
self.var_infos[vid].universe
446446
}
447447

448+
/// Returns the origin for the given variable.
449+
pub fn var_origin(&self, vid: RegionVid) -> RegionVariableOrigin {
450+
self.var_infos[vid].origin
451+
}
452+
448453
fn add_constraint(&mut self, constraint: Constraint<'tcx>, origin: SubregionOrigin<'tcx>) {
449454
// cannot add constraints once regions are resolved
450455
debug!("RegionConstraintCollector: add_constraint({:?})", constraint);

compiler/rustc_mir/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ rustc_serialize = { path = "../rustc_serialize" }
2727
rustc_session = { path = "../rustc_session" }
2828
rustc_target = { path = "../rustc_target" }
2929
rustc_trait_selection = { path = "../rustc_trait_selection" }
30+
rustc_traits = { path = "../rustc_traits" }
3031
rustc_ast = { path = "../rustc_ast" }
3132
rustc_span = { path = "../rustc_span" }
3233
rustc_apfloat = { path = "../rustc_apfloat" }

0 commit comments

Comments
 (0)