Skip to content

Commit 868d099

Browse files
committed
Remove ControlFlow::{BREAK, CONTINUE}
Libs-API decided to remove these in #102697. Follow-up to #107023, which removed them from `compiler/`, but a couple new ones showed up since that was merged.
1 parent 7d4df2d commit 868d099

File tree

6 files changed

+19
-62
lines changed

6 files changed

+19
-62
lines changed

compiler/rustc_trait_selection/src/solve/project_goals.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,24 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
9393
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
9494
if t.needs_infer() {
9595
if ty::Term::from(t) == self.term {
96-
ControlFlow::BREAK
96+
ControlFlow::Break(())
9797
} else {
9898
t.super_visit_with(self)
9999
}
100100
} else {
101-
ControlFlow::CONTINUE
101+
ControlFlow::Continue(())
102102
}
103103
}
104104

105105
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
106106
if c.needs_infer() {
107107
if ty::Term::from(c) == self.term {
108-
ControlFlow::BREAK
108+
ControlFlow::Break(())
109109
} else {
110110
c.super_visit_with(self)
111111
}
112112
} else {
113-
ControlFlow::CONTINUE
113+
ControlFlow::Continue(())
114114
}
115115
}
116116
}

library/core/src/iter/adapters/filter_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ where
9999
) -> impl FnMut((), T) -> ControlFlow<B> + '_ {
100100
move |(), x| match f(x) {
101101
Some(x) => ControlFlow::Break(x),
102-
None => ControlFlow::CONTINUE,
102+
None => ControlFlow::Continue(()),
103103
}
104104
}
105105

library/core/src/iter/adapters/flatten.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ where
539539
#[rustc_inherit_overflow_checks]
540540
fn advance<U: Iterator>(n: usize, iter: &mut U) -> ControlFlow<(), usize> {
541541
match iter.advance_by(n) {
542-
Ok(()) => ControlFlow::BREAK,
542+
Ok(()) => ControlFlow::Break(()),
543543
Err(advanced) => ControlFlow::Continue(n - advanced),
544544
}
545545
}
@@ -629,7 +629,7 @@ where
629629
#[rustc_inherit_overflow_checks]
630630
fn advance<U: DoubleEndedIterator>(n: usize, iter: &mut U) -> ControlFlow<(), usize> {
631631
match iter.advance_back_by(n) {
632-
Ok(()) => ControlFlow::BREAK,
632+
Ok(()) => ControlFlow::Break(()),
633633
Err(advanced) => ControlFlow::Continue(n - advanced),
634634
}
635635
}

