Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4582531

Browse files
committed
Auto merge of rust-lang#139271 - compiler-errors:super-visit, r=<try>
Rely on type flags to avoid visiting types/consts/preds Not sure if this is actually that useful, but let's see. r? `@ghost`
2 parents ae9173d + a76acd6 commit 4582531

File tree

7 files changed

+89
-2
lines changed

7 files changed

+89
-2
lines changed

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,10 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
515515
ct
516516
}
517517
}
518+
519+
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
520+
if p.flags().intersects(self.needs_canonical_flags) { p.super_fold_with(self) } else { p }
521+
}
518522
}
519523

520524
impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {

compiler/rustc_infer/src/infer/resolve.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for OpportunisticVarResolver<'a, 'tcx> {
5656
ct.super_fold_with(self)
5757
}
5858
}
59+
60+
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
61+
if !p.has_non_region_infer() { p } else { p.super_fold_with(self) }
62+
}
5963
}
6064

6165
/// The opportunistic region resolver opportunistically resolves regions

compiler/rustc_middle/src/ty/abstract_const.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ impl<'tcx> TyCtxt<'tcx> {
6363
},
6464
_ => c,
6565
};
66-
ct.super_fold_with(self)
66+
67+
if ct.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION) {
68+
ct.super_fold_with(self)
69+
} else {
70+
ct
71+
}
6772
}
6873
}
6974
ac.fold_with(&mut Expander { tcx: self })

compiler/rustc_middle/src/ty/erase_regions.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,20 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RegionEraserVisitor<'tcx> {
6464
_ => self.tcx.lifetimes.re_erased,
6565
}
6666
}
67+
68+
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
69+
if ct.has_type_flags(TypeFlags::HAS_BINDER_VARS | TypeFlags::HAS_FREE_REGIONS) {
70+
ct.super_fold_with(self)
71+
} else {
72+
ct
73+
}
74+
}
75+
76+
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
77+
if p.has_type_flags(TypeFlags::HAS_BINDER_VARS | TypeFlags::HAS_FREE_REGIONS) {
78+
p.super_fold_with(self)
79+
} else {
80+
p
81+
}
82+
}
6783
}

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,22 @@ pub fn normalize_param_env_or_error<'tcx>(
376376

377377
c
378378
}
379+
380+
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
381+
if t.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION) {
382+
t.super_fold_with(self)
383+
} else {
384+
t
385+
}
386+
}
387+
388+
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
389+
if p.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION) {
390+
p.super_fold_with(self)
391+
} else {
392+
p
393+
}
394+
}
379395
}
380396

381397
// This whole normalization step is a hack to work around the fact that

compiler/rustc_type_ir/src/binder.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,12 +697,24 @@ impl<'a, I: Interner> TypeFolder<I> for ArgFolder<'a, I> {
697697
}
698698

699699
fn fold_const(&mut self, c: I::Const) -> I::Const {
700+
if !c.has_param() {
701+
return c;
702+
}
703+
700704
if let ty::ConstKind::Param(p) = c.kind() {
701705
self.const_for_param(p, c)
702706
} else {
703707
c.super_fold_with(self)
704708
}
705709
}
710+
711+
fn fold_predicate(&mut self, p: I::Predicate) -> I::Predicate {
712+
if !p.has_param() {
713+
return p;
714+
}
715+
716+
p.super_fold_with(self)
717+
}
706718
}
707719

708720
impl<'a, I: Interner> ArgFolder<'a, I> {

compiler/rustc_type_ir/src/fold.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use tracing::{debug, instrument};
5454

5555
use crate::inherent::*;
5656
use crate::visit::{TypeVisitable, TypeVisitableExt as _};
57-
use crate::{self as ty, Interner};
57+
use crate::{self as ty, Interner, TypeFlags};
5858

5959
#[cfg(feature = "nightly")]
6060
type Never = !;
@@ -502,4 +502,34 @@ impl<'a, I: Interner> TypeFolder<I> for RegionFolder<'a, I> {
502502
}
503503
}
504504
}
505+
506+
fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
507+
if t.has_type_flags(
508+
TypeFlags::HAS_FREE_REGIONS | TypeFlags::HAS_RE_BOUND | TypeFlags::HAS_RE_ERASED,
509+
) {
510+
t.super_fold_with(self)
511+
} else {
512+
t
513+
}
514+
}
515+
516+
fn fold_const(&mut self, ct: I::Const) -> I::Const {
517+
if ct.has_type_flags(
518+
TypeFlags::HAS_FREE_REGIONS | TypeFlags::HAS_RE_BOUND | TypeFlags::HAS_RE_ERASED,
519+
) {
520+
ct.super_fold_with(self)
521+
} else {
522+
ct
523+
}
524+
}
525+
526+
fn fold_predicate(&mut self, p: I::Predicate) -> I::Predicate {
527+
if p.has_type_flags(
528+
TypeFlags::HAS_FREE_REGIONS | TypeFlags::HAS_RE_BOUND | TypeFlags::HAS_RE_ERASED,
529+
) {
530+
p.super_fold_with(self)
531+
} else {
532+
p
533+
}
534+
}
505535
}

0 commit comments

Comments
 (0)