From 0e50d5a7ff073a307721e3e525bf28a1876086ab Mon Sep 17 00:00:00 2001 From: dianne Date: Wed, 5 Nov 2025 05:59:28 -0800 Subject: [PATCH 1/2] merge `RvalueScopes` into `ScopeTree` This removes some unneeded indirection and consolidates the logic for scope resolution. --- .../rustc_hir_analysis/src/check/region.rs | 64 ++++++++++++--- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 9 +-- compiler/rustc_hir_typeck/src/lib.rs | 4 - .../rustc_hir_typeck/src/rvalue_scopes.rs | 79 ------------------- compiler/rustc_hir_typeck/src/writeback.rs | 3 - compiler/rustc_middle/src/middle/region.rs | 51 ++++++------ compiler/rustc_middle/src/ty/mod.rs | 2 - compiler/rustc_middle/src/ty/rvalue_scopes.rs | 48 ----------- .../rustc_middle/src/ty/typeck_results.rs | 7 -- .../src/builder/expr/as_rvalue.rs | 4 +- compiler/rustc_mir_build/src/thir/cx/expr.rs | 31 +++----- compiler/rustc_mir_build/src/thir/cx/mod.rs | 4 +- 12 files changed, 99 insertions(+), 207 deletions(-) delete mode 100644 compiler/rustc_hir_typeck/src/rvalue_scopes.rs delete mode 100644 compiler/rustc_middle/src/ty/rvalue_scopes.rs diff --git a/compiler/rustc_hir_analysis/src/check/region.rs b/compiler/rustc_hir_analysis/src/check/region.rs index bac34454b3b7a..42bbe3947e0b9 100644 --- a/compiler/rustc_hir_analysis/src/check/region.rs +++ b/compiler/rustc_hir_analysis/src/check/region.rs @@ -516,12 +516,10 @@ fn resolve_local<'tcx>( if let Some(pat) = pat { if is_binding_pat(pat) { - visitor.scope_tree.record_rvalue_candidate( - expr.hir_id, - RvalueCandidate { - target: expr.hir_id.local_id, - lifetime: visitor.cx.var_parent, - }, + record_subexpr_extended_temp_scopes( + &mut visitor.scope_tree, + expr, + visitor.cx.var_parent, ); } } @@ -604,7 +602,7 @@ fn resolve_local<'tcx>( } } - /// If `expr` matches the `E&` grammar, then records an extended rvalue scope as appropriate: + /// If `expr` matches the `E&` grammar, then records an extended temporary scope as appropriate: /// /// ```text /// E& = & ET @@ -627,10 +625,7 @@ fn resolve_local<'tcx>( match expr.kind { hir::ExprKind::AddrOf(_, _, subexpr) => { record_rvalue_scope_if_borrow_expr(visitor, subexpr, blk_id); - visitor.scope_tree.record_rvalue_candidate( - subexpr.hir_id, - RvalueCandidate { target: subexpr.hir_id.local_id, lifetime: blk_id }, - ); + record_subexpr_extended_temp_scopes(&mut visitor.scope_tree, subexpr, blk_id); } hir::ExprKind::Struct(_, fields, _) => { for field in fields { @@ -687,6 +682,53 @@ fn resolve_local<'tcx>( } } +/// Applied to an expression `expr` if `expr` -- or something owned or partially owned by +/// `expr` -- is going to be indirectly referenced by a variable in a let statement. In that +/// case, the "temporary lifetime" of `expr` is extended to be the block enclosing the `let` +/// statement. +/// +/// More formally, if `expr` matches the grammar `ET`, record the temporary scope of the matching +/// `` as `lifetime`: +/// +/// ```text +/// ET = *ET +/// | ET[...] +/// | ET.f +/// | (ET) +/// | +/// ``` +/// +/// 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<'_>, + lifetime: Option, +) { + debug!(?expr, ?lifetime); + + 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); + + 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; + } + } + } +} + impl<'tcx> ScopeResolutionVisitor<'tcx> { /// Records the current parent (if any) as the parent of `child_scope`. fn record_child_scope(&mut self, child_scope: Scope) { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 38586c844445b..da719e615fd70 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -40,7 +40,7 @@ use tracing::{debug, instrument}; use crate::callee::{self, DeferredCallResolution}; use crate::errors::{self, CtorIsPrivate}; use crate::method::{self, MethodCallee}; -use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy, rvalue_scopes}; +use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy}; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Produces warning on the given node, if the current point in the @@ -604,13 +604,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.normalize(span, field.ty(self.tcx, args)) } - pub(crate) fn resolve_rvalue_scopes(&self, def_id: DefId) { - let scope_tree = self.tcx.region_scope_tree(def_id); - let rvalue_scopes = { rvalue_scopes::resolve_rvalue_scopes(self, scope_tree, def_id) }; - let mut typeck_results = self.typeck_results.borrow_mut(); - typeck_results.rvalue_scopes = rvalue_scopes; - } - /// Drain all obligations that are stalled on coroutines defined in this body. #[instrument(level = "debug", skip(self))] pub(crate) fn drain_stalled_coroutine_obligations(&self) { diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index b4264e9993313..d090eb6338284 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -37,7 +37,6 @@ mod op; mod opaque_types; mod pat; mod place_op; -mod rvalue_scopes; mod typeck_root_ctxt; mod upvar; mod writeback; @@ -237,9 +236,6 @@ fn typeck_with_inspect<'tcx>( // because they don't constrain other type variables. fcx.closure_analyze(body); assert!(fcx.deferred_call_resolutions.borrow().is_empty()); - // Before the coroutine analysis, temporary scopes shall be marked to provide more - // precise information on types to be captured. - fcx.resolve_rvalue_scopes(def_id.to_def_id()); for (ty, span, code) in fcx.deferred_sized_obligations.borrow_mut().drain(..) { let ty = fcx.normalize(span, ty); diff --git a/compiler/rustc_hir_typeck/src/rvalue_scopes.rs b/compiler/rustc_hir_typeck/src/rvalue_scopes.rs deleted file mode 100644 index 973dc7141e64d..0000000000000 --- a/compiler/rustc_hir_typeck/src/rvalue_scopes.rs +++ /dev/null @@ -1,79 +0,0 @@ -use hir::Node; -use hir::def_id::DefId; -use rustc_hir as hir; -use rustc_middle::bug; -use rustc_middle::middle::region::{RvalueCandidate, Scope, ScopeTree}; -use rustc_middle::ty::RvalueScopes; -use tracing::debug; - -use super::FnCtxt; - -/// Applied to an expression `expr` if `expr` -- or something owned or partially owned by -/// `expr` -- is going to be indirectly referenced by a variable in a let statement. In that -/// case, the "temporary lifetime" or `expr` is extended to be the block enclosing the `let` -/// statement. -/// -/// More formally, if `expr` matches the grammar `ET`, record the rvalue scope of the matching -/// `` as `blk_id`: -/// -/// ```text -/// ET = *ET -/// | ET[...] -/// | ET.f -/// | (ET) -/// | -/// ``` -/// -/// Note: ET is intended to match "rvalues or places based on rvalues". -fn record_rvalue_scope_rec( - rvalue_scopes: &mut RvalueScopes, - mut expr: &hir::Expr<'_>, - lifetime: Option, -) { - loop { - // Note: give all the expressions matching `ET` with the - // extended temporary lifetime, not just the innermost rvalue, - // because in codegen if we must compile e.g., `*rvalue()` - // into a temporary, we request the temporary scope of the - // outer expression. - - rvalue_scopes.record_rvalue_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; - } - } - } -} -fn record_rvalue_scope( - rvalue_scopes: &mut RvalueScopes, - expr: &hir::Expr<'_>, - candidate: &RvalueCandidate, -) { - debug!("resolve_rvalue_scope(expr={expr:?}, candidate={candidate:?})"); - record_rvalue_scope_rec(rvalue_scopes, expr, candidate.lifetime) - // FIXME(@dingxiangfei2009): handle the candidates in the function call arguments -} - -pub(crate) fn resolve_rvalue_scopes<'a, 'tcx>( - fcx: &'a FnCtxt<'a, 'tcx>, - scope_tree: &'a ScopeTree, - def_id: DefId, -) -> RvalueScopes { - let tcx = &fcx.tcx; - let mut rvalue_scopes = RvalueScopes::new(); - debug!("start resolving rvalue scopes, def_id={def_id:?}"); - debug!("rvalue_scope: rvalue_candidates={:?}", scope_tree.rvalue_candidates); - for (&hir_id, candidate) in &scope_tree.rvalue_candidates { - let Node::Expr(expr) = tcx.hir_node(hir_id) else { bug!("hir node does not exist") }; - record_rvalue_scope(&mut rvalue_scopes, expr, candidate); - } - rvalue_scopes -} diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index 3235aa396df4f..ec4e7cd6c82a6 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -79,9 +79,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { wbcx.visit_offset_of_container_types(); wbcx.visit_potentially_region_dependent_goals(); - wbcx.typeck_results.rvalue_scopes = - mem::take(&mut self.typeck_results.borrow_mut().rvalue_scopes); - let used_trait_imports = mem::take(&mut self.typeck_results.borrow_mut().used_trait_imports); debug!("used_trait_imports({:?}) = {:?}", item_def_id, used_trait_imports); diff --git a/compiler/rustc_middle/src/middle/region.rs b/compiler/rustc_middle/src/middle/region.rs index 3ed8d9a36e101..c0e443b5ead87 100644 --- a/compiler/rustc_middle/src/middle/region.rs +++ b/compiler/rustc_middle/src/middle/region.rs @@ -11,7 +11,7 @@ use std::fmt; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::unord::UnordMap; use rustc_hir as hir; -use rustc_hir::{HirId, HirIdMap, Node}; +use rustc_hir::{HirId, ItemLocalMap, Node}; use rustc_macros::{HashStable, TyDecodable, TyEncodable}; use rustc_span::{DUMMY_SP, Span}; use tracing::debug; @@ -221,12 +221,12 @@ pub struct ScopeTree { /// variable is declared. var_map: FxIndexMap, - /// Identifies expressions which, if captured into a temporary, ought to - /// have a temporary whose lifetime extends to the end of the enclosing *block*, - /// and not the enclosing *statement*. Expressions that are not present in this - /// table are not rvalue candidates. The set of rvalue candidates is computed - /// during type check based on a traversal of the AST. - pub rvalue_candidates: HirIdMap, + /// Tracks expressions with extended temporary scopes, based on the syntactic rules for + /// temporary lifetime extension. Further details may be found in + /// `rustc_hir_analysis::check::region` and in the [Reference]. + /// + /// [Reference]: https://doc.rust-lang.org/nightly/reference/destructors.html#temporary-lifetime-extension + extended_temp_scopes: ItemLocalMap>, /// Backwards incompatible scoping that will be introduced in future editions. /// This information is used later for linting to identify locals and @@ -234,16 +234,6 @@ pub struct ScopeTree { pub backwards_incompatible_scope: UnordMap, } -/// See the `rvalue_candidates` field for more information on rvalue -/// candidates in general. -/// The `lifetime` field is None to indicate that certain expressions escape -/// into 'static and should have no local cleanup scope. -#[derive(Debug, Copy, Clone, HashStable)] -pub struct RvalueCandidate { - pub target: hir::ItemLocalId, - pub lifetime: Option, -} - impl ScopeTree { pub fn record_scope_parent(&mut self, child: Scope, parent: Option) { debug!("{:?}.parent = {:?}", child, parent); @@ -260,12 +250,13 @@ impl ScopeTree { self.var_map.insert(var, lifetime); } - pub fn record_rvalue_candidate(&mut self, var: HirId, candidate: RvalueCandidate) { - debug!("record_rvalue_candidate(var={var:?}, candidate={candidate:?})"); - if let Some(lifetime) = &candidate.lifetime { - assert!(var.local_id != lifetime.local_id) + /// Make an association between a sub-expression and an extended lifetime + pub fn record_extended_temp_scope(&mut self, var: hir::ItemLocalId, lifetime: Option) { + debug!(?var, ?lifetime); + if let Some(lifetime) = lifetime { + assert!(var != lifetime.local_id); } - self.rvalue_candidates.insert(var, candidate); + self.extended_temp_scopes.insert(var, lifetime); } /// Returns the narrowest scope that encloses `id`, if any. @@ -337,4 +328,20 @@ impl ScopeTree { span_bug!(ty::tls::with(|tcx| inner.span(tcx, self)), "no enclosing temporary scope") } + + /// Returns the scope when the temp created by `expr_id` will be cleaned up. + /// It also emits a lint on potential backwards incompatible change to the temporary scope + /// which is *for now* always shortening. + pub fn temporary_scope(&self, expr_id: hir::ItemLocalId) -> (Option, Option) { + // Check for a designated extended temporary scope. + if let Some(&s) = self.extended_temp_scopes.get(&expr_id) { + debug!("temporary_scope({expr_id:?}) = {s:?} [custom]"); + return (s, None); + } + + // Otherwise, locate the innermost terminating scope. + let (scope, backward_incompatible) = + self.default_temporary_scope(Scope { local_id: expr_id, data: ScopeData::Node }); + (Some(scope), backward_incompatible) + } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index d253deb2fe8fd..a6894522477c0 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -97,7 +97,6 @@ pub use self::region::{ BoundRegion, BoundRegionKind, EarlyParamRegion, LateParamRegion, LateParamRegionKind, Region, RegionKind, RegionVid, }; -pub use self::rvalue_scopes::RvalueScopes; pub use self::sty::{ AliasTy, Article, Binder, BoundTy, BoundTyKind, BoundVariableKind, CanonicalPolyFnSig, CoroutineArgsExt, EarlyBinder, FnSig, InlineConstArgs, InlineConstArgsParts, ParamConst, @@ -156,7 +155,6 @@ mod list; mod opaque_types; mod predicate; mod region; -mod rvalue_scopes; mod structural_impls; #[allow(hidden_glob_reexports)] mod sty; diff --git a/compiler/rustc_middle/src/ty/rvalue_scopes.rs b/compiler/rustc_middle/src/ty/rvalue_scopes.rs deleted file mode 100644 index df4e29d457548..0000000000000 --- a/compiler/rustc_middle/src/ty/rvalue_scopes.rs +++ /dev/null @@ -1,48 +0,0 @@ -use rustc_hir as hir; -use rustc_hir::ItemLocalMap; -use rustc_macros::{HashStable, TyDecodable, TyEncodable}; -use tracing::debug; - -use crate::middle::region::{Scope, ScopeData, ScopeTree}; - -/// `RvalueScopes` is a mapping from sub-expressions to _extended_ lifetime as determined by -/// rules laid out in `rustc_hir_analysis::check::rvalue_scopes`. -#[derive(TyEncodable, TyDecodable, Clone, Debug, Default, Eq, PartialEq, HashStable)] -pub struct RvalueScopes { - map: ItemLocalMap>, -} - -impl RvalueScopes { - pub fn new() -> Self { - Self { map: <_>::default() } - } - - /// Returns the scope when the temp created by `expr_id` will be cleaned up. - /// It also emits a lint on potential backwards incompatible change to the temporary scope - /// which is *for now* always shortening. - pub fn temporary_scope( - &self, - region_scope_tree: &ScopeTree, - expr_id: hir::ItemLocalId, - ) -> (Option, Option) { - // Check for a designated rvalue scope. - if let Some(&s) = self.map.get(&expr_id) { - debug!("temporary_scope({expr_id:?}) = {s:?} [custom]"); - return (s, None); - } - - // Otherwise, locate the innermost terminating scope. - let (scope, backward_incompatible) = region_scope_tree - .default_temporary_scope(Scope { local_id: expr_id, data: ScopeData::Node }); - (Some(scope), backward_incompatible) - } - - /// Make an association between a sub-expression and an extended lifetime - pub fn record_rvalue_scope(&mut self, var: hir::ItemLocalId, lifetime: Option) { - debug!("record_rvalue_scope(var={var:?}, lifetime={lifetime:?})"); - if let Some(lifetime) = lifetime { - assert!(var != lifetime.local_id); - } - self.map.insert(var, lifetime); - } -} diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index 5300be58f04e6..55b738a0a34fc 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -18,7 +18,6 @@ use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisit use rustc_session::Session; use rustc_span::Span; -use super::RvalueScopes; use crate::hir::place::Place as HirPlace; use crate::infer::canonical::Canonical; use crate::mir::FakeReadCause; @@ -198,11 +197,6 @@ pub struct TypeckResults<'tcx> { /// issue by fake reading `t`. pub closure_fake_reads: LocalDefIdMap, FakeReadCause, HirId)>>, - /// Tracks the rvalue scoping rules which defines finer scoping for rvalue expressions - /// by applying extended parameter rules. - /// Details may be found in `rustc_hir_analysis::check::rvalue_scopes`. - pub rvalue_scopes: RvalueScopes, - /// Stores the predicates that apply on coroutine witness types. /// formatting modified file tests/ui/coroutine/retain-resume-ref.rs pub coroutine_stalled_predicates: FxIndexSet<(ty::Predicate<'tcx>, ObligationCause<'tcx>)>, @@ -254,7 +248,6 @@ impl<'tcx> TypeckResults<'tcx> { hidden_types: Default::default(), closure_min_captures: Default::default(), closure_fake_reads: Default::default(), - rvalue_scopes: Default::default(), coroutine_stalled_predicates: Default::default(), potentially_region_dependent_goals: Default::default(), closure_size_eval: Default::default(), diff --git a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs index 552f8c66784ed..546bfc8ea547a 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs @@ -779,8 +779,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { Rvalue::Ref(this.tcx.lifetimes.re_erased, borrow_kind, arg_place), ); - // See the comment in `expr_as_temp` and on the `rvalue_scopes` field for why - // this can be `None`. + // This can be `None` if the expression's temporary scope was extended so that it can be + // borrowed by a `const` or `static`. In that case, it's never dropped. if let Some(temp_lifetime) = temp_lifetime { this.schedule_drop_storage_and_value(upvar_span, temp_lifetime, temp); } diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 8ce0b73e47e36..6ac935d3901ed 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -337,7 +337,7 @@ impl<'tcx> ThirBuildCx<'tcx> { let tcx = self.tcx; let expr_ty = self.typeck_results.expr_ty(expr); let (temp_lifetime, backwards_incompatible) = - self.rvalue_scopes.temporary_scope(self.region_scope_tree, expr.hir_id.local_id); + self.region_scope_tree.temporary_scope(expr.hir_id.local_id); let kind = match expr.kind { // Here comes the interesting stuff: @@ -502,9 +502,8 @@ impl<'tcx> ThirBuildCx<'tcx> { expr: Some(arg), safety_mode: BlockSafety::Safe, }); - let (temp_lifetime, backwards_incompatible) = self - .rvalue_scopes - .temporary_scope(self.region_scope_tree, arg_expr.hir_id.local_id); + let (temp_lifetime, backwards_incompatible) = + self.region_scope_tree.temporary_scope(arg_expr.hir_id.local_id); arg = self.thir.exprs.push(Expr { temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, ty: arg_ty, @@ -996,9 +995,8 @@ impl<'tcx> ThirBuildCx<'tcx> { } } else { let block_ty = self.typeck_results.node_type(body.hir_id); - let (temp_lifetime, backwards_incompatible) = self - .rvalue_scopes - .temporary_scope(self.region_scope_tree, body.hir_id.local_id); + let (temp_lifetime, backwards_incompatible) = + self.region_scope_tree.temporary_scope(body.hir_id.local_id); let block = self.mirror_block(body); let body = self.thir.exprs.push(Expr { ty: block_ty, @@ -1143,7 +1141,7 @@ impl<'tcx> ThirBuildCx<'tcx> { overloaded_callee: Option>, ) -> Expr<'tcx> { let (temp_lifetime, backwards_incompatible) = - self.rvalue_scopes.temporary_scope(self.region_scope_tree, expr.hir_id.local_id); + self.region_scope_tree.temporary_scope(expr.hir_id.local_id); let (ty, user_ty) = match overloaded_callee { Some(fn_def) => (fn_def, None), None => { @@ -1237,9 +1235,8 @@ impl<'tcx> ThirBuildCx<'tcx> { Res::Def(DefKind::Static { .. }, id) => { // this is &raw for extern static or static mut, and & for other statics let ty = self.tcx.static_ptr_ty(id, self.typing_env); - let (temp_lifetime, backwards_incompatible) = self - .rvalue_scopes - .temporary_scope(self.region_scope_tree, expr.hir_id.local_id); + let (temp_lifetime, backwards_incompatible) = + self.region_scope_tree.temporary_scope(expr.hir_id.local_id); let kind = if self.tcx.is_thread_local_static(id) { ExprKind::ThreadLocalRef(id) } else { @@ -1321,7 +1318,7 @@ impl<'tcx> ThirBuildCx<'tcx> { // construct the complete expression `foo()` for the overloaded call, // which will yield the &T type let (temp_lifetime, backwards_incompatible) = - self.rvalue_scopes.temporary_scope(self.region_scope_tree, expr.hir_id.local_id); + self.region_scope_tree.temporary_scope(expr.hir_id.local_id); let fun = self.method_callee(expr, span, overloaded_callee); let fun = self.thir.exprs.push(fun); let fun_ty = self.thir[fun].ty; @@ -1341,9 +1338,8 @@ impl<'tcx> ThirBuildCx<'tcx> { closure_expr: &'tcx hir::Expr<'tcx>, place: HirPlace<'tcx>, ) -> Expr<'tcx> { - let (temp_lifetime, backwards_incompatible) = self - .rvalue_scopes - .temporary_scope(self.region_scope_tree, closure_expr.hir_id.local_id); + let (temp_lifetime, backwards_incompatible) = + self.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id); let var_ty = place.base_ty; // The result of capture analysis in `rustc_hir_typeck/src/upvar.rs` represents a captured path @@ -1405,9 +1401,8 @@ impl<'tcx> ThirBuildCx<'tcx> { let upvar_capture = captured_place.info.capture_kind; let captured_place_expr = self.convert_captured_hir_place(closure_expr, captured_place.place.clone()); - let (temp_lifetime, backwards_incompatible) = self - .rvalue_scopes - .temporary_scope(self.region_scope_tree, closure_expr.hir_id.local_id); + let (temp_lifetime, backwards_incompatible) = + self.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id); match upvar_capture { ty::UpvarCapture::ByValue => captured_place_expr, diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index 9657c4dc839d6..65b05a0e6a985 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -12,7 +12,7 @@ use rustc_hir::{self as hir, HirId, find_attr}; use rustc_middle::bug; use rustc_middle::middle::region; use rustc_middle::thir::*; -use rustc_middle::ty::{self, RvalueScopes, TyCtxt}; +use rustc_middle::ty::{self, TyCtxt}; use tracing::instrument; use crate::thir::pattern::pat_from_hir; @@ -62,7 +62,6 @@ struct ThirBuildCx<'tcx> { region_scope_tree: &'tcx region::ScopeTree, typeck_results: &'tcx ty::TypeckResults<'tcx>, - rvalue_scopes: &'tcx RvalueScopes, /// False to indicate that adjustments should not be applied. Only used for `custom_mir` apply_adjustments: bool, @@ -109,7 +108,6 @@ impl<'tcx> ThirBuildCx<'tcx> { typing_env: ty::TypingEnv::non_body_analysis(tcx, def), region_scope_tree: tcx.region_scope_tree(def), typeck_results, - rvalue_scopes: &typeck_results.rvalue_scopes, body_owner: def.to_def_id(), apply_adjustments: !find_attr!(tcx.hir_attrs(hir_id), AttributeKind::CustomMir(..) => ()).is_some(), From d18697886a817527f5a65f9ca19a5dbd16bcff9f Mon Sep 17 00:00:00 2001 From: dianne Date: Sat, 8 Nov 2025 09:25:45 -0800 Subject: [PATCH 2/2] compute temporary scopes when building MIR, not THIR --- compiler/rustc_middle/src/middle/region.rs | 19 ++- compiler/rustc_middle/src/thir.rs | 20 +-- compiler/rustc_middle/src/thir/visit.rs | 2 +- .../src/builder/expr/as_constant.rs | 4 +- .../src/builder/expr/as_operand.rs | 1 + .../src/builder/expr/as_place.rs | 23 ++-- .../src/builder/expr/as_rvalue.rs | 2 +- .../src/builder/expr/as_temp.rs | 2 +- .../rustc_mir_build/src/builder/expr/stmt.rs | 2 +- .../src/builder/matches/mod.rs | 2 +- compiler/rustc_mir_build/src/thir/cx/expr.rs | 85 ++++-------- compiler/rustc_mir_build/src/thir/cx/mod.rs | 3 - compiler/rustc_mir_build/src/thir/print.rs | 4 +- tests/ui/thir-print/c-variadic.stdout | 4 +- .../thir-print/thir-flat-const-variant.stdout | 126 +++--------------- tests/ui/thir-print/thir-flat.stdout | 14 +- .../ui/thir-print/thir-tree-loop-match.stdout | 46 +++---- tests/ui/thir-print/thir-tree-match.stdout | 28 ++-- tests/ui/thir-print/thir-tree.stdout | 4 +- tests/ui/unpretty/box.stdout | 12 +- 20 files changed, 138 insertions(+), 265 deletions(-) diff --git a/compiler/rustc_middle/src/middle/region.rs b/compiler/rustc_middle/src/middle/region.rs index c0e443b5ead87..990ed8f48fb84 100644 --- a/compiler/rustc_middle/src/middle/region.rs +++ b/compiler/rustc_middle/src/middle/region.rs @@ -234,6 +234,17 @@ pub struct ScopeTree { pub backwards_incompatible_scope: UnordMap, } +/// Temporary lifetime information for expressions, used when lowering to MIR. +#[derive(Clone, Copy, Debug, HashStable)] +pub struct TempLifetime { + /// The scope in which a temporary should be dropped. If `None`, no drop is scheduled; this is + /// the case for lifetime-extended temporaries extended by a const/static item or const block. + pub temp_lifetime: Option, + /// If `Some(lt)`, indicates that the lifetime of this temporary will change to `lt` in a future edition. + /// If `None`, then no changes are expected, or lints are disabled. + pub backwards_incompatible: Option, +} + impl ScopeTree { pub fn record_scope_parent(&mut self, child: Scope, parent: Option) { debug!("{:?}.parent = {:?}", child, parent); @@ -332,16 +343,16 @@ impl ScopeTree { /// Returns the scope when the temp created by `expr_id` will be cleaned up. /// It also emits a lint on potential backwards incompatible change to the temporary scope /// which is *for now* always shortening. - pub fn temporary_scope(&self, expr_id: hir::ItemLocalId) -> (Option, Option) { + pub fn temporary_scope(&self, expr_id: hir::ItemLocalId) -> TempLifetime { // Check for a designated extended temporary scope. if let Some(&s) = self.extended_temp_scopes.get(&expr_id) { debug!("temporary_scope({expr_id:?}) = {s:?} [custom]"); - return (s, None); + return TempLifetime { temp_lifetime: s, backwards_incompatible: None }; } // Otherwise, locate the innermost terminating scope. - let (scope, backward_incompatible) = + let (scope, backwards_incompatible) = self.default_temporary_scope(Scope { local_id: expr_id, data: ScopeData::Node }); - (Some(scope), backward_incompatible) + TempLifetime { temp_lifetime: Some(scope), backwards_incompatible } } } diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index e72ed78d07e6a..4f38ef017f499 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -256,25 +256,15 @@ pub struct Expr<'tcx> { /// The type of this expression pub ty: Ty<'tcx>, - /// The lifetime of this expression if it should be spilled into a - /// temporary - pub temp_lifetime: TempLifetime, + /// The id of the HIR expression whose [temporary scope] should be used for this expression. + /// + /// [temporary scope]: https://doc.rust-lang.org/reference/destructors.html#temporary-scopes + pub temp_scope_id: hir::ItemLocalId, /// span of the expression in the source pub span: Span, } -/// Temporary lifetime information for THIR expressions -#[derive(Clone, Copy, Debug, HashStable)] -pub struct TempLifetime { - /// Lifetime for temporaries as expected. - /// This should be `None` in a constant context. - pub temp_lifetime: Option, - /// If `Some(lt)`, indicates that the lifetime of this temporary will change to `lt` in a future edition. - /// If `None`, then no changes are expected, or lints are disabled. - pub backwards_incompatible: Option, -} - #[derive(Clone, Debug, HashStable)] pub enum ExprKind<'tcx> { /// `Scope`s are used to explicitly mark destruction scopes, @@ -1127,7 +1117,7 @@ mod size_asserts { use super::*; // tidy-alphabetical-start static_assert_size!(Block, 48); - static_assert_size!(Expr<'_>, 72); + static_assert_size!(Expr<'_>, 64); static_assert_size!(ExprKind<'_>, 40); static_assert_size!(Pat<'_>, 64); static_assert_size!(PatKind<'_>, 48); diff --git a/compiler/rustc_middle/src/thir/visit.rs b/compiler/rustc_middle/src/thir/visit.rs index dcfa6c4db3274..2ed506767397a 100644 --- a/compiler/rustc_middle/src/thir/visit.rs +++ b/compiler/rustc_middle/src/thir/visit.rs @@ -45,7 +45,7 @@ pub fn walk_expr<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>( expr: &'thir Expr<'tcx>, ) { use ExprKind::*; - let Expr { kind, ty: _, temp_lifetime: _, span: _ } = expr; + let Expr { kind, ty: _, temp_scope_id: _, span: _ } = expr; match *kind { Scope { value, region_scope: _, lint_level: _ } => { visitor.visit_expr(&visitor.thir()[value]) diff --git a/compiler/rustc_mir_build/src/builder/expr/as_constant.rs b/compiler/rustc_mir_build/src/builder/expr/as_constant.rs index 0e0c7a7fa4f0b..eb0546cd0e374 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_constant.rs @@ -21,7 +21,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { pub(crate) fn as_constant(&mut self, expr: &Expr<'tcx>) -> ConstOperand<'tcx> { let this = self; let tcx = this.tcx; - let Expr { ty, temp_lifetime: _, span, ref kind } = *expr; + let Expr { ty, temp_scope_id: _, span, ref kind } = *expr; match kind { ExprKind::Scope { region_scope: _, lint_level: _, value } => { this.as_constant(&this.thir[*value]) @@ -46,7 +46,7 @@ pub(crate) fn as_constant_inner<'tcx>( push_cuta: impl FnMut(&Box>) -> Option, tcx: TyCtxt<'tcx>, ) -> ConstOperand<'tcx> { - let Expr { ty, temp_lifetime: _, span, ref kind } = *expr; + let Expr { ty, temp_scope_id: _, span, ref kind } = *expr; match *kind { ExprKind::Literal { lit, neg } => { let const_ = lit_to_mir_constant(tcx, LitToConstInput { lit: lit.node, ty, neg }); diff --git a/compiler/rustc_mir_build/src/builder/expr/as_operand.rs b/compiler/rustc_mir_build/src/builder/expr/as_operand.rs index 6a42222399041..39ddf0edf5d2a 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_operand.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_operand.rs @@ -1,5 +1,6 @@ //! See docs in build/expr/mod.rs +use rustc_middle::middle::region::TempLifetime; use rustc_middle::mir::*; use rustc_middle::thir::*; use tracing::{debug, instrument}; diff --git a/compiler/rustc_mir_build/src/builder/expr/as_place.rs b/compiler/rustc_mir_build/src/builder/expr/as_place.rs index 1b143f37a585f..6c53562283387 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_place.rs @@ -503,10 +503,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block.and(place_builder) } ExprKind::ValueTypeAscription { source, ref user_ty, user_ty_span } => { - let source_expr = &this.thir[source]; - let temp = unpack!( - block = this.as_temp(block, source_expr.temp_lifetime, source, mutability) - ); + let temp_lifetime = + this.region_scope_tree.temporary_scope(this.thir[source].temp_scope_id); + let temp = unpack!(block = this.as_temp(block, temp_lifetime, source, mutability)); if let Some(user_ty) = user_ty { let ty_source_info = this.source_info(user_ty_span); let annotation_index = @@ -539,10 +538,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block.and(place_builder.project(PlaceElem::UnwrapUnsafeBinder(expr.ty))) } ExprKind::ValueUnwrapUnsafeBinder { source } => { - let source_expr = &this.thir[source]; - let temp = unpack!( - block = this.as_temp(block, source_expr.temp_lifetime, source, mutability) - ); + let temp_lifetime = + this.region_scope_tree.temporary_scope(this.thir[source].temp_scope_id); + let temp = unpack!(block = this.as_temp(block, temp_lifetime, source, mutability)); block.and(PlaceBuilder::from(temp).project(PlaceElem::UnwrapUnsafeBinder(expr.ty))) } @@ -590,8 +588,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | ExprKind::WrapUnsafeBinder { .. } => { // these are not places, so we need to make a temporary. debug_assert!(!matches!(Category::of(&expr.kind), Some(Category::Place))); - let temp = - unpack!(block = this.as_temp(block, expr.temp_lifetime, expr_id, mutability)); + let temp_lifetime = this.region_scope_tree.temporary_scope(expr.temp_scope_id); + let temp = unpack!(block = this.as_temp(block, temp_lifetime, expr_id, mutability)); block.and(PlaceBuilder::from(temp)) } } @@ -637,7 +635,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Making this a *fresh* temporary means we do not have to worry about // the index changing later: Nothing will ever change this temporary. // The "retagging" transformation (for Stacked Borrows) relies on this. - let index_lifetime = self.thir[index].temp_lifetime; + // Using the enclosing temporary scope for the index ensures it will live past where this + // place is used. This lifetime may be larger than strictly necessary but it means we don't + // need to pass a scope for operands to `as_place`. + let index_lifetime = self.region_scope_tree.temporary_scope(self.thir[index].temp_scope_id); let idx = unpack!(block = self.as_temp(block, index_lifetime, index, Mutability::Not)); block = self.bounds_check(block, &base_place, idx, expr_span, source_info); diff --git a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs index 546bfc8ea547a..91814bca76f15 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs @@ -4,7 +4,7 @@ use rustc_abi::FieldIdx; use rustc_hir::lang_items::LangItem; use rustc_index::{Idx, IndexVec}; use rustc_middle::bug; -use rustc_middle::middle::region; +use rustc_middle::middle::region::{self, TempLifetime}; use rustc_middle::mir::interpret::Scalar; use rustc_middle::mir::*; use rustc_middle::thir::*; diff --git a/compiler/rustc_mir_build/src/builder/expr/as_temp.rs b/compiler/rustc_mir_build/src/builder/expr/as_temp.rs index b0ce3527d8b3d..754ab0c0a16e5 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_temp.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_temp.rs @@ -2,7 +2,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hir::HirId; -use rustc_middle::middle::region::{Scope, ScopeData}; +use rustc_middle::middle::region::{Scope, ScopeData, TempLifetime}; use rustc_middle::mir::*; use rustc_middle::thir::*; use tracing::{debug, instrument}; diff --git a/compiler/rustc_mir_build/src/builder/expr/stmt.rs b/compiler/rustc_mir_build/src/builder/expr/stmt.rs index 675beceea14a9..db0d3a449712b 100644 --- a/compiler/rustc_mir_build/src/builder/expr/stmt.rs +++ b/compiler/rustc_mir_build/src/builder/expr/stmt.rs @@ -1,4 +1,4 @@ -use rustc_middle::middle::region; +use rustc_middle::middle::region::{self, TempLifetime}; use rustc_middle::mir::*; use rustc_middle::span_bug; use rustc_middle::thir::*; diff --git a/compiler/rustc_mir_build/src/builder/matches/mod.rs b/compiler/rustc_mir_build/src/builder/matches/mod.rs index 96c58dc14e8cb..03a4256add841 100644 --- a/compiler/rustc_mir_build/src/builder/matches/mod.rs +++ b/compiler/rustc_mir_build/src/builder/matches/mod.rs @@ -15,7 +15,7 @@ use rustc_abi::{FIRST_VARIANT, FieldIdx, VariantIdx}; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hir::{BindingMode, ByRef, LangItem, LetStmt, LocalSource, Node, Pinnedness}; -use rustc_middle::middle::region; +use rustc_middle::middle::region::{self, TempLifetime}; use rustc_middle::mir::*; use rustc_middle::thir::{self, *}; use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty, ValTree, ValTreeKind}; diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 6ac935d3901ed..59efd805b30ed 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -71,7 +71,7 @@ impl<'tcx> ThirBuildCx<'tcx> { // Finally, wrap this up in the expr's scope. expr = Expr { - temp_lifetime: expr.temp_lifetime, + temp_scope_id: expr_scope.local_id, ty: expr.ty, span: hir_expr.span, kind: ExprKind::Scope { @@ -93,7 +93,7 @@ impl<'tcx> ThirBuildCx<'tcx> { adjustment: &Adjustment<'tcx>, mut span: Span, ) -> Expr<'tcx> { - let Expr { temp_lifetime, .. } = expr; + let Expr { temp_scope_id, .. } = expr; // Adjust the span from the block, to the last expression of the // block. This is a better span when returning a mutable reference @@ -152,7 +152,7 @@ impl<'tcx> ThirBuildCx<'tcx> { Ty::new_fn_def(self.tcx, call_def_id, self.tcx.mk_args(&[expr.ty.into()])); expr = Expr { - temp_lifetime, + temp_scope_id, ty: Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased, expr.ty, deref.mutbl), span, kind: ExprKind::Borrow { @@ -199,13 +199,13 @@ impl<'tcx> ThirBuildCx<'tcx> { variant_index: FIRST_VARIANT, name: FieldIdx::ZERO, }; - let arg = Expr { temp_lifetime, ty: pin_ty, span, kind: pointer_target }; + let arg = Expr { temp_scope_id, ty: pin_ty, span, kind: pointer_target }; let arg = self.thir.exprs.push(arg); // arg = *pointer let expr = ExprKind::Deref { arg }; let arg = self.thir.exprs.push(Expr { - temp_lifetime, + temp_scope_id, ty: ptr_target_ty, span, kind: expr, @@ -219,7 +219,7 @@ impl<'tcx> ThirBuildCx<'tcx> { let new_pin_target = Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased, ptr_target_ty, mutbl); let expr = self.thir.exprs.push(Expr { - temp_lifetime, + temp_scope_id, ty: new_pin_target, span, kind: ExprKind::Borrow { borrow_kind, arg }, @@ -242,7 +242,7 @@ impl<'tcx> ThirBuildCx<'tcx> { } }; - Expr { temp_lifetime, ty: adjustment.target, span, kind } + Expr { temp_scope_id, ty: adjustment.target, span, kind } } /// Lowers a cast expression. @@ -251,7 +251,7 @@ impl<'tcx> ThirBuildCx<'tcx> { fn mirror_expr_cast( &mut self, source: &'tcx hir::Expr<'tcx>, - temp_lifetime: TempLifetime, + temp_scope_id: hir::ItemLocalId, span: Span, ) -> ExprKind<'tcx> { let tcx = self.tcx; @@ -309,7 +309,7 @@ impl<'tcx> ThirBuildCx<'tcx> { ); } let kind = ExprKind::NonHirLiteral { lit, user_ty: None }; - let offset = self.thir.exprs.push(Expr { temp_lifetime, ty: discr_ty, span, kind }); + let offset = self.thir.exprs.push(Expr { temp_scope_id, ty: discr_ty, span, kind }); let source = match discr_did { // in case we are offsetting from a computed discriminant @@ -317,9 +317,9 @@ impl<'tcx> ThirBuildCx<'tcx> { Some(did) => { let kind = ExprKind::NamedConst { def_id: did, args, user_ty: None }; let lhs = - self.thir.exprs.push(Expr { temp_lifetime, ty: discr_ty, span, kind }); + self.thir.exprs.push(Expr { temp_scope_id, ty: discr_ty, span, kind }); let bin = ExprKind::Binary { op: BinOp::Add, lhs, rhs: offset }; - self.thir.exprs.push(Expr { temp_lifetime, ty: discr_ty, span, kind: bin }) + self.thir.exprs.push(Expr { temp_scope_id, ty: discr_ty, span, kind: bin }) } None => offset, }; @@ -336,8 +336,6 @@ impl<'tcx> ThirBuildCx<'tcx> { fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx> { let tcx = self.tcx; let expr_ty = self.typeck_results.expr_ty(expr); - let (temp_lifetime, backwards_incompatible) = - self.region_scope_tree.temporary_scope(expr.hir_id.local_id); let kind = match expr.kind { // Here comes the interesting stuff: @@ -372,7 +370,7 @@ impl<'tcx> ThirBuildCx<'tcx> { let arg_tys = args.iter().map(|e| self.typeck_results.expr_ty_adjusted(e)); let tupled_args = Expr { ty: Ty::new_tup_from_iter(tcx, arg_tys), - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, + temp_scope_id: expr.hir_id.local_id, span: expr.span, kind: ExprKind::Tuple { fields: self.mirror_exprs(args) }, }; @@ -398,7 +396,7 @@ impl<'tcx> ThirBuildCx<'tcx> { } let value = &args[0]; return Expr { - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, + temp_scope_id: expr.hir_id.local_id, ty: expr_ty, span: expr.span, kind: ExprKind::Box { value: self.mirror_expr(value) }, @@ -502,17 +500,15 @@ impl<'tcx> ThirBuildCx<'tcx> { expr: Some(arg), safety_mode: BlockSafety::Safe, }); - let (temp_lifetime, backwards_incompatible) = - self.region_scope_tree.temporary_scope(arg_expr.hir_id.local_id); arg = self.thir.exprs.push(Expr { - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, + temp_scope_id: arg_expr.hir_id.local_id, ty: arg_ty, span: arg_expr.span, kind: ExprKind::Block { block }, }); } let expr = self.thir.exprs.push(Expr { - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, + temp_scope_id: expr.hir_id.local_id, ty, span: expr.span, kind: ExprKind::Borrow { borrow_kind: mutbl.to_borrow_kind(), arg }, @@ -995,12 +991,10 @@ impl<'tcx> ThirBuildCx<'tcx> { } } else { let block_ty = self.typeck_results.node_type(body.hir_id); - let (temp_lifetime, backwards_incompatible) = - self.region_scope_tree.temporary_scope(body.hir_id.local_id); let block = self.mirror_block(body); let body = self.thir.exprs.push(Expr { ty: block_ty, - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, + temp_scope_id: body.hir_id.local_id, span: self.thir[block].span, kind: ExprKind::Block { block }, }); @@ -1022,17 +1016,13 @@ impl<'tcx> ThirBuildCx<'tcx> { expr, cast_ty.hir_id, user_ty, ); - let cast = self.mirror_expr_cast( - source, - TempLifetime { temp_lifetime, backwards_incompatible }, - expr.span, - ); + let cast = self.mirror_expr_cast(source, expr.hir_id.local_id, expr.span); if let Some(user_ty) = user_ty { // NOTE: Creating a new Expr and wrapping a Cast inside of it may be // inefficient, revisit this when performance becomes an issue. let cast_expr = self.thir.exprs.push(Expr { - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, + temp_scope_id: expr.hir_id.local_id, ty: expr_ty, span: expr.span, kind: cast, @@ -1091,12 +1081,7 @@ impl<'tcx> ThirBuildCx<'tcx> { hir::ExprKind::Err(_) => unreachable!("cannot lower a `hir::ExprKind::Err` to THIR"), }; - Expr { - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, - ty: expr_ty, - span: expr.span, - kind, - } + Expr { temp_scope_id: expr.hir_id.local_id, ty: expr_ty, span: expr.span, kind } } fn user_args_applied_to_res( @@ -1140,8 +1125,6 @@ impl<'tcx> ThirBuildCx<'tcx> { span: Span, overloaded_callee: Option>, ) -> Expr<'tcx> { - let (temp_lifetime, backwards_incompatible) = - self.region_scope_tree.temporary_scope(expr.hir_id.local_id); let (ty, user_ty) = match overloaded_callee { Some(fn_def) => (fn_def, None), None => { @@ -1158,7 +1141,7 @@ impl<'tcx> ThirBuildCx<'tcx> { } }; Expr { - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, + temp_scope_id: expr.hir_id.local_id, ty, span, kind: ExprKind::ZstLiteral { user_ty }, @@ -1235,8 +1218,6 @@ impl<'tcx> ThirBuildCx<'tcx> { Res::Def(DefKind::Static { .. }, id) => { // this is &raw for extern static or static mut, and & for other statics let ty = self.tcx.static_ptr_ty(id, self.typing_env); - let (temp_lifetime, backwards_incompatible) = - self.region_scope_tree.temporary_scope(expr.hir_id.local_id); let kind = if self.tcx.is_thread_local_static(id) { ExprKind::ThreadLocalRef(id) } else { @@ -1246,7 +1227,7 @@ impl<'tcx> ThirBuildCx<'tcx> { ExprKind::Deref { arg: self.thir.exprs.push(Expr { ty, - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, + temp_scope_id: expr.hir_id.local_id, span: expr.span, kind, }), @@ -1317,13 +1298,11 @@ impl<'tcx> ThirBuildCx<'tcx> { // construct the complete expression `foo()` for the overloaded call, // which will yield the &T type - let (temp_lifetime, backwards_incompatible) = - self.region_scope_tree.temporary_scope(expr.hir_id.local_id); let fun = self.method_callee(expr, span, overloaded_callee); let fun = self.thir.exprs.push(fun); let fun_ty = self.thir[fun].ty; let ref_expr = self.thir.exprs.push(Expr { - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, + temp_scope_id: expr.hir_id.local_id, ty: ref_ty, span, kind: ExprKind::Call { ty: fun_ty, fun, args, from_hir_call: false, fn_span: span }, @@ -1338,8 +1317,7 @@ impl<'tcx> ThirBuildCx<'tcx> { closure_expr: &'tcx hir::Expr<'tcx>, place: HirPlace<'tcx>, ) -> Expr<'tcx> { - let (temp_lifetime, backwards_incompatible) = - self.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id); + let temp_scope_id = closure_expr.hir_id.local_id; let var_ty = place.base_ty; // The result of capture analysis in `rustc_hir_typeck/src/upvar.rs` represents a captured path @@ -1353,7 +1331,7 @@ impl<'tcx> ThirBuildCx<'tcx> { }; let mut captured_place_expr = Expr { - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, + temp_scope_id, ty: var_ty, span: closure_expr.span, kind: self.convert_var(var_hir_id), @@ -1381,12 +1359,8 @@ impl<'tcx> ThirBuildCx<'tcx> { } }; - captured_place_expr = Expr { - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, - ty: proj.ty, - span: closure_expr.span, - kind, - }; + captured_place_expr = + Expr { temp_scope_id, ty: proj.ty, span: closure_expr.span, kind }; } captured_place_expr @@ -1401,8 +1375,7 @@ impl<'tcx> ThirBuildCx<'tcx> { let upvar_capture = captured_place.info.capture_kind; let captured_place_expr = self.convert_captured_hir_place(closure_expr, captured_place.place.clone()); - let (temp_lifetime, backwards_incompatible) = - self.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id); + let temp_scope_id = closure_expr.hir_id.local_id; match upvar_capture { ty::UpvarCapture::ByValue => captured_place_expr, @@ -1411,7 +1384,7 @@ impl<'tcx> ThirBuildCx<'tcx> { let expr_id = self.thir.exprs.push(captured_place_expr); Expr { - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, + temp_scope_id, ty: upvar_ty, span: closure_expr.span, kind: ExprKind::ByUse { expr: expr_id, span }, @@ -1428,7 +1401,7 @@ impl<'tcx> ThirBuildCx<'tcx> { } }; Expr { - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, + temp_scope_id, ty: upvar_ty, span: closure_expr.span, kind: ExprKind::Borrow { diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index 65b05a0e6a985..d26dfac0c2abd 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -10,7 +10,6 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::lang_items::LangItem; use rustc_hir::{self as hir, HirId, find_attr}; use rustc_middle::bug; -use rustc_middle::middle::region; use rustc_middle::thir::*; use rustc_middle::ty::{self, TyCtxt}; use tracing::instrument; @@ -60,7 +59,6 @@ struct ThirBuildCx<'tcx> { typing_env: ty::TypingEnv<'tcx>, - region_scope_tree: &'tcx region::ScopeTree, typeck_results: &'tcx ty::TypeckResults<'tcx>, /// False to indicate that adjustments should not be applied. Only used for `custom_mir` @@ -106,7 +104,6 @@ impl<'tcx> ThirBuildCx<'tcx> { // FIXME(#132279): We're in a body, we should use a typing // mode which reveals the opaque types defined by that body. typing_env: ty::TypingEnv::non_body_analysis(tcx, def), - region_scope_tree: tcx.region_scope_tree(def), typeck_results, body_owner: def.to_def_id(), apply_adjustments: diff --git a/compiler/rustc_mir_build/src/thir/print.rs b/compiler/rustc_mir_build/src/thir/print.rs index e0a5c18a2eedb..655cd5f5dc954 100644 --- a/compiler/rustc_mir_build/src/thir/print.rs +++ b/compiler/rustc_mir_build/src/thir/print.rs @@ -183,10 +183,10 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> { } fn print_expr(&mut self, expr: ExprId, depth_lvl: usize) { - let Expr { ty, temp_lifetime, span, kind } = &self.thir[expr]; + let Expr { ty, temp_scope_id, span, kind } = &self.thir[expr]; print_indented!(self, "Expr {", depth_lvl); print_indented!(self, format!("ty: {:?}", ty), depth_lvl + 1); - print_indented!(self, format!("temp_lifetime: {:?}", temp_lifetime), depth_lvl + 1); + print_indented!(self, format!("temp_scope_id: {:?}", temp_scope_id), depth_lvl + 1); print_indented!(self, format!("span: {:?}", span), depth_lvl + 1); print_indented!(self, "kind: ", depth_lvl + 1); self.print_expr_kind(kind, depth_lvl + 2); diff --git a/tests/ui/thir-print/c-variadic.stdout b/tests/ui/thir-print/c-variadic.stdout index 8363f06ebe887..abf726b3eb4ec 100644 --- a/tests/ui/thir-print/c-variadic.stdout +++ b/tests/ui/thir-print/c-variadic.stdout @@ -34,7 +34,7 @@ params: [ body: Expr { ty: () - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(6)), backwards_incompatible: None } + temp_scope_id: 6 span: $DIR/c-variadic.rs:6:39: 6:41 (#0) kind: Scope { @@ -43,7 +43,7 @@ body: value: Expr { ty: () - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(6)), backwards_incompatible: None } + temp_scope_id: 6 span: $DIR/c-variadic.rs:6:39: 6:41 (#0) kind: Block { diff --git a/tests/ui/thir-print/thir-flat-const-variant.stdout b/tests/ui/thir-print/thir-flat-const-variant.stdout index 5588cfdfa5ce0..750a47a7141cb 100644 --- a/tests/ui/thir-print/thir-flat-const-variant.stdout +++ b/tests/ui/thir-print/thir-flat-const-variant.stdout @@ -11,12 +11,7 @@ Thir { fields: [], }, ty: (), - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 7, span: $DIR/thir-flat-const-variant.rs:12:32: 12:34 (#0), }, Expr { @@ -28,12 +23,7 @@ Thir { value: e0, }, ty: (), - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 7, span: $DIR/thir-flat-const-variant.rs:12:32: 12:34 (#0), }, Expr { @@ -53,12 +43,7 @@ Thir { }, ), ty: Foo, - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 3, span: $DIR/thir-flat-const-variant.rs:12:23: 12:35 (#0), }, Expr { @@ -70,12 +55,7 @@ Thir { value: e2, }, ty: Foo, - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 3, span: $DIR/thir-flat-const-variant.rs:12:23: 12:35 (#0), }, ], @@ -96,12 +76,7 @@ Thir { fields: [], }, ty: (), - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 8, span: $DIR/thir-flat-const-variant.rs:13:33: 13:35 (#0), }, Expr { @@ -113,12 +88,7 @@ Thir { value: e0, }, ty: (), - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 8, span: $DIR/thir-flat-const-variant.rs:13:33: 13:35 (#0), }, Expr { @@ -138,12 +108,7 @@ Thir { }, ), ty: Foo, - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 3, span: $DIR/thir-flat-const-variant.rs:13:23: 13:36 (#0), }, Expr { @@ -155,12 +120,7 @@ Thir { value: e2, }, ty: Foo, - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 3, span: $DIR/thir-flat-const-variant.rs:13:23: 13:36 (#0), }, ], @@ -181,12 +141,7 @@ Thir { fields: [], }, ty: (), - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 7, span: $DIR/thir-flat-const-variant.rs:14:33: 14:35 (#0), }, Expr { @@ -198,12 +153,7 @@ Thir { value: e0, }, ty: (), - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 7, span: $DIR/thir-flat-const-variant.rs:14:33: 14:35 (#0), }, Expr { @@ -223,12 +173,7 @@ Thir { }, ), ty: Foo, - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 3, span: $DIR/thir-flat-const-variant.rs:14:24: 14:36 (#0), }, Expr { @@ -240,12 +185,7 @@ Thir { value: e2, }, ty: Foo, - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 3, span: $DIR/thir-flat-const-variant.rs:14:24: 14:36 (#0), }, ], @@ -266,12 +206,7 @@ Thir { fields: [], }, ty: (), - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 8, span: $DIR/thir-flat-const-variant.rs:15:34: 15:36 (#0), }, Expr { @@ -283,12 +218,7 @@ Thir { value: e0, }, ty: (), - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 8, span: $DIR/thir-flat-const-variant.rs:15:34: 15:36 (#0), }, Expr { @@ -308,12 +238,7 @@ Thir { }, ), ty: Foo, - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 3, span: $DIR/thir-flat-const-variant.rs:15:24: 15:37 (#0), }, Expr { @@ -325,12 +250,7 @@ Thir { value: e2, }, ty: Foo, - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(3), - ), - backwards_incompatible: None, - }, + temp_scope_id: 3, span: $DIR/thir-flat-const-variant.rs:15:24: 15:37 (#0), }, ], @@ -360,12 +280,7 @@ Thir { block: b0, }, ty: (), - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(2), - ), - backwards_incompatible: None, - }, + temp_scope_id: 2, span: $DIR/thir-flat-const-variant.rs:18:11: 18:13 (#0), }, Expr { @@ -377,12 +292,7 @@ Thir { value: e0, }, ty: (), - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(2), - ), - backwards_incompatible: None, - }, + temp_scope_id: 2, span: $DIR/thir-flat-const-variant.rs:18:11: 18:13 (#0), }, ], diff --git a/tests/ui/thir-print/thir-flat.stdout b/tests/ui/thir-print/thir-flat.stdout index 59cecfe511c24..f01d64e60b3d6 100644 --- a/tests/ui/thir-print/thir-flat.stdout +++ b/tests/ui/thir-print/thir-flat.stdout @@ -20,12 +20,7 @@ Thir { block: b0, }, ty: (), - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(2), - ), - backwards_incompatible: None, - }, + temp_scope_id: 2, span: $DIR/thir-flat.rs:4:15: 4:17 (#0), }, Expr { @@ -37,12 +32,7 @@ Thir { value: e0, }, ty: (), - temp_lifetime: TempLifetime { - temp_lifetime: Some( - Node(2), - ), - backwards_incompatible: None, - }, + temp_scope_id: 2, span: $DIR/thir-flat.rs:4:15: 4:17 (#0), }, ], diff --git a/tests/ui/thir-print/thir-tree-loop-match.stdout b/tests/ui/thir-print/thir-tree-loop-match.stdout index c9117c3048b03..5f6b130c39055 100644 --- a/tests/ui/thir-print/thir-tree-loop-match.stdout +++ b/tests/ui/thir-print/thir-tree-loop-match.stdout @@ -27,7 +27,7 @@ params: [ body: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None } + temp_scope_id: 28 span: $DIR/thir-tree-loop-match.rs:7:37: 20:2 (#0) kind: Scope { @@ -36,7 +36,7 @@ body: value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None } + temp_scope_id: 28 span: $DIR/thir-tree-loop-match.rs:7:37: 20:2 (#0) kind: Block { @@ -48,7 +48,7 @@ body: expr: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None } + temp_scope_id: 4 span: $DIR/thir-tree-loop-match.rs:9:5: 19:6 (#0) kind: Scope { @@ -57,21 +57,21 @@ body: value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None } + temp_scope_id: 4 span: $DIR/thir-tree-loop-match.rs:9:5: 19:6 (#0) kind: NeverToAny { source: Expr { ty: ! - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None } + temp_scope_id: 4 span: $DIR/thir-tree-loop-match.rs:9:5: 19:6 (#0) kind: LoopMatch { state: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(5)), backwards_incompatible: None } + temp_scope_id: 7 span: $DIR/thir-tree-loop-match.rs:10:9: 10:14 (#0) kind: Scope { @@ -80,7 +80,7 @@ body: value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(5)), backwards_incompatible: None } + temp_scope_id: 7 span: $DIR/thir-tree-loop-match.rs:10:9: 10:14 (#0) kind: VarRef { @@ -96,7 +96,7 @@ body: scrutinee: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(5)), backwards_incompatible: None } + temp_scope_id: 12 span: $DIR/thir-tree-loop-match.rs:11:19: 11:24 (#0) kind: Scope { @@ -105,7 +105,7 @@ body: value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(5)), backwards_incompatible: None } + temp_scope_id: 12 span: $DIR/thir-tree-loop-match.rs:11:19: 11:24 (#0) kind: VarRef { @@ -130,7 +130,7 @@ body: body: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(16)), backwards_incompatible: None } + temp_scope_id: 17 span: $DIR/thir-tree-loop-match.rs:12:25: 15:18 (#0) kind: Scope { @@ -139,14 +139,14 @@ body: value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(16)), backwards_incompatible: None } + temp_scope_id: 17 span: $DIR/thir-tree-loop-match.rs:12:25: 15:18 (#0) kind: NeverToAny { source: Expr { ty: ! - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(16)), backwards_incompatible: None } + temp_scope_id: 17 span: $DIR/thir-tree-loop-match.rs:12:25: 15:18 (#0) kind: Block { @@ -161,7 +161,7 @@ body: expr: Expr { ty: ! - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(21)), backwards_incompatible: None } + temp_scope_id: 19 span: $DIR/thir-tree-loop-match.rs:14:21: 14:37 (#0) kind: Scope { @@ -170,7 +170,7 @@ body: value: Expr { ty: ! - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(21)), backwards_incompatible: None } + temp_scope_id: 19 span: $DIR/thir-tree-loop-match.rs:14:21: 14:37 (#0) kind: ConstContinue ( @@ -178,7 +178,7 @@ body: value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(21)), backwards_incompatible: None } + temp_scope_id: 20 span: $DIR/thir-tree-loop-match.rs:14:32: 14:37 (#0) kind: Scope { @@ -187,7 +187,7 @@ body: value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(21)), backwards_incompatible: None } + temp_scope_id: 20 span: $DIR/thir-tree-loop-match.rs:14:32: 14:37 (#0) kind: Literal( lit: Spanned { node: Bool(false), span: $DIR/thir-tree-loop-match.rs:14:32: 14:37 (#0) }, neg: false) @@ -228,7 +228,7 @@ body: body: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(24)), backwards_incompatible: None } + temp_scope_id: 25 span: $DIR/thir-tree-loop-match.rs:16:26: 16:38 (#0) kind: Scope { @@ -237,21 +237,21 @@ body: value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(24)), backwards_incompatible: None } + temp_scope_id: 25 span: $DIR/thir-tree-loop-match.rs:16:26: 16:38 (#0) kind: NeverToAny { source: Expr { ty: ! - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(24)), backwards_incompatible: None } + temp_scope_id: 25 span: $DIR/thir-tree-loop-match.rs:16:26: 16:38 (#0) kind: Return { value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(24)), backwards_incompatible: None } + temp_scope_id: 26 span: $DIR/thir-tree-loop-match.rs:16:33: 16:38 (#0) kind: Scope { @@ -260,7 +260,7 @@ body: value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(24)), backwards_incompatible: None } + temp_scope_id: 26 span: $DIR/thir-tree-loop-match.rs:16:33: 16:38 (#0) kind: VarRef { @@ -299,7 +299,7 @@ params: [ body: Expr { ty: () - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(2)), backwards_incompatible: None } + temp_scope_id: 2 span: $DIR/thir-tree-loop-match.rs:22:11: 22:13 (#0) kind: Scope { @@ -308,7 +308,7 @@ body: value: Expr { ty: () - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(2)), backwards_incompatible: None } + temp_scope_id: 2 span: $DIR/thir-tree-loop-match.rs:22:11: 22:13 (#0) kind: Block { diff --git a/tests/ui/thir-print/thir-tree-match.stdout b/tests/ui/thir-print/thir-tree-match.stdout index fde5003176679..8a2bad56c126a 100644 --- a/tests/ui/thir-print/thir-tree-match.stdout +++ b/tests/ui/thir-print/thir-tree-match.stdout @@ -27,7 +27,7 @@ params: [ body: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None } + temp_scope_id: 28 span: $DIR/thir-tree-match.rs:15:32: 21:2 (#0) kind: Scope { @@ -36,7 +36,7 @@ body: value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None } + temp_scope_id: 28 span: $DIR/thir-tree-match.rs:15:32: 21:2 (#0) kind: Block { @@ -48,7 +48,7 @@ body: expr: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None } + temp_scope_id: 4 span: $DIR/thir-tree-match.rs:16:5: 20:6 (#0) kind: Scope { @@ -57,14 +57,14 @@ body: value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None } + temp_scope_id: 4 span: $DIR/thir-tree-match.rs:16:5: 20:6 (#0) kind: Match { scrutinee: Expr { ty: Foo - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None } + temp_scope_id: 5 span: $DIR/thir-tree-match.rs:16:11: 16:14 (#0) kind: Scope { @@ -73,7 +73,7 @@ body: value: Expr { ty: Foo - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None } + temp_scope_id: 5 span: $DIR/thir-tree-match.rs:16:11: 16:14 (#0) kind: VarRef { @@ -124,7 +124,7 @@ body: body: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(14)), backwards_incompatible: None } + temp_scope_id: 15 span: $DIR/thir-tree-match.rs:17:36: 17:40 (#0) kind: Scope { @@ -133,7 +133,7 @@ body: value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(14)), backwards_incompatible: None } + temp_scope_id: 15 span: $DIR/thir-tree-match.rs:17:36: 17:40 (#0) kind: Literal( lit: Spanned { node: Bool(true), span: $DIR/thir-tree-match.rs:17:36: 17:40 (#0) }, neg: false) @@ -176,7 +176,7 @@ body: body: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(20)), backwards_incompatible: None } + temp_scope_id: 21 span: $DIR/thir-tree-match.rs:18:27: 18:32 (#0) kind: Scope { @@ -185,7 +185,7 @@ body: value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(20)), backwards_incompatible: None } + temp_scope_id: 21 span: $DIR/thir-tree-match.rs:18:27: 18:32 (#0) kind: Literal( lit: Spanned { node: Bool(false), span: $DIR/thir-tree-match.rs:18:27: 18:32 (#0) }, neg: false) @@ -220,7 +220,7 @@ body: body: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(26)), backwards_incompatible: None } + temp_scope_id: 27 span: $DIR/thir-tree-match.rs:19:24: 19:28 (#0) kind: Scope { @@ -229,7 +229,7 @@ body: value: Expr { ty: bool - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(26)), backwards_incompatible: None } + temp_scope_id: 27 span: $DIR/thir-tree-match.rs:19:24: 19:28 (#0) kind: Literal( lit: Spanned { node: Bool(true), span: $DIR/thir-tree-match.rs:19:24: 19:28 (#0) }, neg: false) @@ -258,7 +258,7 @@ params: [ body: Expr { ty: () - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(2)), backwards_incompatible: None } + temp_scope_id: 2 span: $DIR/thir-tree-match.rs:23:11: 23:13 (#0) kind: Scope { @@ -267,7 +267,7 @@ body: value: Expr { ty: () - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(2)), backwards_incompatible: None } + temp_scope_id: 2 span: $DIR/thir-tree-match.rs:23:11: 23:13 (#0) kind: Block { diff --git a/tests/ui/thir-print/thir-tree.stdout b/tests/ui/thir-print/thir-tree.stdout index b39581ad84151..d61176d6480fe 100644 --- a/tests/ui/thir-print/thir-tree.stdout +++ b/tests/ui/thir-print/thir-tree.stdout @@ -4,7 +4,7 @@ params: [ body: Expr { ty: () - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(2)), backwards_incompatible: None } + temp_scope_id: 2 span: $DIR/thir-tree.rs:4:15: 4:17 (#0) kind: Scope { @@ -13,7 +13,7 @@ body: value: Expr { ty: () - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(2)), backwards_incompatible: None } + temp_scope_id: 2 span: $DIR/thir-tree.rs:4:15: 4:17 (#0) kind: Block { diff --git a/tests/ui/unpretty/box.stdout b/tests/ui/unpretty/box.stdout index 92155d0c73b9d..54bd98c7a6834 100644 --- a/tests/ui/unpretty/box.stdout +++ b/tests/ui/unpretty/box.stdout @@ -4,7 +4,7 @@ params: [ body: Expr { ty: () - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(11)), backwards_incompatible: None } + temp_scope_id: 11 span: $DIR/box.rs:6:11: 8:2 (#0) kind: Scope { @@ -13,7 +13,7 @@ body: value: Expr { ty: () - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(11)), backwards_incompatible: None } + temp_scope_id: 11 span: $DIR/box.rs:6:11: 8:2 (#0) kind: Block { @@ -38,7 +38,7 @@ body: initializer: Some( Expr { ty: std::boxed::Box - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(2)), backwards_incompatible: None } + temp_scope_id: 3 span: $DIR/box.rs:7:13: 7:35 (#0) kind: Scope { @@ -47,13 +47,13 @@ body: value: Expr { ty: std::boxed::Box - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(2)), backwards_incompatible: None } + temp_scope_id: 3 span: $DIR/box.rs:7:13: 7:35 (#0) kind: Box { Expr { ty: i32 - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(2)), backwards_incompatible: None } + temp_scope_id: 8 span: $DIR/box.rs:7:33: 7:34 (#0) kind: Scope { @@ -62,7 +62,7 @@ body: value: Expr { ty: i32 - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(2)), backwards_incompatible: None } + temp_scope_id: 8 span: $DIR/box.rs:7:33: 7:34 (#0) kind: Literal( lit: Spanned { node: Int(Pu128(1), Unsuffixed), span: $DIR/box.rs:7:33: 7:34 (#0) }, neg: false)