Skip to content

Commit 9434486

Browse files
Micro-optimize RegionEraserVisitor
1 parent 70dab5a commit 9434486

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

compiler/rustc_middle/src/ty/erase_regions.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RegionEraserVisitor<'tcx> {
4444
}
4545

4646
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
47-
if ty.has_infer() { ty.super_fold_with(self) } else { self.tcx.erase_regions_ty(ty) }
47+
if !ty.has_type_flags(TypeFlags::HAS_BINDER_VARS | TypeFlags::HAS_FREE_REGIONS) {
48+
ty
49+
} else if ty.has_infer() {
50+
ty.super_fold_with(self)
51+
} else {
52+
self.tcx.erase_regions_ty(ty)
53+
}
4854
}
4955

5056
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> {
6470
_ => self.tcx.lifetimes.re_erased,
6571
}
6672
}
73+
74+
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
75+
if ct.has_type_flags(TypeFlags::HAS_BINDER_VARS | TypeFlags::HAS_FREE_REGIONS) {
76+
ct.super_fold_with(self)
77+
} else {
78+
ct
79+
}
80+
}
81+
82+
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
83+
if p.has_type_flags(TypeFlags::HAS_BINDER_VARS | TypeFlags::HAS_FREE_REGIONS) {
84+
p.super_fold_with(self)
85+
} else {
86+
p
87+
}
88+
}
6789
}

0 commit comments

Comments
 (0)