Remove ScopeDepth from var_parent.
It was never used.
This commit is contained in:
parent
0ad0142a5b
commit
2cc3fa32ef
1 changed files with 16 additions and 10 deletions
|
@ -25,12 +25,18 @@ use tracing::debug;
|
||||||
struct Context {
|
struct Context {
|
||||||
/// The scope that contains any new variables declared, plus its depth in
|
/// The scope that contains any new variables declared, plus its depth in
|
||||||
/// the scope tree.
|
/// the scope tree.
|
||||||
var_parent: Option<(Scope, ScopeDepth)>,
|
var_parent: Option<Scope>,
|
||||||
|
|
||||||
/// Region parent of expressions, etc., plus its depth in the scope tree.
|
/// Region parent of expressions, etc., plus its depth in the scope tree.
|
||||||
parent: Option<(Scope, ScopeDepth)>,
|
parent: Option<(Scope, ScopeDepth)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Context {
|
||||||
|
fn set_var_parent(&mut self) {
|
||||||
|
self.var_parent = self.parent.map(|(p, _)| p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct ScopeResolutionVisitor<'tcx> {
|
struct ScopeResolutionVisitor<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
|
||||||
|
@ -78,7 +84,7 @@ fn record_var_lifetime(visitor: &mut ScopeResolutionVisitor<'_>, var_id: hir::It
|
||||||
//
|
//
|
||||||
// extern fn isalnum(c: c_int) -> c_int
|
// extern fn isalnum(c: c_int) -> c_int
|
||||||
}
|
}
|
||||||
Some((parent_scope, _)) => visitor.scope_tree.record_var_scope(var_id, parent_scope),
|
Some(parent_scope) => visitor.scope_tree.record_var_scope(var_id, parent_scope),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +119,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
|
||||||
// itself has returned.
|
// itself has returned.
|
||||||
|
|
||||||
visitor.enter_node_scope_with_dtor(blk.hir_id.local_id);
|
visitor.enter_node_scope_with_dtor(blk.hir_id.local_id);
|
||||||
visitor.cx.var_parent = visitor.cx.parent;
|
visitor.cx.set_var_parent();
|
||||||
|
|
||||||
{
|
{
|
||||||
// This block should be kept approximately in sync with
|
// This block should be kept approximately in sync with
|
||||||
|
@ -132,7 +138,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
|
||||||
local_id: blk.hir_id.local_id,
|
local_id: blk.hir_id.local_id,
|
||||||
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
|
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
|
||||||
});
|
});
|
||||||
visitor.cx.var_parent = visitor.cx.parent;
|
visitor.cx.set_var_parent();
|
||||||
visitor.visit_stmt(statement);
|
visitor.visit_stmt(statement);
|
||||||
// We need to back out temporarily to the last enclosing scope
|
// We need to back out temporarily to the last enclosing scope
|
||||||
// for the `else` block, so that even the temporaries receiving
|
// for the `else` block, so that even the temporaries receiving
|
||||||
|
@ -157,7 +163,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
|
||||||
local_id: blk.hir_id.local_id,
|
local_id: blk.hir_id.local_id,
|
||||||
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
|
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
|
||||||
});
|
});
|
||||||
visitor.cx.var_parent = visitor.cx.parent;
|
visitor.cx.set_var_parent();
|
||||||
visitor.visit_stmt(statement)
|
visitor.visit_stmt(statement)
|
||||||
}
|
}
|
||||||
hir::StmtKind::Item(..) => {
|
hir::StmtKind::Item(..) => {
|
||||||
|
@ -207,7 +213,7 @@ fn resolve_arm<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, arm: &'tcx hir:
|
||||||
visitor.terminating_scopes.insert(arm.hir_id.local_id);
|
visitor.terminating_scopes.insert(arm.hir_id.local_id);
|
||||||
|
|
||||||
visitor.enter_node_scope_with_dtor(arm.hir_id.local_id);
|
visitor.enter_node_scope_with_dtor(arm.hir_id.local_id);
|
||||||
visitor.cx.var_parent = visitor.cx.parent;
|
visitor.cx.set_var_parent();
|
||||||
|
|
||||||
if let Some(expr) = arm.guard
|
if let Some(expr) = arm.guard
|
||||||
&& !has_let_expr(expr)
|
&& !has_let_expr(expr)
|
||||||
|
@ -484,7 +490,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
|
||||||
ScopeData::IfThen
|
ScopeData::IfThen
|
||||||
};
|
};
|
||||||
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
|
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
|
||||||
visitor.cx.var_parent = visitor.cx.parent;
|
visitor.cx.set_var_parent();
|
||||||
visitor.visit_expr(cond);
|
visitor.visit_expr(cond);
|
||||||
visitor.visit_expr(then);
|
visitor.visit_expr(then);
|
||||||
visitor.cx = expr_cx;
|
visitor.cx = expr_cx;
|
||||||
|
@ -499,7 +505,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
|
||||||
ScopeData::IfThen
|
ScopeData::IfThen
|
||||||
};
|
};
|
||||||
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
|
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
|
||||||
visitor.cx.var_parent = visitor.cx.parent;
|
visitor.cx.set_var_parent();
|
||||||
visitor.visit_expr(cond);
|
visitor.visit_expr(cond);
|
||||||
visitor.visit_expr(then);
|
visitor.visit_expr(then);
|
||||||
visitor.cx = expr_cx;
|
visitor.cx = expr_cx;
|
||||||
|
@ -558,7 +564,7 @@ fn resolve_local<'tcx>(
|
||||||
) {
|
) {
|
||||||
debug!("resolve_local(pat={:?}, init={:?})", pat, init);
|
debug!("resolve_local(pat={:?}, init={:?})", pat, init);
|
||||||
|
|
||||||
let blk_scope = visitor.cx.var_parent.map(|(p, _)| p);
|
let blk_scope = visitor.cx.var_parent;
|
||||||
|
|
||||||
// As an exception to the normal rules governing temporary
|
// As an exception to the normal rules governing temporary
|
||||||
// lifetimes, initializers in a let have a temporary lifetime
|
// lifetimes, initializers in a let have a temporary lifetime
|
||||||
|
@ -849,7 +855,7 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> {
|
||||||
self.enter_body(body.value.hir_id, |this| {
|
self.enter_body(body.value.hir_id, |this| {
|
||||||
if this.tcx.hir_body_owner_kind(owner_id).is_fn_or_closure() {
|
if this.tcx.hir_body_owner_kind(owner_id).is_fn_or_closure() {
|
||||||
// The arguments and `self` are parented to the fn.
|
// The arguments and `self` are parented to the fn.
|
||||||
this.cx.var_parent = this.cx.parent;
|
this.cx.set_var_parent();
|
||||||
for param in body.params {
|
for param in body.params {
|
||||||
this.visit_pat(param.pat);
|
this.visit_pat(param.pat);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue