clone region obligations instead of taking in implied bounds hack

This commit is contained in:
Jana Dönszelmann 2025-09-30 13:29:39 +02:00
parent 817e181ee8
commit 80e598bb12
No known key found for this signature in database
2 changed files with 11 additions and 1 deletions

View file

@ -170,6 +170,10 @@ impl<'tcx> InferCtxt<'tcx> {
std::mem::take(&mut self.inner.borrow_mut().region_obligations)
}
pub fn clone_registered_region_obligations(&self) -> Vec<TypeOutlivesConstraint<'tcx>> {
self.inner.borrow().region_obligations.clone()
}
pub fn register_region_assumption(&self, assumption: ty::ArgOutlivesPredicate<'tcx>) {
let mut inner = self.inner.borrow_mut();
inner.undo_log.push(UndoLog::PushRegionAssumption);

View file

@ -55,6 +55,12 @@ pub fn compute_implied_outlives_bounds_inner<'tcx>(
span: Span,
disable_implied_bounds_hack: bool,
) -> Result<Vec<OutlivesBound<'tcx>>, NoSolution> {
// Inside mir borrowck, each computation starts with an empty list.
assert!(
ocx.infcx.inner.borrow().region_obligations().is_empty(),
"compute_implied_outlives_bounds assumes region obligations are empty before starting"
);
let normalize_ty = |ty| -> Result<_, NoSolution> {
// We must normalize the type so we can compute the right outlives components.
// for example, if we have some constrained param type like `T: Trait<Out = U>`,
@ -143,7 +149,7 @@ pub fn compute_implied_outlives_bounds_inner<'tcx>(
&& ty.visit_with(&mut ContainsBevyParamSet { tcx: ocx.infcx.tcx }).is_break()
{
for TypeOutlivesConstraint { sup_type, sub_region, .. } in
ocx.infcx.take_registered_region_obligations()
ocx.infcx.clone_registered_region_obligations()
{
let mut components = smallvec![];
push_outlives_components(ocx.infcx.tcx, sup_type, &mut components);