Skip to content

Commit fa45efa

Browse files
committed
consider a loan escapes the function via applied member constraints
1 parent c69bd94 commit fa45efa

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

compiler/rustc_borrowck/src/dataflow.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -272,21 +272,28 @@ impl<'tcx> PoloniusOutOfScopePrecomputer<'_, 'tcx> {
272272
loan_issued_at: Location,
273273
) {
274274
let sccs = self.regioncx.constraint_sccs();
275+
let universal_regions = self.regioncx.universal_regions();
275276
let issuing_region_scc = sccs.scc(issuing_region);
276277

277278
// We first handle the cases where the loan doesn't go out of scope, depending on the issuing
278279
// region's successors.
279280
for scc in sccs.depth_first_search(issuing_region_scc) {
280-
// 1. Via member constraints
281+
// 1. Via applied member constraints
281282
//
282283
// The issuing region can flow into the choice regions, and they are either:
283284
// - placeholders or free regions themselves,
284285
// - or also transitively outlive a free region.
285286
//
286-
// That is to say, if there are member constraints here, the loan escapes the function
287-
// and cannot go out of scope. We can early return.
288-
if self.regioncx.scc_has_member_constraints(scc) {
289-
return;
287+
// That is to say, if there are applied member constraints here, the loan escapes the
288+
// function and cannot go out of scope. We could early return here.
289+
//
290+
// For additional insurance via fuzzing and crater, we verify that the constraint's min
291+
// choice indeed escapes the function. In the future, we could e.g. turn this check into
292+
// a debug assert and early return as an optimization.
293+
for constraint in self.regioncx.applied_member_constraints(scc) {
294+
if universal_regions.is_universal_region(constraint.min_choice) {
295+
return;
296+
}
290297
}
291298

292299
// 2. Via regions that are live at all points: placeholders and free regions.
@@ -413,12 +420,12 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
413420
let mut polonius_prec = PoloniusOutOfScopePrecomputer::new(body, regioncx);
414421
for (loan_idx, loan_data) in borrow_set.iter_enumerated() {
415422
let issuing_region = loan_data.region;
416-
let issued_location = loan_data.reserve_location;
423+
let loan_issued_at = loan_data.reserve_location;
417424

418425
polonius_prec.precompute_loans_out_of_scope(
419426
loan_idx,
420427
issuing_region,
421-
issued_location,
428+
loan_issued_at,
422429
);
423430
}
424431

compiler/rustc_borrowck/src/region_infer/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -2293,11 +2293,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22932293
self.constraint_sccs.as_ref()
22942294
}
22952295

2296-
/// Returns whether the given SCC has any member constraints.
2297-
pub(crate) fn scc_has_member_constraints(&self, scc: ConstraintSccIndex) -> bool {
2298-
self.member_constraints.indices(scc).next().is_some()
2299-
}
2300-
23012296
/// Returns whether the given SCC is live at all points: whether the representative is a
23022297
/// placeholder or a free region.
23032298
pub(crate) fn scc_is_live_at_all_points(&self, scc: ConstraintSccIndex) -> bool {

0 commit comments

Comments
 (0)