Skip to content

Remove redundant suffixes from Try (TryType, TryTrait)#155229

Open
nxsaken wants to merge 3 commits intorust-lang:mainfrom
nxsaken:Residual-TryType
Open

Remove redundant suffixes from Try (TryType, TryTrait)#155229
nxsaken wants to merge 3 commits intorust-lang:mainfrom
nxsaken:Residual-TryType

Conversation

@nxsaken
Copy link
Copy Markdown
Contributor

@nxsaken nxsaken commented Apr 13, 2026

Feature: try_trait_v2_residual (#91285)

The main part is renaming Residual::TryType into Try (+ residual_into_try_type into residual_into_try) to reflect the symmetry between Try::Residual: Residual and Residual::Try: Try. I went ahead and changed all similar references except for try_trait* (there it makes sense because it distinguishes the trait feature from the block feature and prevents clashing with the keyword).

r? @scottmcm

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 13, 2026

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. labels Apr 13, 2026
@rust-log-analyzer

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust-analyzer should support both forms, at least for some time.

View changes since this review

@nxsaken
Copy link
Copy Markdown
Contributor Author

nxsaken commented Apr 13, 2026

Let me check my intuition.

I need to add the renamed lang item symbol (into_try_type) back under another name, say,

ResidualIntoTry,    sym::into_try,      FunctionId;
ResidualIntoTryOld, sym::into_try_type, FunctionId;

and then, this:

Some(TryBlock::Homogeneous { .. }) => {
    self.lang_path(lang_items.ResidualIntoTry)
}

seems to be the only mention of ResidualIntoTry in rust-analyzer, where self.lang_path(..) returns Option<Path>, and lang_items.ResidualIntoTry is Option<FunctionId>. Should I Option::or one of them to fallback to ResidualIntoTryOld?

If this is correct, I should only do it in rust-analyzer, not in the compiler? And how can someone tell when it's safe to remove?

@lnicola
Copy link
Copy Markdown
Member

lnicola commented Apr 13, 2026

The main concern is that rust-analyzer should work with both old and new versions of the standard library. The compiler only needs to support the matching one.

If this is correct, I should only do it in rust-analyzer, not in the compiler?

Yes.

And how can someone tell when it's safe to remove?

Add a comment like "// TODO: change [stuff, maybe point to your commit] when dropping support for 1.95" (or whatever is the last stable toolchain that uses the old names).

Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust-analyzer changes LGTM.

View changes since this review

r: R,
) -> <R as Residual<O>>::TryType {
#[lang = "into_try"]
pub const fn residual_into_try<R: [const] Residual<O>, O>(r: R) -> <R as Residual<O>>::Try {
Copy link
Copy Markdown
Member

@scottmcm scottmcm Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest just leaving this function alone. It's perma-unstable, only here for implementing the desugaring. To especially if it affects R-A, can leave it as the same lang item.

View changes since the review

/// #[allow(unreachable_code)]
/// // If there is an enclosing `try {...}`:
/// break 'catch_target Residual::into_try_type(residual),
/// break 'catch_target Residual::into_try(residual),
Copy link
Copy Markdown
Member

@scottmcm scottmcm Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to update, might as well make it actually correct, since it's not part of Residual any more.

View changes since the review

this: Self,
f: impl FnOnce(T) -> R,
) -> <R::Residual as Residual<Box<R::Output>>>::TryType
) -> <R::Residual as Residual<Box<R::Output>>>::Try
Copy link
Copy Markdown
Member

@scottmcm scottmcm Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In core we do this using a type alias which is why that didn't need changing; should alloc switch to using that too?

Suggested change
) -> <R::Residual as Residual<Box<R::Output>>>::Try
) -> ChangeOutputType<R, Box<R::Output>>

View changes since the review

Comment on lines -359 to +363
TryTraitFromResidual, sym::from_residual, from_residual_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
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::Fn, GenericRequirement::None;
TryFromResidual, sym::from_residual, from_residual_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
TryFromOutput, sym::from_output, from_output_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
TryBranch, sym::branch, branch_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
TryFromYeet, sym::from_yeet, from_yeet_fn, Target::Fn, GenericRequirement::None;
ResidualIntoTry, sym::into_try, into_try_fn, Target::Fn, GenericRequirement::None;
Copy link
Copy Markdown
Member

@scottmcm scottmcm Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix: this file uses vertical alignment for the columns, so please fix that.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the items have been misaligned all along. Do you want me to realign everything?

@scottmcm
Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 18, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 18, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants