factor out the rvalue lifetime rule
remove region_scope_tree from RegionCtxt Apply suggestions from code review Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
This commit is contained in:
parent
bb5e6c984d
commit
6044fbe462
25 changed files with 363 additions and 192 deletions
|
@ -108,7 +108,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let_scope_stack.push(remainder_scope);
|
||||
|
||||
// Declare the bindings, which may create a source scope.
|
||||
let remainder_span = remainder_scope.span(this.tcx, this.region_scope_tree);
|
||||
let remainder_span =
|
||||
remainder_scope.span(this.tcx, &this.typeck_results.region_scope_tree);
|
||||
|
||||
let visibility_scope =
|
||||
Some(this.new_source_scope(remainder_span, LintLevel::Inherited, None));
|
||||
|
|
|
@ -699,7 +699,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
self.cfg.push(block, Statement { source_info, kind: StatementKind::StorageLive(local_id) });
|
||||
// Altough there is almost always scope for given variable in corner cases
|
||||
// like #92893 we might get variable with no scope.
|
||||
if let Some(region_scope) = self.region_scope_tree.var_scope(var.local_id) && schedule_drop{
|
||||
if let Some(region_scope) = self.typeck_results.region_scope_tree.var_scope(var.local_id) && schedule_drop{
|
||||
self.schedule_drop(span, region_scope, local_id, DropKind::Storage);
|
||||
}
|
||||
Place::from(local_id)
|
||||
|
@ -712,7 +712,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
for_guard: ForGuard,
|
||||
) {
|
||||
let local_id = self.var_local_id(var, for_guard);
|
||||
if let Some(region_scope) = self.region_scope_tree.var_scope(var.local_id) {
|
||||
if let Some(region_scope) = self.typeck_results.region_scope_tree.var_scope(var.local_id) {
|
||||
self.schedule_drop(span, region_scope, local_id, DropKind::Value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -398,7 +398,6 @@ struct Builder<'a, 'tcx> {
|
|||
tcx: TyCtxt<'tcx>,
|
||||
infcx: &'a InferCtxt<'a, 'tcx>,
|
||||
typeck_results: &'tcx TypeckResults<'tcx>,
|
||||
region_scope_tree: &'tcx region::ScopeTree,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
|
||||
thir: &'a Thir<'tcx>,
|
||||
|
@ -881,7 +880,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
tcx,
|
||||
infcx,
|
||||
typeck_results: tcx.typeck_opt_const_arg(def),
|
||||
region_scope_tree: tcx.region_scope_tree(def.did),
|
||||
param_env,
|
||||
def_id: def.did.to_def_id(),
|
||||
hir_id,
|
||||
|
|
|
@ -916,7 +916,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
}
|
||||
|
||||
if scope.region_scope == region_scope {
|
||||
let region_scope_span = region_scope.span(self.tcx, &self.region_scope_tree);
|
||||
let region_scope_span =
|
||||
region_scope.span(self.tcx, &self.typeck_results.region_scope_tree);
|
||||
// Attribute scope exit drops to scope's closing brace.
|
||||
let scope_end = self.tcx.sess.source_map().end_point(region_scope_span);
|
||||
|
||||
|
|
|
@ -32,7 +32,8 @@ impl<'tcx> Cx<'tcx> {
|
|||
}
|
||||
|
||||
pub(super) fn mirror_expr_inner(&mut self, hir_expr: &'tcx hir::Expr<'tcx>) -> ExprId {
|
||||
let temp_lifetime = self.region_scope_tree.temporary_scope(hir_expr.hir_id.local_id);
|
||||
let temp_lifetime =
|
||||
self.rvalue_scopes.temporary_scope(self.region_scope_tree, hir_expr.hir_id.local_id);
|
||||
let expr_scope =
|
||||
region::Scope { id: hir_expr.hir_id.local_id, data: region::ScopeData::Node };
|
||||
|
||||
|
@ -161,7 +162,8 @@ impl<'tcx> Cx<'tcx> {
|
|||
let tcx = self.tcx;
|
||||
let expr_ty = self.typeck_results().expr_ty(expr);
|
||||
let expr_span = expr.span;
|
||||
let temp_lifetime = self.region_scope_tree.temporary_scope(expr.hir_id.local_id);
|
||||
let temp_lifetime =
|
||||
self.rvalue_scopes.temporary_scope(self.region_scope_tree, expr.hir_id.local_id);
|
||||
|
||||
let kind = match expr.kind {
|
||||
// Here comes the interesting stuff:
|
||||
|
@ -575,7 +577,9 @@ impl<'tcx> Cx<'tcx> {
|
|||
},
|
||||
hir::ExprKind::Loop(ref body, ..) => {
|
||||
let block_ty = self.typeck_results().node_type(body.hir_id);
|
||||
let temp_lifetime = self.region_scope_tree.temporary_scope(body.hir_id.local_id);
|
||||
let temp_lifetime = self
|
||||
.rvalue_scopes
|
||||
.temporary_scope(self.region_scope_tree, body.hir_id.local_id);
|
||||
let block = self.mirror_block(body);
|
||||
let body = self.thir.exprs.push(Expr {
|
||||
ty: block_ty,
|
||||
|
@ -776,7 +780,8 @@ impl<'tcx> Cx<'tcx> {
|
|||
span: Span,
|
||||
overloaded_callee: Option<(DefId, SubstsRef<'tcx>)>,
|
||||
) -> Expr<'tcx> {
|
||||
let temp_lifetime = self.region_scope_tree.temporary_scope(expr.hir_id.local_id);
|
||||
let temp_lifetime =
|
||||
self.rvalue_scopes.temporary_scope(self.region_scope_tree, expr.hir_id.local_id);
|
||||
let (def_id, substs, user_ty) = match overloaded_callee {
|
||||
Some((def_id, substs)) => (def_id, substs, None),
|
||||
None => {
|
||||
|
@ -863,7 +868,9 @@ impl<'tcx> Cx<'tcx> {
|
|||
// a constant reference (or constant raw pointer for `static mut`) in MIR
|
||||
Res::Def(DefKind::Static(_), id) => {
|
||||
let ty = self.tcx.static_ptr_ty(id);
|
||||
let temp_lifetime = self.region_scope_tree.temporary_scope(expr.hir_id.local_id);
|
||||
let temp_lifetime = self
|
||||
.rvalue_scopes
|
||||
.temporary_scope(self.region_scope_tree, expr.hir_id.local_id);
|
||||
let kind = if self.tcx.is_thread_local_static(id) {
|
||||
ExprKind::ThreadLocalRef(id)
|
||||
} else {
|
||||
|
@ -939,7 +946,8 @@ impl<'tcx> Cx<'tcx> {
|
|||
|
||||
// construct the complete expression `foo()` for the overloaded call,
|
||||
// which will yield the &T type
|
||||
let temp_lifetime = self.region_scope_tree.temporary_scope(expr.hir_id.local_id);
|
||||
let temp_lifetime =
|
||||
self.rvalue_scopes.temporary_scope(self.region_scope_tree, 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;
|
||||
|
@ -959,7 +967,9 @@ impl<'tcx> Cx<'tcx> {
|
|||
closure_expr: &'tcx hir::Expr<'tcx>,
|
||||
place: HirPlace<'tcx>,
|
||||
) -> Expr<'tcx> {
|
||||
let temp_lifetime = self.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id);
|
||||
let temp_lifetime = self
|
||||
.rvalue_scopes
|
||||
.temporary_scope(self.region_scope_tree, closure_expr.hir_id.local_id);
|
||||
let var_ty = place.base_ty;
|
||||
|
||||
// The result of capture analysis in `rustc_typeck/check/upvar.rs`represents a captured path
|
||||
|
@ -1014,7 +1024,9 @@ impl<'tcx> Cx<'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 = self.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id);
|
||||
let temp_lifetime = self
|
||||
.rvalue_scopes
|
||||
.temporary_scope(self.region_scope_tree, closure_expr.hir_id.local_id);
|
||||
|
||||
match upvar_capture {
|
||||
ty::UpvarCapture::ByValue => captured_place_expr,
|
||||
|
|
|
@ -16,7 +16,7 @@ use rustc_middle::middle::region;
|
|||
use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput};
|
||||
use rustc_middle::mir::ConstantKind;
|
||||
use rustc_middle::thir::*;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, RvalueScopes, Ty, TyCtxt};
|
||||
use rustc_span::Span;
|
||||
|
||||
pub(crate) fn thir_body<'tcx>(
|
||||
|
@ -51,6 +51,7 @@ struct Cx<'tcx> {
|
|||
|
||||
pub(crate) region_scope_tree: &'tcx region::ScopeTree,
|
||||
pub(crate) typeck_results: &'tcx ty::TypeckResults<'tcx>,
|
||||
pub(crate) rvalue_scopes: &'tcx RvalueScopes,
|
||||
|
||||
/// When applying adjustments to the expression
|
||||
/// with the given `HirId`, use the given `Span`,
|
||||
|
@ -71,8 +72,9 @@ impl<'tcx> Cx<'tcx> {
|
|||
tcx,
|
||||
thir: Thir::new(),
|
||||
param_env: tcx.param_env(def.did),
|
||||
region_scope_tree: tcx.region_scope_tree(def.did),
|
||||
region_scope_tree: &typeck_results.region_scope_tree,
|
||||
typeck_results,
|
||||
rvalue_scopes: &typeck_results.rvalue_scopes,
|
||||
body_owner: def.did.to_def_id(),
|
||||
adjustment_span: None,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue