Skip to content

Commit 52d7065

Browse files
committed
Move into_try_type to a free function
1 parent 7830d74 commit 52d7065

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

core/src/ops/try_trait.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,15 +364,19 @@ pub const trait Residual<O>: Sized {
364364
/// The "return" type of this meta-function.
365365
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
366366
type TryType: [const] Try<Output = O, Residual = Self>;
367+
}
367368

368-
/// Here for convenience in the `?` desugaring.
369-
/// Probably should not be stabilized, as it should never be overridden.
370-
/// (without a `final fn` of some form, cc RFC#3678)
371-
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
372-
#[lang = "into_try_type"]
373-
fn into_try_type(self) -> Self::TryType {
374-
FromResidual::from_residual(self)
375-
}
369+
/// Used in `try {}` blocks so the type produced in the `?` desugaring
370+
/// depends on the residual type `R` and the output type of the block `O`,
371+
/// but importantly not on the contextual type the way it would be if
372+
/// we called `<_ as FromResidual>::from_residual(r)` directly.
373+
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
374+
// needs to be `pub` to avoid `private type` errors
375+
#[expect(unreachable_pub)]
376+
#[inline] // FIXME: force would be nice, but fails -- see #148915
377+
#[lang = "into_try_type"]
378+
pub fn residual_into_try_type<R: Residual<O>, O>(r: R) -> <R as Residual<O>>::TryType {
379+
FromResidual::from_residual(r)
376380
}
377381

378382
#[unstable(feature = "pub_crate_should_not_need_unstable_attr", issue = "none")]

0 commit comments

Comments
 (0)