mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2026-03-06 19:39:12 +00:00
Add Residual, residual_into_try_type to minicore
This commit is contained in:
parent
97770dc5d1
commit
7cb575bc90
@ -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;
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user