library/core/src/iter/traits/double_ended.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ pub trait DoubleEndedIterator: Iterator {
352352
#[inline]
353353
fn check<T>(mut predicate: impl FnMut(&T) -> bool) -> impl FnMut((), T) -> ControlFlow<T> {
354354
move |(), x| {
355-
if predicate(&x) { ControlFlow::Break(x) } else { ControlFlow::CONTINUE }
355+
if predicate(&x) { ControlFlow::Break(x) } else { ControlFlow::Continue(()) }
356356
}
357357
}
358358

library/core/src/iter/traits/iterator.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -2601,10 +2601,10 @@ pub trait Iterator {
26012601
#[inline]
26022602
fn check<T>(mut f: impl FnMut(T) -> bool) -> impl FnMut((), T) -> ControlFlow<()> {
26032603
move |(), x| {
2604-
if f(x) { ControlFlow::CONTINUE } else { ControlFlow::BREAK }
2604+
if f(x) { ControlFlow::Continue(()) } else { ControlFlow::Break(()) }
26052605
}
26062606
}
2607-
self.try_fold((), check(f)) == ControlFlow::CONTINUE
2607+
self.try_fold((), check(f)) == ControlFlow::Continue(())
26082608
}
26092609

26102610
/// Tests if any element of the iterator matches a predicate.
@@ -2654,11 +2654,11 @@ pub trait Iterator {
26542654
#[inline]
26552655
fn check<T>(mut f: impl FnMut(T) -> bool) -> impl FnMut((), T) -> ControlFlow<()> {
26562656
move |(), x| {
2657-
if f(x) { ControlFlow::BREAK } else { ControlFlow::CONTINUE }
2657+
if f(x) { ControlFlow::Break(()) } else { ControlFlow::Continue(()) }
26582658
}
26592659
}
26602660

2661-
self.try_fold((), check(f)) == ControlFlow::BREAK
2661+
self.try_fold((), check(f)) == ControlFlow::Break(())
26622662
}
26632663

26642664
/// Searches for an element of an iterator that satisfies a predicate.
@@ -2717,7 +2717,7 @@ pub trait Iterator {
27172717
#[inline]
27182718
fn check<T>(mut predicate: impl FnMut(&T) -> bool) -> impl FnMut((), T) -> ControlFlow<T> {
27192719
move |(), x| {
2720-
if predicate(&x) { ControlFlow::Break(x) } else { ControlFlow::CONTINUE }
2720+
if predicate(&x) { ControlFlow::Break(x) } else { ControlFlow::Continue(()) }
27212721
}
27222722
}
27232723

@@ -2749,7 +2749,7 @@ pub trait Iterator {
27492749
fn check<T, B>(mut f: impl FnMut(T) -> Option<B>) -> impl FnMut((), T) -> ControlFlow<B> {
27502750
move |(), x| match f(x) {
27512751
Some(x) => ControlFlow::Break(x),
2752-
None => ControlFlow::CONTINUE,
2752+
None => ControlFlow::Continue(()),
27532753
}
27542754
}
27552755

@@ -2812,7 +2812,7 @@ pub trait Iterator {
28122812
R: Residual<Option<I>>,
28132813
{
28142814
move |(), x| match f(&x).branch() {
2815-
ControlFlow::Continue(false) => ControlFlow::CONTINUE,
2815+
ControlFlow::Continue(false) => ControlFlow::Continue(()),
28162816
ControlFlow::Continue(true) => ControlFlow::Break(Try::from_output(Some(x))),
28172817
ControlFlow::Break(r) => ControlFlow::Break(FromResidual::from_residual(r)),
28182818
}
@@ -3491,7 +3491,7 @@ pub trait Iterator {
34913491
F: FnMut(X, Y) -> Ordering,
34923492
{
34933493
move |x, y| match cmp(x, y) {
3494-
Ordering::Equal => ControlFlow::CONTINUE,
3494+
Ordering::Equal => ControlFlow::Continue(()),
34953495
non_eq => ControlFlow::Break(non_eq),
34963496
}
34973497
}
@@ -3567,7 +3567,7 @@ pub trait Iterator {
35673567
F: FnMut(X, Y) -> Option<Ordering>,
35683568
{
35693569
move |x, y| match partial_cmp(x, y) {
3570-
Some(Ordering::Equal) => ControlFlow::CONTINUE,
3570+
Some(Ordering::Equal) => ControlFlow::Continue(()),
35713571
non_eq => ControlFlow::Break(non_eq),
35723572
}
35733573
}
@@ -3625,7 +3625,7 @@ pub trait Iterator {
36253625
F: FnMut(X, Y) -> bool,
36263626
{
36273627
move |x, y| {
3628-
if eq(x, y) { ControlFlow::CONTINUE } else { ControlFlow::BREAK }
3628+
if eq(x, y) { ControlFlow::Continue(()) } else { ControlFlow::Break(()) }
36293629
}
36303630
}
36313631

@@ -3859,7 +3859,7 @@ pub trait Iterator {
38593859

38603860
/// Compares two iterators element-wise using the given function.
38613861
///
3862-
/// If `ControlFlow::CONTINUE` is returned from the function, the comparison moves on to the next
3862+
/// If `ControlFlow::Continue(())` is returned from the function, the comparison moves on to the next
38633863
/// elements of both iterators. Returning `ControlFlow::Break(x)` short-circuits the iteration and
38643864
/// returns `ControlFlow::Break(x)`. If one of the iterators runs out of elements,
38653865
/// `ControlFlow::Continue(ord)` is returned where `ord` is the result of comparing the lengths of

library/core/src/ops/control_flow.rs

-43
Original file line numberDiff line numberDiff line change
@@ -259,46 +259,3 @@ impl<R: ops::Try> ControlFlow<R, R::Output> {
259259
}
260260
}
261261
}
262-
263-
impl<B> ControlFlow<B, ()> {
264-
/// It's frequently the case that there's no value needed with `Continue`,
265-
/// so this provides a way to avoid typing `(())`, if you prefer it.
266-
///
267-
/// # Examples
268-
///
269-
/// ```
270-
/// #![feature(control_flow_enum)]
271-
/// use std::ops::ControlFlow;
272-
///
273-
/// let mut partial_sum = 0;
274-
/// let last_used = (1..10).chain(20..25).try_for_each(|x| {
275-
/// partial_sum += x;
276-
/// if partial_sum > 100 { ControlFlow::Break(x) }
277-
/// else { ControlFlow::CONTINUE }
278-
/// });
279-
/// assert_eq!(last_used.break_value(), Some(22));
280-
/// ```
281-
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
282-
pub const CONTINUE: Self = ControlFlow::Continue(());
283-
}
284-
285-
impl<C> ControlFlow<(), C> {
286-
/// APIs like `try_for_each` don't need values with `Break`,
287-
/// so this provides a way to avoid typing `(())`, if you prefer it.
288-
///
289-
/// # Examples
290-
///
291-
/// ```
292-
/// #![feature(control_flow_enum)]
293-
/// use std::ops::ControlFlow;
294-
///
295-
/// let mut partial_sum = 0;
296-
/// (1..10).chain(20..25).try_for_each(|x| {
297-
/// if partial_sum > 100 { ControlFlow::BREAK }
298-
/// else { partial_sum += x; ControlFlow::CONTINUE }
299-
/// });
300-
/// assert_eq!(partial_sum, 108);
301-
/// ```
302-
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
303-
pub const BREAK: Self = ControlFlow::Break(());
304-
}

0 commit comments

Comments
 (0)