Move into_try_type to a free function

This commit is contained in:
Scott McMurray 2025-11-12 21:59:11 -08:00
parent cc7f844d6d
commit e5803fceed
4 changed files with 15 additions and 11 deletions

View file

@ -372,7 +372,7 @@ language_item_table! {
TryTraitFromOutput, sym::from_output, from_output_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
TryTraitBranch, sym::branch, branch_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
TryTraitFromYeet, sym::from_yeet, from_yeet_fn, Target::Fn, GenericRequirement::None;
ResidualIntoTryType, sym::into_try_type, into_try_type_fn, Target::Method(MethodKind::Trait { body: true }), GenericRequirement::None;
ResidualIntoTryType, sym::into_try_type, into_try_type_fn, Target::Fn, GenericRequirement::None;
CoercePointeeValidated, sym::coerce_pointee_validated, coerce_pointee_validated_trait, Target::Trait, GenericRequirement::Exact(0);

View file

@ -364,15 +364,19 @@ pub const trait Residual<O>: Sized {
/// The "return" type of this meta-function.
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
type TryType: [const] Try<Output = O, Residual = Self>;
}
/// Here for convenience in the `?` desugaring.
/// Probably should not be stabilized, as it should never be overridden.
/// (without a `final fn` of some form, cc RFC#3678)
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
#[lang = "into_try_type"]
fn into_try_type(self) -> Self::TryType {
FromResidual::from_residual(self)
}
/// Used in `try {}` blocks so the type produced in the `?` desugaring
/// depends on the residual type `R` and the output type of the block `O`,
/// but importantly not on the contextual type the way it would be if
/// we called `<_ as FromResidual>::from_residual(r)` directly.
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
// needs to be `pub` to avoid `private type` errors
#[expect(unreachable_pub)]
#[inline] // FIXME: force would be nice, but fails -- see #148915
#[lang = "into_try_type"]
pub fn residual_into_try_type<R: Residual<O>, O>(r: R) -> <R as Residual<O>>::TryType {
FromResidual::from_residual(r)
}
#[unstable(feature = "pub_crate_should_not_need_unstable_attr", issue = "none")]

View file

@ -34,7 +34,7 @@ fn option_traits(_1: Option<u32>) -> Option<u32> {
}
bb3: {
_0 = <Option<Infallible> as Residual<u32>>::into_try_type(const Option::<Infallible>::None) -> [return: bb4, unwind unreachable];
_0 = ops::try_trait::residual_into_try_type::<Option<Infallible>, u32>(const Option::<Infallible>::None) -> [return: bb4, unwind unreachable];
}
bb4: {

View file

@ -34,7 +34,7 @@ fn option_traits(_1: Option<u32>) -> Option<u32> {
}
bb3: {
_0 = <Option<Infallible> as Residual<u32>>::into_try_type(const Option::<Infallible>::None) -> [return: bb4, unwind continue];
_0 = ops::try_trait::residual_into_try_type::<Option<Infallible>, u32>(const Option::<Infallible>::None) -> [return: bb4, unwind continue];
}
bb4: {