From 5d151083fc52e53dcededc4afcc316ffecbf79dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Tue, 30 Dec 2025 16:22:59 +0000 Subject: [PATCH] optimization: do nothing if there are no loans --- compiler/rustc_borrowck/src/polonius/mod.rs | 26 +++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_borrowck/src/polonius/mod.rs b/compiler/rustc_borrowck/src/polonius/mod.rs index 5773b57a7a0f..7f7952daaa67 100644 --- a/compiler/rustc_borrowck/src/polonius/mod.rs +++ b/compiler/rustc_borrowck/src/polonius/mod.rs @@ -139,18 +139,20 @@ impl PoloniusContext { let localized_outlives_constraints = LocalizedOutlivesConstraintSet::default(); - // From the outlives constraints, liveness, and variances, we can compute reachability on - // the lazy localized constraint graph to trace the liveness of loans, for the next step in - // the chain (the NLL loan scope and active loans computations). - let live_loans = compute_loan_liveness( - &body, - regioncx.outlives_constraints(), - regioncx.liveness_constraints(), - &live_region_variances, - regioncx.universal_regions(), - borrow_set, - ); - regioncx.record_live_loans(live_loans); + if borrow_set.len() > 0 { + // From the outlives constraints, liveness, and variances, we can compute reachability + // on the lazy localized constraint graph to trace the liveness of loans, for the next + // step in the chain (the NLL loan scope and active loans computations). + let live_loans = compute_loan_liveness( + &body, + regioncx.outlives_constraints(), + regioncx.liveness_constraints(), + &live_region_variances, + regioncx.universal_regions(), + borrow_set, + ); + regioncx.record_live_loans(live_loans); + } PoloniusDiagnosticsContext { localized_outlives_constraints, boring_nll_locals } }