From 7cb575bc901afecd2c015a0e94f3cb89d2d4477f Mon Sep 17 00:00:00 2001 From: Geoffry Song Date: Mon, 2 Feb 2026 14:28:21 -0800 Subject: [PATCH] Add Residual, residual_into_try_type to minicore --- crates/hir-def/src/lang_item.rs | 1 + crates/test-utils/src/minicore.rs | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) 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: Sized { + type TryType: [const] Try; + } #[lang = "Try"] pub trait Try: FromResidual { type Output; @@ -962,6 +965,12 @@ pub mod ops { #[lang = "branch"] fn branch(self) -> ControlFlow; } + #[lang = "into_try_type"] + pub const fn residual_into_try_type, O>( + r: R, + ) -> >::TryType { + FromResidual::from_residual(r) + } impl Try for ControlFlow { type Output = C; @@ -985,6 +994,10 @@ pub mod ops { } } } + + impl Residual for ControlFlow { + type TryType = ControlFlow; + } // region:option impl Try for Option { type Output = T; @@ -1008,6 +1021,10 @@ pub mod ops { } } } + + impl const Residual for Option { + type TryType = Option; + } // endregion:option // region:result // region:from @@ -1037,10 +1054,14 @@ pub mod ops { } } } + + impl const Residual for Result { + type TryType = Result; + } // endregion:from // endregion:result } - pub use self::try_::{ControlFlow, FromResidual, Try}; + pub use self::try_::{ControlFlow, FromResidual, Residual, Try}; // endregion:try // region:add