]> git.lizzy.rs Git - rust.git/commitdiff
Replace `core::iter::AlwaysOk<T>` by `Result<T, !>`
authorkennytm <kennytm@gmail.com>
Mon, 21 May 2018 14:50:25 +0000 (22:50 +0800)
committerkennytm <kennytm@gmail.com>
Tue, 12 Jun 2018 22:54:31 +0000 (06:54 +0800)
src/libcore/iter/iterator.rs
src/libcore/iter/mod.rs
src/libcore/iter/traits.rs

index 1972b0099053ee837620ed85863729504fb21a4b..81150bc0378090b64c0e920b413f784849c1a087 100644 (file)
@@ -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 @@ fn try_for_each<F, R>(&mut self, mut f: F) -> R where
     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.
index f152ee73b6996fa14c5d432c29c0dcdbff446f48..840d45ff1cc15847e52c00040aec606e0a8e0282 100644 (file)
 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> {
index 1551429557f1e5d141c8f32d1951d9a7dbb601c3..3d2ce9e6b104bc9aae32559816e10a81eb9bf9bb 100644 (file)
@@ -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 @@ fn try_rfold<B, F, R>(&mut self, init: B, mut f: F) -> R where
     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.