Skip to content

Commit

Permalink
Format ControlFlow changes with rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
NoraCodes committed Sep 2, 2020
1 parent d0af125 commit 96eb5e1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cmp;
use crate::fmt;
use crate::intrinsics;
use crate::ops::{Add, AddAssign, Try, ControlFlow};
use crate::ops::{Add, AddAssign, ControlFlow, Try};

use super::from_fn;
use super::{DoubleEndedIterator, ExactSizeIterator, FusedIterator, Iterator, TrustedLen};
Expand Down
1 change: 0 additions & 1 deletion library/core/src/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,3 @@ mod adapters;
mod range;
mod sources;
mod traits;

2 changes: 1 addition & 1 deletion library/core/src/iter/traits/double_ended.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ops::{Try, ControlFlow};
use crate::ops::{ControlFlow, Try};

/// An iterator able to yield elements from both ends.
///
Expand Down
12 changes: 9 additions & 3 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// can't split that into multiple files.

use crate::cmp::{self, Ordering};
use crate::ops::{Add, Try, ControlFlow};
use crate::ops::{Add, ControlFlow, Try};

use super::super::TrustedRandomAccess;
use super::super::{Chain, Cloned, Copied, Cycle, Enumerate, Filter, FilterMap, Fuse};
Expand Down Expand Up @@ -2234,7 +2234,9 @@ pub trait Iterator {
F: FnMut(Self::Item) -> Option<B>,
{
#[inline]
fn check<T, B>(mut f: impl FnMut(T) -> Option<B>) -> impl FnMut((), T) -> ControlFlow<(), B> {
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(()),
Expand Down Expand Up @@ -2354,7 +2356,11 @@ pub trait Iterator {
) -> impl FnMut(usize, T) -> ControlFlow<usize, usize> {
// The addition might panic on overflow
move |i, x| {
if predicate(x) { ControlFlow::Break(i) } else { ControlFlow::Continue(Add::add(i, 1)) }
if predicate(x) {
ControlFlow::Break(i)
} else {
ControlFlow::Continue(Add::add(i, 1))
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions library/core/src/ops/control_flow.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::ops::Try;

/// Used to make try_fold closures more like normal loops
#[unstable(feature="control_flow_enum", reason="new API", issue="75744")]
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ControlFlow<C, B> {
/// Continue in the loop, using the given value for the next iteration
Expand All @@ -10,7 +10,7 @@ pub enum ControlFlow<C, B> {
Break(B),
}

#[unstable(feature="control_flow_enum", reason="new API", issue="75744")]
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
impl<C, B> Try for ControlFlow<C, B> {
type Ok = C;
type Error = B;
Expand All @@ -35,7 +35,7 @@ impl<C, B> ControlFlow<C, B> {
/// Converts the `ControlFlow` into an `Option` which is `Some` if the
/// `ControlFlow` was `Break` and `None` otherwise.
#[inline]
#[unstable(feature="control_flow_enum", reason="new API", issue="75744")]
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
pub fn break_value(self) -> Option<B> {
match self {
ControlFlow::Continue(..) => None,
Expand All @@ -46,7 +46,7 @@ impl<C, B> ControlFlow<C, B> {

impl<R: Try> ControlFlow<R::Ok, R> {
/// Create a `ControlFlow` from any type implementing `Try`.
#[unstable(feature="control_flow_enum", reason="new API", issue="75744")]
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
#[inline]
pub fn from_try(r: R) -> Self {
match Try::into_result(r) {
Expand All @@ -56,7 +56,7 @@ impl<R: Try> ControlFlow<R::Ok, R> {
}

/// Convert a `ControlFlow` into any type implementing `Try`;
#[unstable(feature="control_flow_enum", reason="new API", issue="75744")]
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
#[inline]
pub fn into_try(self) -> R {
match self {
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@

mod arith;
mod bit;
mod control_flow;
mod deref;
mod drop;
mod function;
Expand All @@ -148,7 +149,6 @@ mod index;
mod range;
mod r#try;
mod unsize;
mod control_flow;

#[stable(feature = "rust1", since = "1.0.0")]
pub use self::arith::{Add, Div, Mul, Neg, Rem, Sub};
Expand Down Expand Up @@ -193,5 +193,5 @@ pub use self::unsize::CoerceUnsized;
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
pub use self::unsize::DispatchFromDyn;

#[unstable(feature="control_flow_enum", reason="new API", issue="75744")]
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
pub use self::control_flow::ControlFlow;

0 comments on commit 96eb5e1

Please sign in to comment.