about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-04-02 23:38:27 +0000
committerMichael Goulet <michael@errs.io>2025-04-03 00:08:24 +0000
commit9434486312b33633d265b19804c3e9b76535527c (patch)
tree107d164627feb5aa2f2442efaa1e978f363318ef
parent70dab5a27c03a5637cc1d4ba36a5139760d25e38 (diff)
downloadrust-9434486312b33633d265b19804c3e9b76535527c.tar.gz
rust-9434486312b33633d265b19804c3e9b76535527c.zip
Micro-optimize RegionEraserVisitor
-rw-r--r--compiler/rustc_middle/src/ty/erase_regions.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/erase_regions.rs b/compiler/rustc_middle/src/ty/erase_regions.rs
index f25c48cf42a..8bddb5c0fd7 100644
--- a/compiler/rustc_middle/src/ty/erase_regions.rs
+++ b/compiler/rustc_middle/src/ty/erase_regions.rs
@@ -44,7 +44,13 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RegionEraserVisitor<'tcx> {
     }
 
     fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
-        if ty.has_infer() { ty.super_fold_with(self) } else { self.tcx.erase_regions_ty(ty) }
+        if !ty.has_type_flags(TypeFlags::HAS_BINDER_VARS | TypeFlags::HAS_FREE_REGIONS) {
+            ty
+        } else if ty.has_infer() {
+            ty.super_fold_with(self)
+        } else {
+            self.tcx.erase_regions_ty(ty)
+        }
     }
 
     fn fold_binder<T>(&mut self, t: ty::Binder<'tcx, T>) -> ty::Binder<'tcx, T>
@@ -64,4 +70,20 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RegionEraserVisitor<'tcx> {
             _ => self.tcx.lifetimes.re_erased,
         }
     }
+
+    fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
+        if ct.has_type_flags(TypeFlags::HAS_BINDER_VARS | TypeFlags::HAS_FREE_REGIONS) {
+            ct.super_fold_with(self)
+        } else {
+            ct
+        }
+    }
+
+    fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
+        if p.has_type_flags(TypeFlags::HAS_BINDER_VARS | TypeFlags::HAS_FREE_REGIONS) {
+            p.super_fold_with(self)
+        } else {
+            p
+        }
+    }
 }