@@ -23,18 +23,11 @@ use tracing::debug;
2323
2424#[ derive( Debug ,  Copy ,  Clone ) ]  
2525struct  Context  { 
26-     /// The scope that contains any new variables declared, plus its depth in 
27- /// the scope tree. 
26+     /// The scope that contains any new variables declared. 
2827var_parent :  Option < Scope > , 
2928
30-     /// Region parent of expressions, etc., plus its depth in the scope tree. 
31- parent :  Option < ( Scope ,  ScopeDepth ) > , 
32- } 
33- 
34- impl  Context  { 
35-     fn  set_var_parent ( & mut  self )  { 
36-         self . var_parent  = self . parent . map ( |( p,  _) | p) ; 
37-     } 
29+     /// Region parent of expressions, etc. 
30+ parent :  Option < Scope > , 
3831} 
3932
4033struct  ScopeResolutionVisitor < ' tcx >  { 
@@ -119,7 +112,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
119112    // itself has returned. 
120113
121114    visitor. enter_node_scope_with_dtor ( blk. hir_id . local_id ) ; 
122-     visitor. cx . set_var_parent ( ) ; 
115+     visitor. cx . var_parent  = visitor . cx . parent ; 
123116
124117    { 
125118        // This block should be kept approximately in sync with 
@@ -138,7 +131,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
138131                        local_id :  blk. hir_id . local_id , 
139132                        data :  ScopeData :: Remainder ( FirstStatementIndex :: new ( i) ) , 
140133                    } ) ; 
141-                     visitor. cx . set_var_parent ( ) ; 
134+                     visitor. cx . var_parent  = visitor . cx . parent ; 
142135                    visitor. visit_stmt ( statement) ; 
143136                    // We need to back out temporarily to the last enclosing scope 
144137                    // for the `else` block, so that even the temporaries receiving 
@@ -163,7 +156,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
163156                        local_id :  blk. hir_id . local_id , 
164157                        data :  ScopeData :: Remainder ( FirstStatementIndex :: new ( i) ) , 
165158                    } ) ; 
166-                     visitor. cx . set_var_parent ( ) ; 
159+                     visitor. cx . var_parent  = visitor . cx . parent ; 
167160                    visitor. visit_stmt ( statement) 
168161                } 
169162                hir:: StmtKind :: Item ( ..)  => { 
@@ -213,7 +206,7 @@ fn resolve_arm<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, arm: &'tcx hir:
213206    visitor. terminating_scopes . insert ( arm. hir_id . local_id ) ; 
214207
215208    visitor. enter_node_scope_with_dtor ( arm. hir_id . local_id ) ; 
216-     visitor. cx . set_var_parent ( ) ; 
209+     visitor. cx . var_parent  = visitor . cx . parent ; 
217210
218211    if  let  Some ( expr)  = arm. guard 
219212        && !has_let_expr ( expr) 
@@ -490,7 +483,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
490483                ScopeData :: IfThen 
491484            } ; 
492485            visitor. enter_scope ( Scope  {  local_id :  then. hir_id . local_id ,  data } ) ; 
493-             visitor. cx . set_var_parent ( ) ; 
486+             visitor. cx . var_parent  = visitor . cx . parent ; 
494487            visitor. visit_expr ( cond) ; 
495488            visitor. visit_expr ( then) ; 
496489            visitor. cx  = expr_cx; 
@@ -505,7 +498,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
505498                ScopeData :: IfThen 
506499            } ; 
507500            visitor. enter_scope ( Scope  {  local_id :  then. hir_id . local_id ,  data } ) ; 
508-             visitor. cx . set_var_parent ( ) ; 
501+             visitor. cx . var_parent  = visitor . cx . parent ; 
509502            visitor. visit_expr ( cond) ; 
510503            visitor. visit_expr ( then) ; 
511504            visitor. cx  = expr_cx; 
@@ -545,7 +538,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
545538            // Keep traversing up while we can. 
546539            match  visitor. scope_tree . parent_map . get ( & scope)  { 
547540                // Don't cross from closure bodies to their parent. 
548-                 Some ( & ( superscope,  _ ) )  => match  superscope. data  { 
541+                 Some ( & superscope)  => match  superscope. data  { 
549542                    ScopeData :: CallSite  => break , 
550543                    _ => scope = superscope, 
551544                } , 
@@ -781,20 +774,16 @@ fn resolve_local<'tcx>(
781774
782775impl < ' tcx >  ScopeResolutionVisitor < ' tcx >  { 
783776    /// Records the current parent (if any) as the parent of `child_scope`. 
784- /// Returns the depth of `child_scope`. 
785- fn  record_child_scope ( & mut  self ,  child_scope :  Scope )  -> ScopeDepth  { 
777+ fn  record_child_scope ( & mut  self ,  child_scope :  Scope )  { 
786778        let  parent = self . cx . parent ; 
787779        self . scope_tree . record_scope_parent ( child_scope,  parent) ; 
788-         // If `child_scope` has no parent, it must be the root node, and so has 
789-         // a depth of 1. Otherwise, its depth is one more than its parent's. 
790-         parent. map_or ( 1 ,  |( _p,  d) | d + 1 ) 
791780    } 
792781
793782    /// Records the current parent (if any) as the parent of `child_scope`, 
794783/// and sets `child_scope` as the new current parent. 
795784fn  enter_scope ( & mut  self ,  child_scope :  Scope )  { 
796-         let  child_depth =  self . record_child_scope ( child_scope) ; 
797-         self . cx . parent  = Some ( ( child_scope,  child_depth ) ) ; 
785+         self . record_child_scope ( child_scope) ; 
786+         self . cx . parent  = Some ( child_scope) ; 
798787    } 
799788
800789    fn  enter_node_scope_with_dtor ( & mut  self ,  id :  hir:: ItemLocalId )  { 
@@ -855,7 +844,7 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> {
855844        self . enter_body ( body. value . hir_id ,  |this| { 
856845            if  this. tcx . hir_body_owner_kind ( owner_id) . is_fn_or_closure ( )  { 
857846                // The arguments and `self` are parented to the fn. 
858-                 this. cx . set_var_parent ( ) ; 
847+                 this. cx . var_parent  = this . cx . parent ; 
859848                for  param in  body. params  { 
860849                    this. visit_pat ( param. pat ) ; 
861850                } 
0 commit comments