Skip to content

Commit 8d94899

Browse files
authored
Unrolled build for #150548
Rollup merge of #150548 - dianne:temp-scope-extension-loop-rewrite, r=BoxyUwU `region_scope_tree`: Rewrite a `loop` as tail recursion This addresses #146098 (comment), hopefully making `record_subexpr_extended_temp_scopes` a bit more legible. I removed a `debug!` in the process, since the function it calls every iteration, [`ScopeTree::record_extended_temp_scope`](https://github.com/rust-lang/rust/blob/2848c2ebe9a8a604cd63455263299d7258bc8252/compiler/rustc_middle/src/middle/region.rs#L264-L271), does the same `debug!`. Keeping the behavior of having an additional `debug!` for the top-level expression would hurt legibility, and having a duplicate `debug!` at each iteration seems excessive. No information is lost from the debug output, so I think it's fine to just have the inner `debug!`s. r? BoxyUwU or anyone
2 parents 4c62aa4 + 6b60e81 commit 8d94899

File tree

1 file changed

+14
-20
lines changed
  • compiler/rustc_hir_analysis/src/check

1 file changed

+14
-20
lines changed

compiler/rustc_hir_analysis/src/check/region.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -701,31 +701,25 @@ fn resolve_local<'tcx>(
701701
/// Note: ET is intended to match "rvalues or places based on rvalues".
702702
fn record_subexpr_extended_temp_scopes(
703703
scope_tree: &mut ScopeTree,
704-
mut expr: &hir::Expr<'_>,
704+
expr: &hir::Expr<'_>,
705705
lifetime: Option<Scope>,
706706
) {
707-
debug!(?expr, ?lifetime);
707+
// Note: give all the expressions matching `ET` with the
708+
// extended temporary lifetime, not just the innermost rvalue,
709+
// because in MIR building if we must compile e.g., `*rvalue()`
710+
// into a temporary, we request the temporary scope of the
711+
// outer expression.
708712

709-
loop {
710-
// Note: give all the expressions matching `ET` with the
711-
// extended temporary lifetime, not just the innermost rvalue,
712-
// because in MIR building if we must compile e.g., `*rvalue()`
713-
// into a temporary, we request the temporary scope of the
714-
// outer expression.
713+
scope_tree.record_extended_temp_scope(expr.hir_id.local_id, lifetime);
715714

716-
scope_tree.record_extended_temp_scope(expr.hir_id.local_id, lifetime);
717-
718-
match expr.kind {
719-
hir::ExprKind::AddrOf(_, _, subexpr)
720-
| hir::ExprKind::Unary(hir::UnOp::Deref, subexpr)
721-
| hir::ExprKind::Field(subexpr, _)
722-
| hir::ExprKind::Index(subexpr, _, _) => {
723-
expr = subexpr;
724-
}
725-
_ => {
726-
return;
727-
}
715+
match expr.kind {
716+
hir::ExprKind::AddrOf(_, _, subexpr)
717+
| hir::ExprKind::Unary(hir::UnOp::Deref, subexpr)
718+
| hir::ExprKind::Field(subexpr, _)
719+
| hir::ExprKind::Index(subexpr, _, _) => {
720+
record_subexpr_extended_temp_scopes(scope_tree, subexpr, lifetime);
728721
}
722+
_ => {}
729723
}
730724
}
731725

0 commit comments

Comments
 (0)