Skip to content

Commit 29b140a

Browse files
Use TypeVisitor::BreakTy in HasTypeFlagsVisitor
1 parent 23feec3 commit 29b140a

File tree

1 file changed

+22
-5
lines changed
  • compiler/rustc_middle/src/ty

1 file changed

+22
-5
lines changed

compiler/rustc_middle/src/ty/fold.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
7373
}
7474

7575
fn has_type_flags(&self, flags: TypeFlags) -> bool {
76-
self.visit_with(&mut HasTypeFlagsVisitor { flags }).is_break()
76+
self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags)
7777
}
7878
fn has_projections(&self) -> bool {
7979
self.has_type_flags(TypeFlags::HAS_PROJECTION)
@@ -901,32 +901,49 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
901901
}
902902
}
903903

904+
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
905+
struct FoundFlags;
906+
904907
// FIXME: Optimize for checking for infer flags
905908
struct HasTypeFlagsVisitor {
906909
flags: ty::TypeFlags,
907910
}
908911

909912
impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
913+
type BreakTy = FoundFlags;
914+
910915
fn visit_ty(&mut self, t: Ty<'_>) -> ControlFlow<Self::BreakTy> {
911916
debug!(
912917
"HasTypeFlagsVisitor: t={:?} t.flags={:?} self.flags={:?}",
913918
t,
914919
t.flags(),
915920
self.flags
916921
);
917-
if t.flags().intersects(self.flags) { ControlFlow::BREAK } else { ControlFlow::CONTINUE }
922+
if t.flags().intersects(self.flags) {
923+
ControlFlow::Break(FoundFlags)
924+
} else {
925+
ControlFlow::CONTINUE
926+
}
918927
}
919928

920929
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
921930
let flags = r.type_flags();
922931
debug!("HasTypeFlagsVisitor: r={:?} r.flags={:?} self.flags={:?}", r, flags, self.flags);
923-
if flags.intersects(self.flags) { ControlFlow::BREAK } else { ControlFlow::CONTINUE }
932+
if flags.intersects(self.flags) {
933+
ControlFlow::Break(FoundFlags)
934+
} else {
935+
ControlFlow::CONTINUE
936+
}
924937
}
925938

926939
fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
927940
let flags = FlagComputation::for_const(c);
928941
debug!("HasTypeFlagsVisitor: c={:?} c.flags={:?} self.flags={:?}", c, flags, self.flags);
929-
if flags.intersects(self.flags) { ControlFlow::BREAK } else { ControlFlow::CONTINUE }
942+
if flags.intersects(self.flags) {
943+
ControlFlow::Break(FoundFlags)
944+
} else {
945+
ControlFlow::CONTINUE
946+
}
930947
}
931948

932949
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
@@ -935,7 +952,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
935952
predicate, predicate.inner.flags, self.flags
936953
);
937954
if predicate.inner.flags.intersects(self.flags) {
938-
ControlFlow::BREAK
955+
ControlFlow::Break(FoundFlags)
939956
} else {
940957
ControlFlow::CONTINUE
941958
}

0 commit comments

Comments
 (0)