1+ use crate :: convert:: Infallible ;
12use crate :: ops:: ControlFlow ;
23
34/// The `?` operator and `try {}` blocks.
@@ -384,15 +385,8 @@ pub fn residual_into_try_type<R: Residual<O>, O>(r: R) -> <R as Residual<O>>::Tr
384385pub( crate ) type ChangeOutputType <T : Try <Residual : Residual <V >>, V > =
385386 <T :: Residual as Residual < V > >:: TryType ;
386387
387- /// An adapter for implementing non-try methods via the `Try` implementation.
388- ///
389- /// Conceptually the same as `Result<T, !>`, but requiring less work in trait
390- /// solving and inhabited-ness checking and such, by being an obvious newtype
391- /// and not having `From` bounds lying around.
392- ///
393- /// Not currently planned to be exposed publicly, so just `pub(crate)`.
394- #[ repr( transparent) ]
395- pub( crate ) struct NeverShortCircuit <T >( pub T ) ;
388+ /// A helper alias for implementing non-try methods via the `Try` implementation.
389+ pub ( crate ) type NeverShortCircuit <T > = ControlFlow <Infallible , T >;
396390
397391impl <T > NeverShortCircuit <T > {
398392 /// Wraps a unary function to produce one that wraps the output into a `NeverShortCircuit`.
@@ -403,43 +397,21 @@ impl<T> NeverShortCircuit<T> {
403397 pub ( crate ) fn wrap_mut_1 < A > (
404398 mut f : impl FnMut ( A ) -> T ,
405399 ) -> impl FnMut ( A ) -> NeverShortCircuit < T > {
406- move |a| NeverShortCircuit ( f ( a) )
400+ move |a| NeverShortCircuit :: Continue ( f ( a) )
407401 }
408402
409403 #[ inline]
410404 pub ( crate ) fn wrap_mut_2 < A , B > ( mut f : impl FnMut ( A , B ) -> T ) -> impl FnMut ( A , B ) -> Self {
411- move |a, b| NeverShortCircuit ( f ( a, b) )
412- }
413- }
414-
415- pub ( crate ) enum NeverShortCircuitResidual { }
416-
417- impl < T > Try for NeverShortCircuit < T > {
418- type Output = T ;
419- type Residual = NeverShortCircuitResidual ;
420-
421- #[ inline]
422- fn branch ( self ) -> ControlFlow < NeverShortCircuitResidual , T > {
423- ControlFlow :: Continue ( self . 0 )
405+ move |a, b| NeverShortCircuit :: Continue ( f ( a, b) )
424406 }
425407
426408 #[ inline]
427- fn from_output ( x : T ) -> Self {
428- NeverShortCircuit ( x)
409+ pub ( crate ) fn into_continue ( self ) -> T {
410+ let NeverShortCircuit :: Continue ( v) = self ;
411+ v
429412 }
430413}
431414
432- impl < T > FromResidual for NeverShortCircuit < T > {
433- #[ inline]
434- fn from_residual ( never : NeverShortCircuitResidual ) -> Self {
435- match never { }
436- }
437- }
438-
439- impl < T > Residual < T > for NeverShortCircuitResidual {
440- type TryType = NeverShortCircuit < T > ;
441- }
442-
443415/// Implement `FromResidual<Yeet<T>>` on your type to enable
444416/// `do yeet expr` syntax in functions returning your type.
445417#[ unstable( feature = "try_trait_v2_yeet" , issue = "96374" ) ]
0 commit comments