diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index eae0e1c761866..512433bc68b6f 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -87,8 +87,7 @@ where pub fn try_from_fn(cb: F) -> ChangeOutputType where F: FnMut(usize) -> R, - R: Try, - R::Residual: Residual<[R::Output; N]>, + R: Try, { // SAFETY: we know for certain that this iterator will yield exactly `N` // items. @@ -535,11 +534,10 @@ impl [T; N] { /// assert_eq!(c, Some(a)); /// ``` #[unstable(feature = "array_try_map", issue = "79711")] - pub fn try_map(self, f: F) -> ChangeOutputType + pub fn try_map(self, f: F) -> ChangeOutputType where F: FnMut(T) -> R, - R: Try, - R::Residual: Residual<[R::Output; N]>, + R: Try, { // SAFETY: we know for certain that this iterator will yield exactly `N` // items. @@ -809,15 +807,15 @@ impl [T; N] { /// /// It is up to the caller to guarantee that `iter` yields at least `N` items. /// Violating this condition causes undefined behavior. -unsafe fn try_collect_into_array_unchecked(iter: &mut I) -> R::TryType +unsafe fn try_collect_into_array_unchecked( + iter: &mut I, +) -> ChangeOutputType where // Note: `TrustedLen` here is somewhat of an experiment. This is just an // internal function, so feel free to remove if this bound turns out to be a // bad idea. In that case, remember to also remove the lower bound // `debug_assert!` below! - I: Iterator + TrustedLen, - I::Item: Try, - R: Residual<[T; N]>, + I: Iterator> + TrustedLen, { debug_assert!(N <= iter.size_hint().1.unwrap_or(usize::MAX)); debug_assert!(N <= iter.size_hint().0); @@ -852,13 +850,11 @@ where /// If `iter.next()` panicks, all items already yielded by the iterator are /// dropped. #[inline] -fn try_collect_into_array( +fn try_collect_into_array( iter: &mut I, -) -> Result> +) -> Result, IntoIter> where - I: Iterator, - I::Item: Try, - R: Residual<[T; N]>, + I: Iterator>, { if N == 0 { // SAFETY: An empty array is always inhabited and has no validity invariants. diff --git a/library/core/src/iter/adapters/mod.rs b/library/core/src/iter/adapters/mod.rs index 8cc2b7cec4165..b5fb808e0f341 100644 --- a/library/core/src/iter/adapters/mod.rs +++ b/library/core/src/iter/adapters/mod.rs @@ -153,11 +153,10 @@ pub(crate) struct GenericShunt<'a, I, R> { /// Process the given iterator as if it yielded a the item's `Try::Output` /// type instead. Any `Try::Residual`s encountered will stop the inner iterator /// and be propagated back to the overall result. -pub(crate) fn try_process(iter: I, mut f: F) -> ChangeOutputType +pub(crate) fn try_process(iter: I, mut f: F) -> ChangeOutputType where - I: Iterator>, - for<'a> F: FnMut(GenericShunt<'a, I, R>) -> U, - R: Residual, + I: Iterator>, + for<'a> F: FnMut(GenericShunt<'a, I, ::Residual>) -> U, { let mut residual = None; let shunt = GenericShunt { iter, residual: &mut residual }; diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 83c7e8977e9f3..659c83ee98891 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -1910,8 +1910,7 @@ pub trait Iterator { fn try_collect(&mut self) -> ChangeOutputType where Self: Sized, - ::Item: Try, - <::Item as Try>::Residual: Residual, + Self::Item: Try, B: FromIterator<::Output>, { try_process(ByRefSized(self), |i| i.collect()) @@ -2512,12 +2511,11 @@ pub trait Iterator { /// ``` #[inline] #[unstable(feature = "iterator_try_reduce", reason = "new API", issue = "87053")] - fn try_reduce(&mut self, f: F) -> ChangeOutputType> + fn try_reduce(&mut self, f: F) -> ChangeOutputType> where Self: Sized, F: FnMut(Self::Item, Self::Item) -> R, - R: Try, - R::Residual: Residual>, + R: Try, { let first = match self.next() { Some(i) => i, @@ -2769,20 +2767,18 @@ pub trait Iterator { /// ``` #[inline] #[unstable(feature = "try_find", reason = "new API", issue = "63178")] - fn try_find(&mut self, f: F) -> ChangeOutputType> + fn try_find(&mut self, f: F) -> ChangeOutputType> where Self: Sized, F: FnMut(&Self::Item) -> R, - R: Try, - R::Residual: Residual>, + R: Try, { #[inline] - fn check( - mut f: impl FnMut(&I) -> V, - ) -> impl FnMut((), I) -> ControlFlow + fn check( + mut f: impl FnMut(&I) -> R, + ) -> impl FnMut((), I) -> ControlFlow>> where - V: Try, - R: Residual>, + R: Try, { move |(), x| match f(&x).branch() { ControlFlow::Continue(false) => ControlFlow::CONTINUE, diff --git a/library/core/src/ops/control_flow.rs b/library/core/src/ops/control_flow.rs index cd183540cd5e9..215e665545eee 100644 --- a/library/core/src/ops/control_flow.rs +++ b/library/core/src/ops/control_flow.rs @@ -129,8 +129,8 @@ impl const ops::FromResidual for ControlFlow { #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try", issue = "74935")] -impl const ops::Residual for ControlFlow { - type TryType = ControlFlow; +impl const ops::Residual for ControlFlow { + type TryType = ControlFlow; } impl ControlFlow { diff --git a/library/core/src/ops/try_trait.rs b/library/core/src/ops/try_trait.rs index 84a69046807c4..a769527c24bd4 100644 --- a/library/core/src/ops/try_trait.rs +++ b/library/core/src/ops/try_trait.rs @@ -359,14 +359,15 @@ where /// ` as Residual>::TryType = Result`. #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[const_trait] -pub trait Residual { +pub trait Residual { /// The "return" type of this meta-function. #[unstable(feature = "try_trait_v2_residual", issue = "91285")] - type TryType: ~const Try; + type TryType: ~const Try; } +// This type alias is used in the return types of public functions, so rustc wants a stability attr #[unstable(feature = "pub_crate_should_not_need_unstable_attr", issue = "none")] -pub(crate) type ChangeOutputType = <::Residual as Residual>::TryType; +pub(crate) type ChangeOutputType = <::Residual as Residual>::TryType; /// An adapter for implementing non-try methods via the `Try` implementation. /// @@ -413,8 +414,8 @@ impl const FromResidual for NeverShortCircuit { } } -impl const Residual for NeverShortCircuitResidual { - type TryType = NeverShortCircuit; +impl const Residual for NeverShortCircuitResidual { + type TryType = NeverShortCircuit; } /// Implement `FromResidual>` on your type to enable diff --git a/library/core/src/option.rs b/library/core/src/option.rs index a81dbc6924fb7..969556f6bbed7 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -2321,8 +2321,8 @@ impl ops::FromResidual> for Option { #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try", issue = "74935")] -impl const ops::Residual for Option { - type TryType = Option; +impl const ops::Residual for Option { + type TryType = Option; } impl Option> { diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 3f33c5fd6ca36..5cab80384fb04 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -2120,6 +2120,6 @@ impl> ops::FromResidual> for Result { #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try", issue = "74935")] -impl const ops::Residual for Result { - type TryType = Result; +impl const ops::Residual for Result { + type TryType = Result; }