diff options
| author | kennytm <kennytm@gmail.com> | 2018-05-21 22:50:25 +0800 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2018-06-13 06:54:31 +0800 |
| commit | 8ae188959ba5237f3c40f9d9c15954cce6288aee (patch) | |
| tree | 2fe33506777045be9a2f4483cd25be76b744a550 | |
| parent | b68432d560c7c6f1e738b27e49d271a2a778f898 (diff) | |
| download | rust-8ae188959ba5237f3c40f9d9c15954cce6288aee.tar.gz rust-8ae188959ba5237f3c40f9d9c15954cce6288aee.zip | |
Replace `core::iter::AlwaysOk<T>` by `Result<T, !>`
| -rw-r--r-- | src/libcore/iter/iterator.rs | 4 | ||||
| -rw-r--r-- | src/libcore/iter/mod.rs | 15 | ||||
| -rw-r--r-- | src/libcore/iter/traits.rs | 4 |
3 files changed, 4 insertions, 19 deletions
diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs index 1972b009905..81150bc0378 100644 --- a/src/libcore/iter/iterator.rs +++ b/src/libcore/iter/iterator.rs @@ -11,7 +11,7 @@ use cmp::Ordering; use ops::Try; -use super::{AlwaysOk, LoopState}; +use super::LoopState; use super::{Chain, Cycle, Cloned, Enumerate, Filter, FilterMap, Fuse}; use super::{Flatten, FlatMap, flatten_compat}; use super::{Inspect, Map, Peekable, Scan, Skip, SkipWhile, StepBy, Take, TakeWhile, Rev}; @@ -1614,7 +1614,7 @@ pub trait Iterator { fn fold<B, F>(mut self, init: B, mut f: F) -> B where Self: Sized, F: FnMut(B, Self::Item) -> B, { - self.try_fold(init, move |acc, x| AlwaysOk(f(acc, x))).0 + self.try_fold(init, move |acc, x| Ok::<B, !>(f(acc, x))).unwrap() } /// Tests if every element of the iterator matches a predicate. diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index f152ee73b69..840d45ff1cc 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -354,21 +354,6 @@ mod range; mod sources; mod traits; -/// Transparent newtype used to implement foo methods in terms of try_foo. -/// Important until #43278 is fixed; might be better as `Result<T, !>` later. -struct AlwaysOk<T>(pub T); - -impl<T> Try for AlwaysOk<T> { - type Ok = T; - type Error = !; - #[inline] - fn into_result(self) -> Result<Self::Ok, Self::Error> { Ok(self.0) } - #[inline] - fn from_error(v: Self::Error) -> Self { v } - #[inline] - fn from_ok(v: Self::Ok) -> Self { AlwaysOk(v) } -} - /// Used to make try_fold closures more like normal loops #[derive(PartialEq)] enum LoopState<C, B> { diff --git a/src/libcore/iter/traits.rs b/src/libcore/iter/traits.rs index 1551429557f..3d2ce9e6b10 100644 --- a/src/libcore/iter/traits.rs +++ b/src/libcore/iter/traits.rs @@ -10,7 +10,7 @@ use ops::{Mul, Add, Try}; use num::Wrapping; -use super::{AlwaysOk, LoopState}; +use super::LoopState; /// Conversion from an `Iterator`. /// @@ -524,7 +524,7 @@ pub trait DoubleEndedIterator: Iterator { fn rfold<B, F>(mut self, accum: B, mut f: F) -> B where Self: Sized, F: FnMut(B, Self::Item) -> B, { - self.try_rfold(accum, move |acc, x| AlwaysOk(f(acc, x))).0 + self.try_rfold(accum, move |acc, x| Ok::<B, !>(f(acc, x))).unwrap() } /// Searches for an element of an iterator from the back that satisfies a predicate. |
