Use ControlFlow::is{break,continue}

This commit is contained in:
LeSeulArtichaut 2020-10-22 10:20:24 +02:00
parent 8e4cf0b3ed
commit 24e1a7e656
10 changed files with 25 additions and 25 deletions

View File

@ -109,7 +109,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
args.visit_with(visitor)
}
Assert { ref cond, ref msg, .. } => {
if cond.visit_with(visitor) == ControlFlow::BREAK {
if cond.visit_with(visitor).is_break() {
use AssertKind::*;
match msg {
BoundsCheck { ref len, ref index } => {

View File

@ -59,8 +59,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
/// If `binder` is `ty::INNERMOST`, this indicates whether
/// there are any late-bound regions that appear free.
fn has_vars_bound_at_or_above(&self, binder: ty::DebruijnIndex) -> bool {
self.visit_with(&mut HasEscapingVarsVisitor { outer_index: binder })
== ControlFlow::Break(())
self.visit_with(&mut HasEscapingVarsVisitor { outer_index: binder }).is_break()
}
/// Returns `true` if this `self` has any regions that escape `binder` (and
@ -74,7 +73,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
}
fn has_type_flags(&self, flags: TypeFlags) -> bool {
self.visit_with(&mut HasTypeFlagsVisitor { flags }) == ControlFlow::Break(())
self.visit_with(&mut HasTypeFlagsVisitor { flags }).is_break()
}
fn has_projections(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_PROJECTION)
@ -368,8 +367,7 @@ impl<'tcx> TyCtxt<'tcx> {
}
}
value.visit_with(&mut RegionVisitor { outer_index: ty::INNERMOST, callback })
== ControlFlow::BREAK
value.visit_with(&mut RegionVisitor { outer_index: ty::INNERMOST, callback }).is_break()
}
}
@ -685,7 +683,7 @@ impl<'tcx> TyCtxt<'tcx> {
{
let mut collector = LateBoundRegionsCollector::new(just_constraint);
let result = value.as_ref().skip_binder().visit_with(&mut collector);
assert!(result == ControlFlow::Continue(())); // should never have stopped early
assert!(result.is_continue()); // should never have stopped early
collector.regions
}

View File

@ -74,7 +74,7 @@ where
}
let mut vis = UsedParamsNeedSubstVisitor { tcx };
if ty.visit_with(&mut vis) == ControlFlow::BREAK {
if ty.visit_with(&mut vis).is_break() {
throw_inval!(TooGeneric);
} else {
Ok(())

View File

@ -139,7 +139,7 @@ fn mark_used_by_predicates<'tcx>(
// predicate is used.
let any_param_used = {
let mut vis = HasUsedGenericParams { unused_parameters };
predicate.visit_with(&mut vis) == ControlFlow::BREAK
predicate.visit_with(&mut vis).is_break()
};
if any_param_used {

View File

@ -1086,7 +1086,7 @@ impl<'tcx> TypePrivacyVisitor<'tcx> {
adjustments.iter().try_for_each(|adjustment| self.visit(adjustment.target))?;
}
};
result == ControlFlow::BREAK
result.is_break()
}
fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display) -> bool {
@ -1128,14 +1128,14 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
self.span = hir_ty.span;
if let Some(typeck_results) = self.maybe_typeck_results {
// Types in bodies.
if self.visit(typeck_results.node_type(hir_ty.hir_id)) == ControlFlow::BREAK {
if self.visit(typeck_results.node_type(hir_ty.hir_id)).is_break() {
return;
}
} else {
// Types in signatures.
// FIXME: This is very ineffective. Ideally each HIR type should be converted
// into a semantic type only once and the result should be cached somehow.
if self.visit(rustc_typeck::hir_ty_to_ty(self.tcx, hir_ty)) == ControlFlow::BREAK {
if self.visit(rustc_typeck::hir_ty_to_ty(self.tcx, hir_ty)).is_break() {
return;
}
}
@ -1157,16 +1157,17 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
);
for (trait_predicate, _, _) in bounds.trait_bounds {
if self.visit_trait(trait_predicate.skip_binder()) == ControlFlow::BREAK {
if self.visit_trait(trait_predicate.skip_binder()).is_break() {
return;
}
}
for (poly_predicate, _) in bounds.projection_bounds {
let tcx = self.tcx;
if self.visit(poly_predicate.skip_binder().ty) == ControlFlow::BREAK
|| self.visit_trait(poly_predicate.skip_binder().projection_ty.trait_ref(tcx))
== ControlFlow::BREAK
if self.visit(poly_predicate.skip_binder().ty).is_break()
|| self
.visit_trait(poly_predicate.skip_binder().projection_ty.trait_ref(tcx))
.is_break()
{
return;
}
@ -1193,7 +1194,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
// Method calls have to be checked specially.
self.span = span;
if let Some(def_id) = self.typeck_results().type_dependent_def_id(expr.hir_id) {
if self.visit(self.tcx.type_of(def_id)) == ControlFlow::BREAK {
if self.visit(self.tcx.type_of(def_id)).is_break() {
return;
}
} else {

View File

@ -869,8 +869,9 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
}
}
value.visit_with(&mut IllegalSelfTypeVisitor { tcx, trait_def_id, supertraits: None })
== ControlFlow::BREAK
value
.visit_with(&mut IllegalSelfTypeVisitor { tcx, trait_def_id, supertraits: None })
.is_break()
}
pub fn provide(providers: &mut ty::query::Providers) {

View File

@ -248,7 +248,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
let ty = self.tcx().normalize_erasing_regions(ty::ParamEnv::empty(), field_ty);
debug!("structural-match ADT: field_ty={:?}, ty={:?}", field_ty, ty);
if ty.visit_with(self) == ControlFlow::BREAK {
if ty.visit_with(self).is_break() {
// found an ADT without structural-match; halt visiting!
assert!(self.found.is_some());
return ControlFlow::BREAK;

View File

@ -452,7 +452,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
impl<'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueVisitor<'tcx> {
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<(), ()> {
debug!("check_opaque_for_inheriting_lifetimes: (visit_ty) t={:?}", t);
if t != self.opaque_identity_ty && t.super_visit_with(self) == ControlFlow::BREAK {
if t != self.opaque_identity_ty && t.super_visit_with(self).is_break() {
self.ty = Some(t);
return ControlFlow::BREAK;
}
@ -499,7 +499,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
let prohibit_opaque = tcx
.explicit_item_bounds(def_id)
.iter()
.any(|(predicate, _)| predicate.visit_with(&mut visitor) == ControlFlow::BREAK);
.any(|(predicate, _)| predicate.visit_with(&mut visitor).is_break());
debug!(
"check_opaque_for_inheriting_lifetimes: prohibit_opaque={:?}, visitor={:?}",
prohibit_opaque, visitor

View File

@ -819,7 +819,7 @@ fn check_where_clauses<'tcx, 'fcx>(
}
}
let mut param_count = CountParams::default();
let has_region = pred.visit_with(&mut param_count) == ControlFlow::BREAK;
let has_region = pred.visit_with(&mut param_count).is_break();
let substituted_pred = pred.subst(fcx.tcx, substs);
// Don't check non-defaulted params, dependent defaults (including lifetimes)
// or preds with multiple params.

View File

@ -518,7 +518,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> {
self.possible_borrower.add(borrowed.local, lhs);
},
other => {
if ContainsRegion.visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty) == ControlFlow::CONTINUE {
if ContainsRegion.visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty).is_continue() {
return;
}
rvalue_locals(other, |rhs| {
@ -540,7 +540,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> {
// If the call returns something with lifetimes,
// let's conservatively assume the returned value contains lifetime of all the arguments.
// For example, given `let y: Foo<'a> = foo(x)`, `y` is considered to be a possible borrower of `x`.
if ContainsRegion.visit_ty(&self.body.local_decls[*dest].ty) == ControlFlow::CONTINUE {
if ContainsRegion.visit_ty(&self.body.local_decls[*dest].ty).is_continue() {
return;
}