diff options
| author | bors <bors@rust-lang.org> | 2020-06-20 02:45:08 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-06-20 02:45:08 +0000 |
| commit | 033013cab3a861224fd55f494c8be1cb0349eb49 (patch) | |
| tree | 1252179bcb152e2712bda63c7a51bedbf772c783 /src/libcore | |
| parent | 34c5cd9a64d8537236626c4ccbed39a924cd38e2 (diff) | |
| parent | 3e40cca65ab5b0f862a5c538a3aec5c55683688b (diff) | |
| download | rust-033013cab3a861224fd55f494c8be1cb0349eb49.tar.gz rust-033013cab3a861224fd55f494c8be1cb0349eb49.zip | |
Auto merge of #73528 - Manishearth:rollup-7djz8nd, r=Manishearth
Rollup of 16 pull requests Successful merges: - #71420 (Specialization is unsound) - #71899 (Refactor `try_find` a little) - #72689 (add str to common types) - #72791 (update coerce docs and unify relevant tests) - #72934 (forbid mutable references in all constant contexts except for const-fns) - #73027 (Make `need_type_info_err` more conservative) - #73347 (Diagnose use of incompatible sanitizers) - #73359 (shim.rs: avoid creating `Call` terminators calling `Self`) - #73399 (Clean up E0668 explanation) - #73436 (Clean up E0670 explanation) - #73440 (Add src/librustdoc as an alias for src/tools/rustdoc) - #73442 (pretty/mir: const value enums with no variants) - #73452 (Unify region variables when projecting associated types) - #73458 (Use alloc::Layout in DroplessArena API) - #73484 (Update the doc for std::prelude to the correct behavior) - #73506 (Bump Rustfmt and RLS) Failed merges: r? @ghost
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/iter/traits/iterator.rs | 29 | ||||
| -rw-r--r-- | src/libcore/tests/lib.rs | 2 |
2 files changed, 19 insertions, 12 deletions
diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs index fbfcdc3c1a9..530cf881f29 100644 --- a/src/libcore/iter/traits/iterator.rs +++ b/src/libcore/iter/traits/iterator.rs @@ -2265,7 +2265,7 @@ pub trait Iterator { } /// Applies function to the elements of iterator and returns - /// the first non-none result or the first error. + /// the first true result or the first error. /// /// # Examples /// @@ -2286,19 +2286,26 @@ pub trait Iterator { /// ``` #[inline] #[unstable(feature = "try_find", reason = "new API", issue = "63178")] - fn try_find<F, E, R>(&mut self, mut f: F) -> Result<Option<Self::Item>, E> + fn try_find<F, R>(&mut self, f: F) -> Result<Option<Self::Item>, R::Error> where Self: Sized, F: FnMut(&Self::Item) -> R, - R: Try<Ok = bool, Error = E>, - { - self.try_fold((), move |(), x| match f(&x).into_result() { - Ok(false) => LoopState::Continue(()), - Ok(true) => LoopState::Break(Ok(x)), - Err(x) => LoopState::Break(Err(x)), - }) - .break_value() - .transpose() + R: Try<Ok = bool>, + { + #[inline] + fn check<F, T, R>(mut f: F) -> impl FnMut((), T) -> LoopState<(), Result<T, R::Error>> + where + F: FnMut(&T) -> R, + R: Try<Ok = bool>, + { + move |(), x| match f(&x).into_result() { + Ok(false) => LoopState::Continue(()), + Ok(true) => LoopState::Break(Ok(x)), + Err(x) => LoopState::Break(Err(x)), + } + } + + self.try_fold((), check(f)).break_value().transpose() } /// Searches for an element in an iterator, returning its index. diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs index 37ebf411280..4e55452a4c3 100644 --- a/src/libcore/tests/lib.rs +++ b/src/libcore/tests/lib.rs @@ -19,7 +19,7 @@ #![feature(raw)] #![feature(sort_internals)] #![feature(slice_partition_at_index)] -#![feature(specialization)] +#![feature(min_specialization)] #![feature(step_trait)] #![feature(step_trait_ext)] #![feature(str_internals)] |
