Skip to content

Commit 0d3d480

Browse files
committed
Auto merge of #140737 - amandasystems:revised-constraint-search, r=<try>
Region inference: Use outlives-static constraints in constraint search Revise the extra `r: 'static` constraints added upon universe issues to add an explanation, and use that explanation during constraint blame search. This greatly simplifies the region inference logic, which now does not need to reverse-engineer the event that caused a region to outlive `'static`. This cosmetically changes the output of two UI tests. I blessed them i separate commits with separate motivations, but that can of course be squashed as desired. We probably want that. The PR was extracted out of #130227 and consists of one-third of its functional payload. It is based on #140466, so that has to land first. We probably want a perf run of this. It shouldn't have much of an impact and a positive one if any, but I have been wrong before. In particular, SCC annotations are heavier now. r? lcnr
2 parents b6685d7 + a209255 commit 0d3d480

File tree

9 files changed

+343
-209
lines changed

9 files changed

+343
-209
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
565565
let (blame_constraint, path) = self.regioncx.best_blame_constraint(
566566
borrow_region,
567567
NllRegionVariableOrigin::FreeRegion,
568-
|r| self.regioncx.provides_universal_region(r, borrow_region, outlived_region),
568+
outlived_region,
569569
);
570570
let BlameConstraint { category, from_closure, cause, .. } = blame_constraint;
571571

compiler/rustc_borrowck/src/diagnostics/opaque_suggestions.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,9 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for FindOpaqueRegion<'_, 'tcx> {
174174
let opaque_region_vid = self.regioncx.to_region_vid(opaque_region);
175175

176176
// Find a path between the borrow region and our opaque capture.
177-
if let Some((path, _)) =
178-
self.regioncx.find_constraint_paths_between_regions(self.borrow_region, |r| {
179-
r == opaque_region_vid
180-
})
177+
if let Some(path) = self
178+
.regioncx
179+
.constraint_path_between_regions(self.borrow_region, opaque_region_vid)
181180
{
182181
for constraint in path {
183182
// If we find a call in this path, then check if it defines the opaque.

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
6262
| ConstraintCategory::Boring
6363
| ConstraintCategory::BoringNoLocation
6464
| ConstraintCategory::Internal
65-
| ConstraintCategory::IllegalUniverse => "",
65+
| ConstraintCategory::IllegalPlaceholder(..) => "",
6666
}
6767
}
6868
}
@@ -396,11 +396,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
396396
let error_vid = self.regioncx.region_from_element(longer_fr, &error_element);
397397

398398
// Find the code to blame for the fact that `longer_fr` outlives `error_fr`.
399-
let (_, cause) = self.regioncx.find_outlives_blame_span(
400-
longer_fr,
401-
NllRegionVariableOrigin::Placeholder(placeholder),
402-
error_vid,
403-
);
399+
let cause = self
400+
.regioncx
401+
.best_blame_constraint(
402+
longer_fr,
403+
NllRegionVariableOrigin::Placeholder(placeholder),
404+
error_vid,
405+
)
406+
.0
407+
.cause;
404408

405409
let universe = placeholder.universe;
406410
let universe_info = self.regioncx.universe_info(universe);
@@ -456,9 +460,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
456460
) {
457461
debug!("report_region_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
458462

459-
let (blame_constraint, path) = self.regioncx.best_blame_constraint(fr, fr_origin, |r| {
460-
self.regioncx.provides_universal_region(r, fr, outlived_fr)
461-
});
463+
let (blame_constraint, path) =
464+
self.regioncx.best_blame_constraint(fr, fr_origin, outlived_fr);
462465
let BlameConstraint { category, cause, variance_info, .. } = blame_constraint;
463466

464467
debug!("report_region_error: category={:?} {:?} {:?}", category, cause, variance_info);

0 commit comments

Comments
 (0)