rust-lang/rust · critical
Accessing live loans requires `-Zpolonius=next`
Error message
Accessing live loans requires `-Zpolonius=next`
What it means
This assertion fires in `LivenessValues::is_loan_live_at`, which checks whether a specific borrow (loan) is live at a given program point. The `live_loans` field is an `Option` that is only populated via `record_live_loans` when `-Zpolonius=next` is active. If any code path calls `is_loan_live_at` without `-Zpolonius=next` having recorded live loans, the `.expect(...)` panics.
Source
Thrown at compiler/rustc_borrowck/src/region_infer/values.rs:213
self.location_map.point_from_location(location)
}
#[inline]
pub(crate) fn location_from_point(&self, point: PointIndex) -> Location {
self.location_map.to_location(point)
}
/// When using `-Zpolonius=next`, records the given live loans for the loan scopes and active
/// loans dataflow computations.
pub(crate) fn record_live_loans(&mut self, live_loans: LiveLoans) {
self.live_loans = Some(live_loans);
}
/// When using `-Zpolonius=next`, returns whether the `loan_idx` is live at the given `point`.
pub(crate) fn is_loan_live_at(&self, loan_idx: BorrowIndex, point: PointIndex) -> bool {
self.live_loans
.as_ref()
.expect("Accessing live loans requires `-Zpolonius=next`")
.contains(point, loan_idx)
}
}
/// Maps from `ty::PlaceholderRegion` values that are used in the rest of
/// rustc to the internal `PlaceholderIndex` values that are used in
/// NLL.
#[derive(Debug, Default)]
#[derive(Clone)] // FIXME(#146079)
pub(crate) struct PlaceholderIndices<'tcx> {
indices: FxIndexSet<ty::PlaceholderRegion<'tcx>>,
}
impl<'tcx> PlaceholderIndices<'tcx> {
/// Returns the `PlaceholderIndex` for the inserted `PlaceholderRegion`
pub(crate) fn insert(&mut self, placeholder: ty::PlaceholderRegion<'tcx>) -> PlaceholderIndex {
let (index, _) = self.indices.insert_full(placeholder);
index.into()View on GitHub (pinned to 7088e4b63a)
Solutions
- Add `-Zpolonius=next` to RUSTFLAGS if you need live-loan data: `RUSTFLAGS='-Zpolonius=next' cargo build`.
- Remove any code or tooling that relies on `is_loan_live_at` outside of polonius=next mode.
- File a bug — the compiler should guard `is_loan_live_at` callers with a flag check rather than panicking.
- Update nightly; the polonius=next guard wiring changes frequently.
Example fix
# before (is_loan_live_at called without polonius=next) RUSTFLAGS='' cargo build # after (enable polonius=next for live-loan support) RUSTFLAGS='-Zpolonius=next' cargo build
Defensive patterns
Strategy: validation
Validate before calling
// In a custom rustc driver, check before accessing live loans:
if tcx.sess.opts.unstable_opts.polonius.is_next_enabled() {
let is_live = regioncx.liveness_constraints().is_loan_live_at(loan, point);
} else {
// polonius=next not enabled; cannot check live loans
return false;
} Prevention
- Only call is_loan_live_at when -Zpolonius=next is active.
- Guard all polonius-specific API calls with flag checks.
- Don't share diagnostic code between NLL and polonius modes without conditional gates.
- Document which functions require -Zpolonius=next in compiler-internal docs.
When it happens
Trigger: Calling `is_loan_live_at` (directly or via a code path that reaches it) when the borrow checker ran without `-Zpolonius=next`. This typically means a diagnostic or analysis routine that uses polonius-specific loan-liveness data was invoked in a non-polonius compilation, or a polonius=next body had its `record_live_loans` call skipped.
Common situations: Nightly Rust with code that triggers a diagnostic path (e.g., a borrow-check error diagnostic) that queries live-loan status, but the compilation wasn't started with `-Zpolonius=next`. Can also happen when tooling (rustdoc, clippy, or a proc-macro) invokes the borrow checker in a mode that doesn't set up polonius data.
Related errors
- missing polonius context with `-Zpolonius=next`
- Can't have a type error relating to itself
- Polonius output is unavailable despite `-Z polonius`
- coroutine lowered from async gen fn should be in fn
- simd {}
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/4b5ab30c8b01e91d.
Report an issue: GitHub.