Unnamed repository; edit this file 'description' to name the repository.
Add Residual, residual_into_try_type to minicore
| -rw-r--r-- | crates/hir-def/src/lang_item.rs | 1 | ||||
| -rw-r--r-- | crates/test-utils/src/minicore.rs | 23 |
2 files changed, 23 insertions, 1 deletions
diff --git a/crates/hir-def/src/lang_item.rs b/crates/hir-def/src/lang_item.rs index 51dd55301f..fef92c89b1 100644 --- a/crates/hir-def/src/lang_item.rs +++ b/crates/hir-def/src/lang_item.rs @@ -456,6 +456,7 @@ language_item_table! { LangItems => TryTraitFromOutput, sym::from_output, FunctionId; TryTraitBranch, sym::branch, FunctionId; TryTraitFromYeet, sym::from_yeet, FunctionId; + ResidualIntoTryType, sym::into_try_type, FunctionId; PointerLike, sym::pointer_like, TraitId; diff --git a/crates/test-utils/src/minicore.rs b/crates/test-utils/src/minicore.rs index 48c3e89525..5b9165d537 100644 --- a/crates/test-utils/src/minicore.rs +++ b/crates/test-utils/src/minicore.rs @@ -953,6 +953,9 @@ pub mod ops { #[lang = "from_residual"] fn from_residual(residual: R) -> Self; } + pub const trait Residual<O>: Sized { + type TryType: [const] Try<Output = O, Residual = Self>; + } #[lang = "Try"] pub trait Try: FromResidual<Self::Residual> { type Output; @@ -962,6 +965,12 @@ pub mod ops { #[lang = "branch"] fn branch(self) -> ControlFlow<Self::Residual, Self::Output>; } + #[lang = "into_try_type"] + pub const fn residual_into_try_type<R: [const] Residual<O>, O>( + r: R, + ) -> <R as Residual<O>>::TryType { + FromResidual::from_residual(r) + } impl<B, C> Try for ControlFlow<B, C> { type Output = C; @@ -985,6 +994,10 @@ pub mod ops { } } } + + impl<B, C> Residual<C> for ControlFlow<B, Infallible> { + type TryType = ControlFlow<B, C>; + } // region:option impl<T> Try for Option<T> { type Output = T; @@ -1008,6 +1021,10 @@ pub mod ops { } } } + + impl<T> const Residual<T> for Option<Infallible> { + type TryType = Option<T>; + } // endregion:option // region:result // region:from @@ -1037,10 +1054,14 @@ pub mod ops { } } } + + impl<T, E> const Residual<T> for Result<Infallible, E> { + type TryType = Result<T, E>; + } // endregion:from // endregion:result } - pub use self::try_::{ControlFlow, FromResidual, Try}; + pub use self::try_::{ControlFlow, FromResidual, Residual, Try}; // endregion:try // region:add |