Skip to content

Commit

Permalink
Rollup merge of rust-lang#126347 - slanterns:try_simplify, r=scottmcm
Browse files Browse the repository at this point in the history
Simplify `try_*`'s signature on `Iterator`

Inspired by rust-lang#126249 (comment).

r? `@scottmcm`

(Seems there's no need to explicitly use `<Self as Iterator>::Item`? I only find this occurrence across the whole file.)
  • Loading branch information
fmease committed Jun 13, 2024
2 parents 921645c + fac1733 commit 1fc56c9
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2080,8 +2080,7 @@ pub trait Iterator {
fn try_collect<B>(&mut self) -> ChangeOutputType<Self::Item, B>
where
Self: Sized,
<Self as Iterator>::Item: Try,
<<Self as Iterator>::Item as Try>::Residual: Residual<B>,
Self::Item: Try<Residual: Residual<B>>,
B: FromIterator<<Self::Item as Try>::Output>,
{
try_process(ByRefSized(self), |i| i.collect())
Expand Down Expand Up @@ -2689,12 +2688,13 @@ pub trait Iterator {
#[inline]
#[unstable(feature = "iterator_try_reduce", reason = "new API", issue = "87053")]
#[rustc_do_not_const_check]
fn try_reduce<F, R>(&mut self, f: F) -> ChangeOutputType<R, Option<R::Output>>
fn try_reduce<R>(
&mut self,
f: impl FnMut(Self::Item, Self::Item) -> R,
) -> ChangeOutputType<R, Option<R::Output>>
where
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> R,
R: Try<Output = Self::Item>,
R::Residual: Residual<Option<Self::Item>>,
R: Try<Output = Self::Item, Residual: Residual<Option<Self::Item>>>,
{
let first = match self.next() {
Some(i) => i,
Expand Down Expand Up @@ -2956,12 +2956,13 @@ pub trait Iterator {
#[inline]
#[unstable(feature = "try_find", reason = "new API", issue = "63178")]
#[rustc_do_not_const_check]
fn try_find<F, R>(&mut self, f: F) -> ChangeOutputType<R, Option<Self::Item>>
fn try_find<R>(
&mut self,
f: impl FnMut(&Self::Item) -> R,
) -> ChangeOutputType<R, Option<Self::Item>>
where
Self: Sized,
F: FnMut(&Self::Item) -> R,
R: Try<Output = bool>,
R::Residual: Residual<Option<Self::Item>>,
R: Try<Output = bool, Residual: Residual<Option<Self::Item>>>,
{
#[inline]
fn check<I, V, R>(
Expand Down

0 comments on commit 1fc56c9

Please sign in to comment.