Skip to content

Commit 44f7d8f

Browse files
Use TypeVisitor::BreakTy in HasEscapingVarsVisitor
1 parent 29b140a commit 44f7d8f

File tree

1 file changed

+11
-4
lines changed
  • compiler/rustc_middle/src/ty

1 file changed

+11
-4
lines changed

compiler/rustc_middle/src/ty/fold.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,9 @@ where
818818
value.fold_with(&mut Shifter::new(tcx, amount))
819819
}
820820

821+
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
822+
struct FoundEscapingVars;
823+
821824
/// An "escaping var" is a bound var whose binder is not part of `t`. A bound var can be a
822825
/// bound region or a bound type.
823826
///
@@ -849,6 +852,8 @@ struct HasEscapingVarsVisitor {
849852
}
850853

851854
impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
855+
type BreakTy = FoundEscapingVars;
856+
852857
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> ControlFlow<Self::BreakTy> {
853858
self.outer_index.shift_in(1);
854859
let result = t.super_visit_with(self);
@@ -863,7 +868,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
863868
// `outer_exclusive_binder` is always 1 higher than the
864869
// content in `t`). Therefore, `t` has some escaping vars.
865870
if t.outer_exclusive_binder > self.outer_index {
866-
ControlFlow::BREAK
871+
ControlFlow::Break(FoundEscapingVars)
867872
} else {
868873
ControlFlow::CONTINUE
869874
}
@@ -874,7 +879,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
874879
// of outer index, then it escapes the binders we have
875880
// visited.
876881
if r.bound_at_or_above_binder(self.outer_index) {
877-
ControlFlow::BREAK
882+
ControlFlow::Break(FoundEscapingVars)
878883
} else {
879884
ControlFlow::CONTINUE
880885
}
@@ -887,14 +892,16 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
887892
// const, as it has types/regions embedded in a lot of other
888893
// places.
889894
match ct.val {
890-
ty::ConstKind::Bound(debruijn, _) if debruijn >= self.outer_index => ControlFlow::BREAK,
895+
ty::ConstKind::Bound(debruijn, _) if debruijn >= self.outer_index => {
896+
ControlFlow::Break(FoundEscapingVars)
897+
}
891898
_ => ct.super_visit_with(self),
892899
}
893900
}
894901

895902
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
896903
if predicate.inner.outer_exclusive_binder > self.outer_index {
897-
ControlFlow::BREAK
904+
ControlFlow::Break(FoundEscapingVars)
898905
} else {
899906
ControlFlow::CONTINUE
900907
}

0 commit comments

Comments
 (0)