From 6741efa81442bf638b240acfcb0886d54be2ac91 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Sat, 27 Jun 2026 08:45:43 +0200 Subject: [PATCH] borrowck: Keep returned `path` from `best_blame_constraint()` consistent The function `fn best_blame_constraint()` returns a `Vec` and a `BlameConstraint`. The `BlameConstraint` is really just a slimmed down version of an `OutlivesConstraint`. So we can remove `BlameConstraint` entirely and instead return `Vec` and an index into that `Vec`. (Encapsulated in a struct for nice ergonomics.) To prepare for that, change the code to adjust `Vec` in-place and return info about the adjusted element, rather than returning info for a newly created "fake" `OutlivesConstraint`. --- compiler/rustc_borrowck/src/region_infer/mod.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 64aa92c2c8878..505aa74b04437 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -1630,7 +1630,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { }); // Edge case: it's possible that `'from_region` is an unnameable placeholder. - let path = if let Some(unnameable) = due_to_placeholder_outlives + let mut path = if let Some(unnameable) = due_to_placeholder_outlives && unnameable != from_region { // We ignore the extra edges due to unnameable placeholders to get @@ -1799,10 +1799,9 @@ impl<'tcx> RegionInferenceContext<'tcx> { if let ConstraintCategory::ClosureUpvar(f) = p.category { Some(f) } else { None } }) { - OutlivesConstraint { - category: ConstraintCategory::Return(ReturnConstraint::ClosureUpvar(field)), - ..path[best_choice] - } + path[best_choice].category = + ConstraintCategory::Return(ReturnConstraint::ClosureUpvar(field)); + path[best_choice] } else { path[best_choice] };