From 98f7e1fbb52bb3e350b6751e8c965d7d8d4260be Mon Sep 17 00:00:00 2001 From: nxsaken Date: Mon, 13 Apr 2026 10:46:45 +0400 Subject: [PATCH 1/3] TryType, TryTrait -> Try --- compiler/rustc_ast_lowering/src/expr.rs | 14 +++++++------- compiler/rustc_hir/src/lang_items.rs | 10 +++++----- compiler/rustc_hir_typeck/src/expr.rs | 4 ++-- compiler/rustc_middle/src/mir/interpret/error.rs | 3 +++ compiler/rustc_span/src/symbol.rs | 2 +- .../src/error_reporting/traits/call_kind.rs | 6 +++--- library/alloc/src/boxed.rs | 2 +- library/alloc/src/rc.rs | 4 ++-- library/alloc/src/sync.rs | 4 ++-- library/core/src/iter/traits/iterator.rs | 2 +- library/core/src/ops/control_flow.rs | 2 +- library/core/src/ops/try_trait.rs | 14 +++++++------- library/core/src/option.rs | 4 ++-- library/core/src/result.rs | 2 +- .../clippy/clippy_lints/src/matches/try_err.rs | 2 +- .../clippy_lints/src/methods/clone_on_copy.rs | 2 +- .../clippy/clippy_lints/src/methods/str_splitn.rs | 2 +- .../clippy_lints/src/needless_question_mark.rs | 2 +- src/tools/clippy/clippy_lints/src/question_mark.rs | 2 +- .../clippy_lints/src/returns/needless_return.rs | 2 +- .../clippy/clippy_lints/src/unused_io_amount.rs | 2 +- .../crates/hir-def/src/expr_store/lower.rs | 10 +++++----- .../rust-analyzer/crates/hir-def/src/lang_item.rs | 10 +++++----- .../crates/hir/src/source_analyzer.rs | 2 +- .../crates/intern/src/symbol/symbols.rs | 2 +- .../crates/test-utils/src/minicore.rs | 14 +++++++------- ....option_traits.PreCodegen.after.panic-abort.mir | 2 +- ...option_traits.PreCodegen.after.panic-unwind.mir | 2 +- tests/ui/traits/const-traits/auxiliary/minicore.rs | 2 +- 29 files changed, 67 insertions(+), 64 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index b6bc122051cbc..06a10ccfc17f0 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -609,7 +609,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> { // `::std::ops::Try::from_output($tail_expr)` block.expr = Some(this.wrap_in_try_constructor( - hir::LangItem::TryTraitFromOutput, + hir::LangItem::TryFromOutput, try_span, tail_expr, ok_wrapped_span, @@ -1972,7 +1972,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> { /// ControlFlow::Break(residual) => /// #[allow(unreachable_code)] /// // If there is an enclosing `try {...}`: - /// break 'catch_target Residual::into_try_type(residual), + /// break 'catch_target Residual::into_try(residual), /// // Otherwise: /// return Try::from_residual(residual), /// } @@ -1997,7 +1997,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> { self.expr_call_lang_item_fn( unstable_span, - hir::LangItem::TryTraitBranch, + hir::LangItem::TryBranch, arena_vec![self; sub_expr], ) }; @@ -2024,13 +2024,13 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> { let (constructor_item, target_id) = match self.try_block_scope { TryBlockScope::Function => { - (hir::LangItem::TryTraitFromResidual, Err(hir::LoopIdError::OutsideLoopScope)) + (hir::LangItem::TryFromResidual, Err(hir::LoopIdError::OutsideLoopScope)) } TryBlockScope::Homogeneous(block_id) => { - (hir::LangItem::ResidualIntoTryType, Ok(block_id)) + (hir::LangItem::ResidualIntoTry, Ok(block_id)) } TryBlockScope::Heterogeneous(block_id) => { - (hir::LangItem::TryTraitFromResidual, Ok(block_id)) + (hir::LangItem::TryFromResidual, Ok(block_id)) } }; let from_residual_expr = self.wrap_in_try_constructor( @@ -2088,7 +2088,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> { ); let from_yeet_expr = self.wrap_in_try_constructor( - hir::LangItem::TryTraitFromYeet, + hir::LangItem::TryFromYeet, unstable_span, yeeted_expr, yeeted_span, diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index c144f0b7dbc5b..2f66031008c86 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -356,11 +356,11 @@ language_item_table! { SliceLen, sym::slice_len_fn, slice_len_fn, Target::Method(MethodKind::Inherent), GenericRequirement::None; // Language items from AST lowering - 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; CoercePointeeValidated, sym::coerce_pointee_validated, coerce_pointee_validated_trait, Target::Trait, GenericRequirement::Exact(0); diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 55e6d233f4755..7a48f9930f73e 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -576,13 +576,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { Some(ObligationCauseCode::ForLoopIterator) } - LangItem::TryTraitFromOutput + LangItem::TryFromOutput if expr.span.is_desugaring(DesugaringKind::TryBlock) => { // FIXME it's a try block, not a question mark Some(ObligationCauseCode::QuestionMark) } - LangItem::TryTraitBranch | LangItem::TryTraitFromResidual + LangItem::TryBranch | LangItem::TryFromResidual if expr.span.is_desugaring(DesugaringKind::QuestionMark) => { Some(ObligationCauseCode::QuestionMark) diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index 6c7505a7cbbb0..8c1f227ec7647 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -961,7 +961,10 @@ impl<'tcx, T> ops::Try for InterpResult<'tcx, T> { } impl<'tcx, T> ops::Residual for InterpResult<'tcx, convert::Infallible> { + #[cfg(bootstrap)] type TryType = InterpResult<'tcx, T>; + #[cfg(not(bootstrap))] + type Try = InterpResult<'tcx, T>; } impl<'tcx, T> ops::FromResidual for InterpResult<'tcx, T> { diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index e7126cf70b574..00dffe08856f5 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1105,7 +1105,7 @@ symbols! { into_async_iter_into_iter, into_future, into_iter, - into_try_type, + into_try, intra_doc_pointers, intrinsics, irrefutable_let_patterns, diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/call_kind.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/call_kind.rs index 2c18ffc105503..4072b22f0f4d7 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/call_kind.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/call_kind.rs @@ -134,14 +134,14 @@ pub fn call_kind<'tcx>( { Some((CallDesugaringKind::ForLoopNext, method_args.type_at(0))) } else if fn_call_span.desugaring_kind() == Some(DesugaringKind::QuestionMark) { - if tcx.is_lang_item(method_did, LangItem::TryTraitBranch) { + if tcx.is_lang_item(method_did, LangItem::TryBranch) { Some((CallDesugaringKind::QuestionBranch, method_args.type_at(0))) - } else if tcx.is_lang_item(method_did, LangItem::TryTraitFromResidual) { + } else if tcx.is_lang_item(method_did, LangItem::TryFromResidual) { Some((CallDesugaringKind::QuestionFromResidual, method_args.type_at(0))) } else { None } - } else if tcx.is_lang_item(method_did, LangItem::TryTraitFromOutput) + } else if tcx.is_lang_item(method_did, LangItem::TryFromOutput) && fn_call_span.desugaring_kind() == Some(DesugaringKind::TryBlock) { Some((CallDesugaringKind::TryBlockFromOutput, method_args.type_at(0))) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 2c95f199e3c4e..6e1287aefd83b 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -476,7 +476,7 @@ impl Box { pub fn try_map( this: Self, f: impl FnOnce(T) -> R, - ) -> >>::TryType + ) -> >>::Try where R: Try, R::Residual: Residual>, diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 73fd7e4b6023c..774746e3842c4 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -713,7 +713,7 @@ impl Rc { pub fn try_map( this: Self, f: impl FnOnce(&T) -> R, - ) -> >>::TryType + ) -> >>::Try where R: Try, R::Residual: Residual>, @@ -4265,7 +4265,7 @@ impl UniqueRc { pub fn try_map( this: Self, f: impl FnOnce(T) -> R, - ) -> >>::TryType + ) -> >>::Try where R: Try, R::Residual: Residual>, diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 645a55843f359..640938e33dcdc 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -723,7 +723,7 @@ impl Arc { pub fn try_map( this: Self, f: impl FnOnce(&T) -> R, - ) -> >>::TryType + ) -> >>::Try where R: Try, R::Residual: Residual>, @@ -4691,7 +4691,7 @@ impl UniqueArc { pub fn try_map( this: Self, f: impl FnOnce(T) -> R, - ) -> >>::TryType + ) -> >>::Try where R: Try, R::Residual: Residual>, diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index c6a06c133a156..3309f49ad5d9d 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -3060,7 +3060,7 @@ pub const trait Iterator { #[inline] fn check( mut f: impl FnMut(&I) -> V, - ) -> impl FnMut((), I) -> ControlFlow + ) -> impl FnMut((), I) -> ControlFlow where V: Try, R: Residual>, diff --git a/library/core/src/ops/control_flow.rs b/library/core/src/ops/control_flow.rs index f532e8f116f05..4688d0a8fe013 100644 --- a/library/core/src/ops/control_flow.rs +++ b/library/core/src/ops/control_flow.rs @@ -136,7 +136,7 @@ impl const ops::FromResidual> for Cont #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try_residual", issue = "91285")] impl const ops::Residual for ControlFlow { - type TryType = ControlFlow; + type Try = ControlFlow; } impl ControlFlow { diff --git a/library/core/src/ops/try_trait.rs b/library/core/src/ops/try_trait.rs index 34000f6d6b218..5e5bc18254b07 100644 --- a/library/core/src/ops/try_trait.rs +++ b/library/core/src/ops/try_trait.rs @@ -358,14 +358,14 @@ where /// For example, /// `Result: Try>`, /// and in the other direction, -/// ` as Residual>::TryType = Result`. +/// ` as Residual>::Try = Result`. #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try_residual", issue = "91285")] pub const trait Residual: Sized { /// The "return" type of this meta-function. #[unstable(feature = "try_trait_v2_residual", issue = "91285")] // FIXME: ought to be implied - type TryType: [const] Try; + type Try: [const] Try; } /// Used in `try {}` blocks so the type produced in the `?` desugaring @@ -377,17 +377,17 @@ pub const trait Residual: Sized { // 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 const fn residual_into_try_type, O>( +#[lang = "into_try"] +pub const fn residual_into_try, O>( r: R, -) -> >::TryType { +) -> >::Try { FromResidual::from_residual(r) } #[unstable(feature = "pub_crate_should_not_need_unstable_attr", issue = "none")] #[allow(type_alias_bounds)] pub(crate) type ChangeOutputType>, V> = - >::TryType; + >::Try; /// An adapter for implementing non-try methods via the `Try` implementation. /// @@ -463,7 +463,7 @@ impl const FromResidual for NeverShortCircuit { } #[rustc_const_unstable(feature = "const_never_short_circuit", issue = "none")] impl const Residual for NeverShortCircuitResidual { - type TryType = NeverShortCircuit; + type Try = NeverShortCircuit; } /// Implement `FromResidual>` on your type to enable diff --git a/library/core/src/option.rs b/library/core/src/option.rs index d4dd33b948193..3145291d84790 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1860,7 +1860,7 @@ impl Option { pub fn get_or_try_insert_with<'a, R, F>( &'a mut self, f: F, - ) -> >::TryType + ) -> >::Try where F: FnOnce() -> R, R: Try>, @@ -2808,7 +2808,7 @@ impl const ops::FromResidual> for Option { #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try", issue = "74935")] impl const ops::Residual for Option { - type TryType = Option; + type Try = Option; } impl Option> { diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 5f438d72ac13c..b9a5c48f8c522 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -2203,5 +2203,5 @@ impl> const ops::FromResidual> for Result< #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try", issue = "74935")] impl const ops::Residual for Result { - type TryType = Result; + type Try = Result; } diff --git a/src/tools/clippy/clippy_lints/src/matches/try_err.rs b/src/tools/clippy/clippy_lints/src/matches/try_err.rs index 401b8468135bc..3e739a452c50d 100644 --- a/src/tools/clippy/clippy_lints/src/matches/try_err.rs +++ b/src/tools/clippy/clippy_lints/src/matches/try_err.rs @@ -24,7 +24,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, scrutine // }; if let ExprKind::Call(match_fun, [try_arg]) = scrutinee.kind && let ExprKind::Path(match_fun_path) = match_fun.kind - && cx.tcx.qpath_is_lang_item(match_fun_path, LangItem::TryTraitBranch) + && cx.tcx.qpath_is_lang_item(match_fun_path, LangItem::TryBranch) && let ExprKind::Call(err_fun, [err_arg]) = try_arg.kind && err_fun.res(cx).ctor_parent(cx).is_lang_item(cx, ResultErr) && let Some(return_ty) = find_return_type(cx, &expr.kind) diff --git a/src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs b/src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs index 18087bd96debf..b9dfcf1454770 100644 --- a/src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs +++ b/src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs @@ -48,7 +48,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>) ExprKind::Call(hir_callee, [_]) => matches!( hir_callee.kind, ExprKind::Path(qpath) - if cx.tcx.qpath_is_lang_item(qpath, rustc_hir::LangItem::TryTraitBranch) + if cx.tcx.qpath_is_lang_item(qpath, rustc_hir::LangItem::TryBranch) ), ExprKind::MethodCall(_, self_arg, ..) if expr.hir_id == self_arg.hir_id => true, ExprKind::Match(_, _, MatchSource::TryDesugar(_) | MatchSource::AwaitDesugar) diff --git a/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs b/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs index fff203296bce9..96d529a0eb0c5 100644 --- a/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs +++ b/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs @@ -337,7 +337,7 @@ fn parse_iter_usage<'tcx>( .. }, [_], - ) if cx.tcx.qpath_is_lang_item(qpath, LangItem::TryTraitBranch) => { + ) if cx.tcx.qpath_is_lang_item(qpath, LangItem::TryBranch) => { let parent_span = e.span.parent_callsite().unwrap(); if parent_span.ctxt() == ctxt { (Some(UnwrapKind::QuestionMark), parent_span) diff --git a/src/tools/clippy/clippy_lints/src/needless_question_mark.rs b/src/tools/clippy/clippy_lints/src/needless_question_mark.rs index 29c45168b61e5..1c2a3f65041ea 100644 --- a/src/tools/clippy/clippy_lints/src/needless_question_mark.rs +++ b/src/tools/clippy/clippy_lints/src/needless_question_mark.rs @@ -106,7 +106,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { && let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar(_)) = &arg.kind && let ExprKind::Call(called, [inner_expr]) = &inner_expr_with_q.kind && let ExprKind::Path(qpath) = called.kind - && cx.tcx.qpath_is_lang_item(qpath, LangItem::TryTraitBranch) + && cx.tcx.qpath_is_lang_item(qpath, LangItem::TryBranch) && expr.span.eq_ctxt(inner_expr.span) && let expr_ty = cx.typeck_results().expr_ty(expr) && let inner_ty = cx.typeck_results().expr_ty(inner_expr) diff --git a/src/tools/clippy/clippy_lints/src/question_mark.rs b/src/tools/clippy/clippy_lints/src/question_mark.rs index dfd7834a149b1..5a6442d980c47 100644 --- a/src/tools/clippy/clippy_lints/src/question_mark.rs +++ b/src/tools/clippy/clippy_lints/src/question_mark.rs @@ -539,7 +539,7 @@ fn is_try_block(cx: &LateContext<'_>, bl: &Block<'_>) -> bool { if let Some(expr) = bl.expr && let ExprKind::Call(callee, [_]) = expr.kind && let ExprKind::Path(qpath) = callee.kind - && cx.tcx.qpath_is_lang_item(qpath, LangItem::TryTraitFromOutput) + && cx.tcx.qpath_is_lang_item(qpath, LangItem::TryFromOutput) { true } else { diff --git a/src/tools/clippy/clippy_lints/src/returns/needless_return.rs b/src/tools/clippy/clippy_lints/src/returns/needless_return.rs index 04e4f379e37c1..fc483a227e449 100644 --- a/src/tools/clippy/clippy_lints/src/returns/needless_return.rs +++ b/src/tools/clippy/clippy_lints/src/returns/needless_return.rs @@ -135,7 +135,7 @@ fn check_final_expr<'tcx>( // if desugar of `do yeet`, don't lint if let ExprKind::Call(path_expr, [_]) = inner_expr.kind && let ExprKind::Path(qpath) = path_expr.kind - && cx.tcx.qpath_is_lang_item(qpath, LangItem::TryTraitFromYeet) + && cx.tcx.qpath_is_lang_item(qpath, LangItem::TryFromYeet) { return; } diff --git a/src/tools/clippy/clippy_lints/src/unused_io_amount.rs b/src/tools/clippy/clippy_lints/src/unused_io_amount.rs index ffce03cb5dbea..f791643460c04 100644 --- a/src/tools/clippy/clippy_lints/src/unused_io_amount.rs +++ b/src/tools/clippy/clippy_lints/src/unused_io_amount.rs @@ -259,7 +259,7 @@ fn unpack_call_chain<'a>(mut expr: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> { fn unpack_try<'a>(cx: &LateContext<'_>, mut expr: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> { while let ExprKind::Call(func, [arg_0]) = expr.kind && let ExprKind::Path(qpath) = func.kind - && cx.tcx.qpath_is_lang_item(qpath, hir::LangItem::TryTraitBranch) + && cx.tcx.qpath_is_lang_item(qpath, hir::LangItem::TryBranch) { expr = arg_0; } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs b/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs index 7fe91a3d02dba..5b9f6b1fbae56 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs @@ -1750,7 +1750,7 @@ impl<'db> ExprCollector<'db> { /// `try { ; }` into `': { ; ::std::ops::Try::from_output(()) }` /// and save the `` to use it as a break target for desugaring of the `?` operator. fn desugar_try_block(&mut self, e: BlockExpr, result_type: Option) -> ExprId { - let try_from_output = self.lang_path(self.lang_items().TryTraitFromOutput); + let try_from_output = self.lang_path(self.lang_items().TryFromOutput); let label = self.generate_new_name(); let label = self.alloc_label_desugared(Label { name: label }, AstPtr::new(&e).wrap_right()); let try_block_info = match result_type { @@ -1960,7 +1960,7 @@ impl<'db> ExprCollector<'db> { /// ControlFlow::Continue(val) => val, /// ControlFlow::Break(residual) => /// // If there is an enclosing `try {...}`: - /// break 'catch_target Residual::into_try_type(residual), + /// break 'catch_target Residual::into_try(residual), /// // If there is an enclosing `try bikeshed Ty {...}`: /// break 'catch_target Try::from_residual(residual), /// // Otherwise: @@ -1969,7 +1969,7 @@ impl<'db> ExprCollector<'db> { /// ``` fn collect_try_operator(&mut self, syntax_ptr: AstPtr, e: ast::TryExpr) -> ExprId { let lang_items = self.lang_items(); - let try_branch = self.lang_path(lang_items.TryTraitBranch); + let try_branch = self.lang_path(lang_items.TryBranch); let cf_continue = self.lang_path(lang_items.ControlFlowContinue); let cf_break = self.lang_path(lang_items.ControlFlowBreak); let operand = self.collect_expr_opt(e.expr()); @@ -2010,10 +2010,10 @@ impl<'db> ExprCollector<'db> { let it = self.alloc_expr(Expr::Path(Path::from(break_name)), syntax_ptr); let convert_fn = match self.current_try_block { Some(TryBlock::Homogeneous { .. }) => { - self.lang_path(lang_items.ResidualIntoTryType) + self.lang_path(lang_items.ResidualIntoTry) } Some(TryBlock::Heterogeneous { .. }) | None => { - self.lang_path(lang_items.TryTraitFromResidual) + self.lang_path(lang_items.TryFromResidual) } }; let callee = diff --git a/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs b/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs index fef92c89b145a..7960b66c91121 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs @@ -452,11 +452,11 @@ language_item_table! { LangItems => SliceLen, sym::slice_len_fn, FunctionId; // Language items from AST lowering - TryTraitFromResidual, sym::from_residual, FunctionId; - TryTraitFromOutput, sym::from_output, FunctionId; - TryTraitBranch, sym::branch, FunctionId; - TryTraitFromYeet, sym::from_yeet, FunctionId; - ResidualIntoTryType, sym::into_try_type, FunctionId; + TryFromResidual, sym::from_residual, FunctionId; + TryFromOutput, sym::from_output, FunctionId; + TryBranch, sym::branch, FunctionId; + TryFromYeet, sym::from_yeet, FunctionId; + ResidualIntoTry, sym::into_try, FunctionId; PointerLike, sym::pointer_like, TraitId; diff --git a/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs b/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs index 1a34fa913425e..3b94e1c2d6f35 100644 --- a/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs +++ b/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs @@ -803,7 +803,7 @@ impl<'db> SourceAnalyzer<'db> { ) -> Option { let ty = self.ty_of_expr(try_expr.expr()?)?; - let op_fn = self.lang_items(db).TryTraitBranch?; + let op_fn = self.lang_items(db).TryBranch?; // HACK: subst for `branch()` coincides with that for `Try` because `branch()` itself // doesn't have any generic parameters, so we skip building another subst for `branch()`. let substs = GenericArgs::new_from_slice(&[ty.into()]); diff --git a/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs b/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs index cc09a1aae7a6d..3b0f508076baa 100644 --- a/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs +++ b/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs @@ -286,7 +286,7 @@ define_symbols! { Into, into_future, into_iter, - into_try_type, + into_try, IntoFuture, IntoIter, IntoIterator, diff --git a/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs b/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs index 86fb08073253c..f861ad35b61c7 100644 --- a/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs +++ b/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs @@ -955,7 +955,7 @@ pub mod ops { fn from_residual(residual: R) -> Self; } pub const trait Residual: Sized { - type TryType: [const] Try; + type Try: [const] Try; } #[lang = "Try"] pub trait Try: FromResidual { @@ -966,10 +966,10 @@ pub mod ops { #[lang = "branch"] fn branch(self) -> ControlFlow; } - #[lang = "into_try_type"] - pub const fn residual_into_try_type, O>( + #[lang = "into_try"] + pub const fn residual_into_try, O>( r: R, - ) -> >::TryType { + ) -> >::Try { FromResidual::from_residual(r) } @@ -997,7 +997,7 @@ pub mod ops { } impl Residual for ControlFlow { - type TryType = ControlFlow; + type Try = ControlFlow; } // region:option impl Try for Option { @@ -1024,7 +1024,7 @@ pub mod ops { } impl const Residual for Option { - type TryType = Option; + type Try = Option; } // endregion:option // region:result @@ -1057,7 +1057,7 @@ pub mod ops { } impl const Residual for Result { - type TryType = Result; + type Try = Result; } // endregion:from // endregion:result diff --git a/tests/mir-opt/pre-codegen/option_bubble_debug.option_traits.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/option_bubble_debug.option_traits.PreCodegen.after.panic-abort.mir index 55f44d954d806..c5efb1f569a07 100644 --- a/tests/mir-opt/pre-codegen/option_bubble_debug.option_traits.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/option_bubble_debug.option_traits.PreCodegen.after.panic-abort.mir @@ -34,7 +34,7 @@ fn option_traits(_1: Option) -> Option { } bb3: { - _0 = ops::try_trait::residual_into_try_type::, u32>(const Option::::None) -> [return: bb4, unwind unreachable]; + _0 = ops::try_trait::residual_into_try::, u32>(const Option::::None) -> [return: bb4, unwind unreachable]; } bb4: { diff --git a/tests/mir-opt/pre-codegen/option_bubble_debug.option_traits.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/option_bubble_debug.option_traits.PreCodegen.after.panic-unwind.mir index b42aea38d3e35..2ad7bbd5c7caf 100644 --- a/tests/mir-opt/pre-codegen/option_bubble_debug.option_traits.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/option_bubble_debug.option_traits.PreCodegen.after.panic-unwind.mir @@ -34,7 +34,7 @@ fn option_traits(_1: Option) -> Option { } bb3: { - _0 = ops::try_trait::residual_into_try_type::, u32>(const Option::::None) -> [return: bb4, unwind continue]; + _0 = ops::try_trait::residual_into_try::, u32>(const Option::::None) -> [return: bb4, unwind continue]; } bb4: { diff --git a/tests/ui/traits/const-traits/auxiliary/minicore.rs b/tests/ui/traits/const-traits/auxiliary/minicore.rs index 2e5df13d021d5..088a0f9c47c2b 100644 --- a/tests/ui/traits/const-traits/auxiliary/minicore.rs +++ b/tests/ui/traits/const-traits/auxiliary/minicore.rs @@ -133,7 +133,7 @@ pub const trait Drop { } pub const trait Residual { - type TryType: [const] Try + Try; + type Try: [const] Try + Try; } const fn size_of() -> usize { From d3aabdbfbc9e14c17f55549fb223d02179049dfb Mon Sep 17 00:00:00 2001 From: nxsaken Date: Mon, 13 Apr 2026 12:12:49 +0400 Subject: [PATCH 2/3] fmt --- compiler/rustc_hir_typeck/src/expr.rs | 4 +--- library/core/src/iter/traits/iterator.rs | 4 +--- library/core/src/ops/try_trait.rs | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 7a48f9930f73e..9fd23db3fc6d3 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -576,9 +576,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { Some(ObligationCauseCode::ForLoopIterator) } - LangItem::TryFromOutput - if expr.span.is_desugaring(DesugaringKind::TryBlock) => - { + LangItem::TryFromOutput if expr.span.is_desugaring(DesugaringKind::TryBlock) => { // FIXME it's a try block, not a question mark Some(ObligationCauseCode::QuestionMark) } diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 3309f49ad5d9d..64064dce0abc1 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -3058,9 +3058,7 @@ pub const trait Iterator { R: Try>>, { #[inline] - fn check( - mut f: impl FnMut(&I) -> V, - ) -> impl FnMut((), I) -> ControlFlow + fn check(mut f: impl FnMut(&I) -> V) -> impl FnMut((), I) -> ControlFlow where V: Try, R: Residual>, diff --git a/library/core/src/ops/try_trait.rs b/library/core/src/ops/try_trait.rs index 5e5bc18254b07..64c9a52601a1f 100644 --- a/library/core/src/ops/try_trait.rs +++ b/library/core/src/ops/try_trait.rs @@ -378,9 +378,7 @@ pub const trait Residual: Sized { #[expect(unreachable_pub)] #[inline] // FIXME: force would be nice, but fails -- see #148915 #[lang = "into_try"] -pub const fn residual_into_try, O>( - r: R, -) -> >::Try { +pub const fn residual_into_try, O>(r: R) -> >::Try { FromResidual::from_residual(r) } From 69f25768e283b75bedae658f0bb97130c577a731 Mon Sep 17 00:00:00 2001 From: nxsaken Date: Mon, 13 Apr 2026 16:19:26 +0400 Subject: [PATCH 3/3] Support the old lang item in rust-analyzer --- src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs | 2 +- src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs | 3 +++ src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs b/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs index 5b9f6b1fbae56..6c91c808afefc 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs @@ -2010,7 +2010,7 @@ impl<'db> ExprCollector<'db> { let it = self.alloc_expr(Expr::Path(Path::from(break_name)), syntax_ptr); let convert_fn = match self.current_try_block { Some(TryBlock::Homogeneous { .. }) => { - self.lang_path(lang_items.ResidualIntoTry) + self.lang_path(lang_items.ResidualIntoTry.or(lang_items.ResidualIntoTryOld)) } Some(TryBlock::Heterogeneous { .. }) | None => { self.lang_path(lang_items.TryFromResidual) diff --git a/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs b/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs index 7960b66c91121..c6129db767d28 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs @@ -457,6 +457,9 @@ language_item_table! { LangItems => TryBranch, sym::branch, FunctionId; TryFromYeet, sym::from_yeet, FunctionId; ResidualIntoTry, sym::into_try, FunctionId; + // TODO: remove when dropping support for the last stable toolchain using `into_try_type`, + // see https://github.com/rust-lang/rust/pull/155229 + ResidualIntoTryOld, sym::into_try_type, FunctionId; PointerLike, sym::pointer_like, TraitId; diff --git a/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs b/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs index 3b0f508076baa..4bfd39118dec1 100644 --- a/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs +++ b/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs @@ -287,6 +287,7 @@ define_symbols! { into_future, into_iter, into_try, + into_try_type, IntoFuture, IntoIter, IntoIterator,