From 6b60e81e8c6de24a5d131dab3d5d61541aa0fb96 Mon Sep 17 00:00:00 2001 From: dianne Date: Wed, 31 Dec 2025 08:51:49 -0800 Subject: [PATCH] Rewrite a `loop` as tail recursion --- .../rustc_hir_analysis/src/check/region.rs | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/region.rs b/compiler/rustc_hir_analysis/src/check/region.rs index 0e8cdc266f899..0c611e6c4c9e6 100644 --- a/compiler/rustc_hir_analysis/src/check/region.rs +++ b/compiler/rustc_hir_analysis/src/check/region.rs @@ -701,31 +701,25 @@ fn resolve_local<'tcx>( /// Note: ET is intended to match "rvalues or places based on rvalues". fn record_subexpr_extended_temp_scopes( scope_tree: &mut ScopeTree, - mut expr: &hir::Expr<'_>, + expr: &hir::Expr<'_>, lifetime: Option, ) { - debug!(?expr, ?lifetime); + // Note: give all the expressions matching `ET` with the + // extended temporary lifetime, not just the innermost rvalue, + // because in MIR building if we must compile e.g., `*rvalue()` + // into a temporary, we request the temporary scope of the + // outer expression. - loop { - // Note: give all the expressions matching `ET` with the - // extended temporary lifetime, not just the innermost rvalue, - // because in MIR building if we must compile e.g., `*rvalue()` - // into a temporary, we request the temporary scope of the - // outer expression. + scope_tree.record_extended_temp_scope(expr.hir_id.local_id, lifetime); - scope_tree.record_extended_temp_scope(expr.hir_id.local_id, lifetime); - - match expr.kind { - hir::ExprKind::AddrOf(_, _, subexpr) - | hir::ExprKind::Unary(hir::UnOp::Deref, subexpr) - | hir::ExprKind::Field(subexpr, _) - | hir::ExprKind::Index(subexpr, _, _) => { - expr = subexpr; - } - _ => { - return; - } + match expr.kind { + hir::ExprKind::AddrOf(_, _, subexpr) + | hir::ExprKind::Unary(hir::UnOp::Deref, subexpr) + | hir::ExprKind::Field(subexpr, _) + | hir::ExprKind::Index(subexpr, _, _) => { + record_subexpr_extended_temp_scopes(scope_tree, subexpr, lifetime); } + _ => {} } }