1
Fork 0

Introduce TypeVisitor::BreakTy

This commit is contained in:
LeSeulArtichaut 2020-11-05 17:30:39 +01:00
parent 30e49a9ead
commit e0f3119103
31 changed files with 157 additions and 128 deletions

View file

@ -693,12 +693,15 @@ impl<'tcx, OP> TypeVisitor<'tcx> for ConstrainOpaqueTypeRegionVisitor<OP>
where
OP: FnMut(ty::Region<'tcx>),
{
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ControlFlow<()> {
fn visit_binder<T: TypeFoldable<'tcx>>(
&mut self,
t: &ty::Binder<T>,
) -> ControlFlow<Self::BreakTy> {
t.as_ref().skip_binder().visit_with(self);
ControlFlow::CONTINUE
}
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<()> {
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
match *r {
// ignore bound regions, keep visiting
ty::ReLateBound(_, _) => ControlFlow::CONTINUE,
@ -709,7 +712,7 @@ where
}
}
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<()> {
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
// We're only interested in types involving regions
if !ty.flags().intersects(ty::TypeFlags::HAS_FREE_REGIONS) {
return ControlFlow::CONTINUE;

View file

@ -78,7 +78,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
Concrete,
}
let mut failure_kind = FailureKind::Concrete;
walk_abstract_const(tcx, ct, |node| match node {
walk_abstract_const::<!, _>(tcx, ct, |node| match node {
Node::Leaf(leaf) => {
let leaf = leaf.subst(tcx, ct.substs);
if leaf.has_infer_types_or_consts() {
@ -574,19 +574,19 @@ pub(super) fn try_unify_abstract_consts<'tcx>(
// on `ErrorReported`.
}
pub fn walk_abstract_const<'tcx, F>(
pub fn walk_abstract_const<'tcx, R, F>(
tcx: TyCtxt<'tcx>,
ct: AbstractConst<'tcx>,
mut f: F,
) -> ControlFlow<()>
) -> ControlFlow<R>
where
F: FnMut(Node<'tcx>) -> ControlFlow<()>,
F: FnMut(Node<'tcx>) -> ControlFlow<R>,
{
fn recurse<'tcx>(
fn recurse<'tcx, R>(
tcx: TyCtxt<'tcx>,
ct: AbstractConst<'tcx>,
f: &mut dyn FnMut(Node<'tcx>) -> ControlFlow<()>,
) -> ControlFlow<()> {
f: &mut dyn FnMut(Node<'tcx>) -> ControlFlow<R>,
) -> ControlFlow<R> {
let root = ct.root();
f(root)?;
match root {

View file

@ -771,7 +771,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
}
impl<'tcx> TypeVisitor<'tcx> for IllegalSelfTypeVisitor<'tcx> {
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<()> {
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
match t.kind() {
ty::Param(_) => {
if t == self.tcx.types.self_param {
@ -812,7 +812,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
}
}
fn visit_const(&mut self, ct: &ty::Const<'tcx>) -> ControlFlow<()> {
fn visit_const(&mut self, ct: &ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
// First check if the type of this constant references `Self`.
self.visit_ty(ct.ty)?;
@ -844,7 +844,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
}
}
fn visit_predicate(&mut self, pred: ty::Predicate<'tcx>) -> ControlFlow<()> {
fn visit_predicate(&mut self, pred: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::PredicateAtom::ConstEvaluatable(def, substs) = pred.skip_binders() {
// FIXME(const_evaluatable_checked): We should probably deduplicate the logic for
// `AbstractConst`s here, it might make sense to change `ConstEvaluatable` to

View file

@ -135,7 +135,7 @@ impl Search<'a, 'tcx> {
}
impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<()> {
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
debug!("Search visiting ty: {:?}", ty);
let (adt_def, substs) = match *ty.kind() {