Skip to content

Commit 24e1a7e

Browse files
Use ControlFlow::is{break,continue}
1 parent 8e4cf0b commit 24e1a7e

File tree

10 files changed

+25
-25
lines changed

10 files changed

+25
-25
lines changed

compiler/rustc_middle/src/mir/type_foldable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
109109
args.visit_with(visitor)
110110
}
111111
Assert { ref cond, ref msg, .. } => {
112-
if cond.visit_with(visitor) == ControlFlow::BREAK {
112+
if cond.visit_with(visitor).is_break() {
113113
use AssertKind::*;
114114
match msg {
115115
BoundsCheck { ref len, ref index } => {

compiler/rustc_middle/src/ty/fold.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
5959
/// If `binder` is `ty::INNERMOST`, this indicates whether
6060
/// there are any late-bound regions that appear free.
6161
fn has_vars_bound_at_or_above(&self, binder: ty::DebruijnIndex) -> bool {
62-
self.visit_with(&mut HasEscapingVarsVisitor { outer_index: binder })
63-
== ControlFlow::Break(())
62+
self.visit_with(&mut HasEscapingVarsVisitor { outer_index: binder }).is_break()
6463
}
6564

6665
/// Returns `true` if this `self` has any regions that escape `binder` (and
@@ -74,7 +73,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
7473
}
7574

7675
fn has_type_flags(&self, flags: TypeFlags) -> bool {
77-
self.visit_with(&mut HasTypeFlagsVisitor { flags }) == ControlFlow::Break(())
76+
self.visit_with(&mut HasTypeFlagsVisitor { flags }).is_break()
7877
}
7978
fn has_projections(&self) -> bool {
8079
self.has_type_flags(TypeFlags::HAS_PROJECTION)
@@ -368,8 +367,7 @@ impl<'tcx> TyCtxt<'tcx> {
368367
}
369368
}
370369

371-
value.visit_with(&mut RegionVisitor { outer_index: ty::INNERMOST, callback })
372-
== ControlFlow::BREAK
370+
value.visit_with(&mut RegionVisitor { outer_index: ty::INNERMOST, callback }).is_break()
373371
}
374372
}
375373

@@ -685,7 +683,7 @@ impl<'tcx> TyCtxt<'tcx> {
685683
{
686684
let mut collector = LateBoundRegionsCollector::new(just_constraint);
687685
let result = value.as_ref().skip_binder().visit_with(&mut collector);
688-
assert!(result == ControlFlow::Continue(())); // should never have stopped early
686+
assert!(result.is_continue()); // should never have stopped early
689687
collector.regions
690688
}
691689

compiler/rustc_mir/src/interpret/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ where
7474
}
7575

7676
let mut vis = UsedParamsNeedSubstVisitor { tcx };
77-
if ty.visit_with(&mut vis) == ControlFlow::BREAK {
77+
if ty.visit_with(&mut vis).is_break() {
7878
throw_inval!(TooGeneric);
7979
} else {
8080
Ok(())

compiler/rustc_mir/src/monomorphize/polymorphize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn mark_used_by_predicates<'tcx>(
139139
// predicate is used.
140140
let any_param_used = {
141141
let mut vis = HasUsedGenericParams { unused_parameters };
142-
predicate.visit_with(&mut vis) == ControlFlow::BREAK
142+
predicate.visit_with(&mut vis).is_break()
143143
};
144144

145145
if any_param_used {

compiler/rustc_privacy/src/lib.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ impl<'tcx> TypePrivacyVisitor<'tcx> {
10861086
adjustments.iter().try_for_each(|adjustment| self.visit(adjustment.target))?;
10871087
}
10881088
};
1089-
result == ControlFlow::BREAK
1089+
result.is_break()
10901090
}
10911091

10921092
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> {
11281128
self.span = hir_ty.span;
11291129
if let Some(typeck_results) = self.maybe_typeck_results {
11301130
// Types in bodies.
1131-
if self.visit(typeck_results.node_type(hir_ty.hir_id)) == ControlFlow::BREAK {
1131+
if self.visit(typeck_results.node_type(hir_ty.hir_id)).is_break() {
11321132
return;
11331133
}
11341134
} else {
11351135
// Types in signatures.
11361136
// FIXME: This is very ineffective. Ideally each HIR type should be converted
11371137
// into a semantic type only once and the result should be cached somehow.
1138-
if self.visit(rustc_typeck::hir_ty_to_ty(self.tcx, hir_ty)) == ControlFlow::BREAK {
1138+
if self.visit(rustc_typeck::hir_ty_to_ty(self.tcx, hir_ty)).is_break() {
11391139
return;
11401140
}
11411141
}
@@ -1157,16 +1157,17 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
11571157
);
11581158

11591159
for (trait_predicate, _, _) in bounds.trait_bounds {
1160-
if self.visit_trait(trait_predicate.skip_binder()) == ControlFlow::BREAK {
1160+
if self.visit_trait(trait_predicate.skip_binder()).is_break() {
11611161
return;
11621162
}
11631163
}
11641164

11651165
for (poly_predicate, _) in bounds.projection_bounds {
11661166
let tcx = self.tcx;
1167-
if self.visit(poly_predicate.skip_binder().ty) == ControlFlow::BREAK
1168-
|| self.visit_trait(poly_predicate.skip_binder().projection_ty.trait_ref(tcx))
1169-
== ControlFlow::BREAK
1167+
if self.visit(poly_predicate.skip_binder().ty).is_break()
1168+
|| self
1169+
.visit_trait(poly_predicate.skip_binder().projection_ty.trait_ref(tcx))
1170+
.is_break()
11701171
{
11711172
return;
11721173
}
@@ -1193,7 +1194,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
11931194
// Method calls have to be checked specially.
11941195
self.span = span;
11951196
if let Some(def_id) = self.typeck_results().type_dependent_def_id(expr.hir_id) {
1196-
if self.visit(self.tcx.type_of(def_id)) == ControlFlow::BREAK {
1197+
if self.visit(self.tcx.type_of(def_id)).is_break() {
11971198
return;
11981199
}
11991200
} else {

compiler/rustc_trait_selection/src/traits/object_safety.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,9 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
869869
}
870870
}
871871

872-
value.visit_with(&mut IllegalSelfTypeVisitor { tcx, trait_def_id, supertraits: None })
873-
== ControlFlow::BREAK
872+
value
873+
.visit_with(&mut IllegalSelfTypeVisitor { tcx, trait_def_id, supertraits: None })
874+
.is_break()
874875
}
875876

876877
pub fn provide(providers: &mut ty::query::Providers) {

compiler/rustc_trait_selection/src/traits/structural_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
248248
let ty = self.tcx().normalize_erasing_regions(ty::ParamEnv::empty(), field_ty);
249249
debug!("structural-match ADT: field_ty={:?}, ty={:?}", field_ty, ty);
250250

251-
if ty.visit_with(self) == ControlFlow::BREAK {
251+
if ty.visit_with(self).is_break() {
252252
// found an ADT without structural-match; halt visiting!
253253
assert!(self.found.is_some());
254254
return ControlFlow::BREAK;

compiler/rustc_typeck/src/check/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
452452
impl<'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueVisitor<'tcx> {
453453
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<(), ()> {
454454
debug!("check_opaque_for_inheriting_lifetimes: (visit_ty) t={:?}", t);
455-
if t != self.opaque_identity_ty && t.super_visit_with(self) == ControlFlow::BREAK {
455+
if t != self.opaque_identity_ty && t.super_visit_with(self).is_break() {
456456
self.ty = Some(t);
457457
return ControlFlow::BREAK;
458458
}
@@ -499,7 +499,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
499499
let prohibit_opaque = tcx
500500
.explicit_item_bounds(def_id)
501501
.iter()
502-
.any(|(predicate, _)| predicate.visit_with(&mut visitor) == ControlFlow::BREAK);
502+
.any(|(predicate, _)| predicate.visit_with(&mut visitor).is_break());
503503
debug!(
504504
"check_opaque_for_inheriting_lifetimes: prohibit_opaque={:?}, visitor={:?}",
505505
prohibit_opaque, visitor

compiler/rustc_typeck/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ fn check_where_clauses<'tcx, 'fcx>(
819819
}
820820
}
821821
let mut param_count = CountParams::default();
822-
let has_region = pred.visit_with(&mut param_count) == ControlFlow::BREAK;
822+
let has_region = pred.visit_with(&mut param_count).is_break();
823823
let substituted_pred = pred.subst(fcx.tcx, substs);
824824
// Don't check non-defaulted params, dependent defaults (including lifetimes)
825825
// or preds with multiple params.

src/tools/clippy/clippy_lints/src/redundant_clone.rs

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

0 commit comments

Comments
 (0)