Skip to content

Commit

Permalink
Remove ControlFlow::{BREAK, CONTINUE}
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
scottmcm committed Jan 28, 2023
1 parent 7d4df2d commit 868d099
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 62 deletions.
8 changes: 4 additions & 4 deletions compiler/rustc_trait_selection/src/solve/project_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,24 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
if t.needs_infer() {
if ty::Term::from(t) == self.term {
ControlFlow::BREAK
ControlFlow::Break(())
} else {
t.super_visit_with(self)
}
} else {
ControlFlow::CONTINUE
ControlFlow::Continue(())
}
}

fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
if c.needs_infer() {
if ty::Term::from(c) == self.term {
ControlFlow::BREAK
ControlFlow::Break(())
} else {
c.super_visit_with(self)
}
} else {
ControlFlow::CONTINUE
ControlFlow::Continue(())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/filter_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ where
) -> impl FnMut((), T) -> ControlFlow<B> + '_ {
move |(), x| match f(x) {
Some(x) => ControlFlow::Break(x),
None => ControlFlow::CONTINUE,
None => ControlFlow::Continue(()),
}
}

Expand Down
4 changes: 2 additions & 2 deletions library/core/src/iter/adapters/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ where
#[rustc_inherit_overflow_checks]
fn advance<U: Iterator>(n: usize, iter: &mut U) -> ControlFlow<(), usize> {
match iter.advance_by(n) {
Ok(()) => ControlFlow::BREAK,
Ok(()) => ControlFlow::Break(()),
Err(advanced) => ControlFlow::Continue(n - advanced),
}
}
Expand Down Expand Up @@ -629,7 +629,7 @@ where
#[rustc_inherit_overflow_checks]
fn advance<U: DoubleEndedIterator>(n: usize, iter: &mut U) -> ControlFlow<(), usize> {
match iter.advance_back_by(n) {
Ok(()) => ControlFlow::BREAK,
Ok(()) => ControlFlow::Break(()),
Err(advanced) => ControlFlow::Continue(n - advanced),
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/traits/double_ended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ pub trait DoubleEndedIterator: Iterator {
#[inline]
fn check<T>(mut predicate: impl FnMut(&T) -> bool) -> impl FnMut((), T) -> ControlFlow<T> {
move |(), x| {
if predicate(&x) { ControlFlow::Break(x) } else { ControlFlow::CONTINUE }
if predicate(&x) { ControlFlow::Break(x) } else { ControlFlow::Continue(()) }
}
}

Expand Down
22 changes: 11 additions & 11 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2601,10 +2601,10 @@ pub trait Iterator {
#[inline]
fn check<T>(mut f: impl FnMut(T) -> bool) -> impl FnMut((), T) -> ControlFlow<()> {
move |(), x| {
if f(x) { ControlFlow::CONTINUE } else { ControlFlow::BREAK }
if f(x) { ControlFlow::Continue(()) } else { ControlFlow::Break(()) }
}
}
self.try_fold((), check(f)) == ControlFlow::CONTINUE
self.try_fold((), check(f)) == ControlFlow::Continue(())
}

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

self.try_fold((), check(f)) == ControlFlow::BREAK
self.try_fold((), check(f)) == ControlFlow::Break(())
}

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

Expand Down Expand Up @@ -2749,7 +2749,7 @@ pub trait Iterator {
fn check<T, B>(mut f: impl FnMut(T) -> Option<B>) -> impl FnMut((), T) -> ControlFlow<B> {
move |(), x| match f(x) {
Some(x) => ControlFlow::Break(x),
None => ControlFlow::CONTINUE,
None => ControlFlow::Continue(()),
}
}

Expand Down Expand Up @@ -2812,7 +2812,7 @@ pub trait Iterator {
R: Residual<Option<I>>,
{
move |(), x| match f(&x).branch() {
ControlFlow::Continue(false) => ControlFlow::CONTINUE,
ControlFlow::Continue(false) => ControlFlow::Continue(()),
ControlFlow::Continue(true) => ControlFlow::Break(Try::from_output(Some(x))),
ControlFlow::Break(r) => ControlFlow::Break(FromResidual::from_residual(r)),
}
Expand Down Expand Up @@ -3491,7 +3491,7 @@ pub trait Iterator {
F: FnMut(X, Y) -> Ordering,
{
move |x, y| match cmp(x, y) {
Ordering::Equal => ControlFlow::CONTINUE,
Ordering::Equal => ControlFlow::Continue(()),
non_eq => ControlFlow::Break(non_eq),
}
}
Expand Down Expand Up @@ -3567,7 +3567,7 @@ pub trait Iterator {
F: FnMut(X, Y) -> Option<Ordering>,
{
move |x, y| match partial_cmp(x, y) {
Some(Ordering::Equal) => ControlFlow::CONTINUE,
Some(Ordering::Equal) => ControlFlow::Continue(()),
non_eq => ControlFlow::Break(non_eq),
}
}
Expand Down Expand Up @@ -3625,7 +3625,7 @@ pub trait Iterator {
F: FnMut(X, Y) -> bool,
{
move |x, y| {
if eq(x, y) { ControlFlow::CONTINUE } else { ControlFlow::BREAK }
if eq(x, y) { ControlFlow::Continue(()) } else { ControlFlow::Break(()) }
}
}

Expand Down Expand Up @@ -3859,7 +3859,7 @@ pub trait Iterator {

/// Compares two iterators element-wise using the given function.
///
/// If `ControlFlow::CONTINUE` is returned from the function, the comparison moves on to the next
/// If `ControlFlow::Continue(())` is returned from the function, the comparison moves on to the next
/// elements of both iterators. Returning `ControlFlow::Break(x)` short-circuits the iteration and
/// returns `ControlFlow::Break(x)`. If one of the iterators runs out of elements,
/// `ControlFlow::Continue(ord)` is returned where `ord` is the result of comparing the lengths of
Expand Down
43 changes: 0 additions & 43 deletions library/core/src/ops/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,46 +259,3 @@ impl<R: ops::Try> ControlFlow<R, R::Output> {
}
}
}

impl<B> ControlFlow<B, ()> {
/// It's frequently the case that there's no value needed with `Continue`,
/// so this provides a way to avoid typing `(())`, if you prefer it.
///
/// # Examples
///
/// ```
/// #![feature(control_flow_enum)]
/// use std::ops::ControlFlow;
///
/// let mut partial_sum = 0;
/// let last_used = (1..10).chain(20..25).try_for_each(|x| {
/// partial_sum += x;
/// if partial_sum > 100 { ControlFlow::Break(x) }
/// else { ControlFlow::CONTINUE }
/// });
/// assert_eq!(last_used.break_value(), Some(22));
/// ```
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
pub const CONTINUE: Self = ControlFlow::Continue(());
}

impl<C> ControlFlow<(), C> {
/// APIs like `try_for_each` don't need values with `Break`,
/// so this provides a way to avoid typing `(())`, if you prefer it.
///
/// # Examples
///
/// ```
/// #![feature(control_flow_enum)]
/// use std::ops::ControlFlow;
///
/// let mut partial_sum = 0;
/// (1..10).chain(20..25).try_for_each(|x| {
/// if partial_sum > 100 { ControlFlow::BREAK }
/// else { partial_sum += x; ControlFlow::CONTINUE }
/// });
/// assert_eq!(partial_sum, 108);
/// ```
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
pub const BREAK: Self = ControlFlow::Break(());
}

0 comments on commit 868d099

Please sign in to comment.