about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-10-24 19:29:54 +0200
committerGitHub <noreply@github.com>2023-10-24 19:29:54 +0200
commit61ff4dbedd4b8337080959a38e38e07d7d1456be (patch)
tree5f24b6d0ec322e7ad1a75146c7c3321c0035f0f9
parent845c414fae079ab3e9e61fa628de774c632c5058 (diff)
parent2bba98b1216e21fcb18e2242c491ae7205af8308 (diff)
downloadrust-61ff4dbedd4b8337080959a38e38e07d7d1456be.tar.gz
rust-61ff4dbedd4b8337080959a38e38e07d7d1456be.zip
Rollup merge of #116792 - JonasAlaif:renumber-fix, r=b-naber
Avoid unnecessary renumbering during borrowck

Currently, after renumbering there are always unused `RegionVid`s if the return type contains any regions, this is due to `visit_ty` being called twice on the same `Ty`: once with `TyContext::ReturnTy` and once with `TyContext::LocalDecl { local: _0 }`. This PR skips renumbering the first time around.
-rw-r--r--compiler/rustc_borrowck/src/renumber.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/rustc_borrowck/src/renumber.rs b/compiler/rustc_borrowck/src/renumber.rs
index 5d6f5cc8967..ec0131c5349 100644
--- a/compiler/rustc_borrowck/src/renumber.rs
+++ b/compiler/rustc_borrowck/src/renumber.rs
@@ -81,6 +81,10 @@ impl<'a, 'tcx> MutVisitor<'tcx> for RegionRenumberer<'a, 'tcx> {
 
     #[instrument(skip(self), level = "debug")]
     fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) {
+        if matches!(ty_context, TyContext::ReturnTy(_)) {
+            // We will renumber the return ty when called again with `TyContext::LocalDecl`
+            return;
+        }
         *ty = self.renumber_regions(*ty, || RegionCtxt::TyContext(ty_context));
 
         debug!(?ty);