Skip to content

Commit 349e4b3

Browse files
committed
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.
1 parent ef9cb23 commit 349e4b3

File tree

6 files changed

+304
-171
lines changed

6 files changed

+304
-171
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: 3 additions & 4 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
}
@@ -456,9 +456,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
456456
) {
457457
debug!("report_region_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
458458

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-
});
459+
let (blame_constraint, path) =
460+
self.regioncx.best_blame_constraint(fr, fr_origin, outlived_fr);
462461
let BlameConstraint { category, cause, variance_info, .. } = blame_constraint;
463462

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

0 commit comments

Comments
 (0)