@@ -31,7 +31,7 @@ struct Context {
3131 parent : Option < ( Scope , ScopeDepth ) > ,
3232}
3333
34- struct RegionResolutionVisitor < ' tcx > {
34+ struct ScopeResolutionVisitor < ' tcx > {
3535 tcx : TyCtxt < ' tcx > ,
3636
3737 // The number of expressions and patterns visited in the current body.
@@ -71,7 +71,7 @@ struct RegionResolutionVisitor<'tcx> {
7171}
7272
7373/// Records the lifetime of a local variable as `cx.var_parent`
74- fn record_var_lifetime ( visitor : & mut RegionResolutionVisitor < ' _ > , var_id : hir:: ItemLocalId ) {
74+ fn record_var_lifetime ( visitor : & mut ScopeResolutionVisitor < ' _ > , var_id : hir:: ItemLocalId ) {
7575 match visitor. cx . var_parent {
7676 None => {
7777 // this can happen in extern fn declarations like
@@ -82,7 +82,7 @@ fn record_var_lifetime(visitor: &mut RegionResolutionVisitor<'_>, var_id: hir::I
8282 }
8383}
8484
85- fn resolve_block < ' tcx > ( visitor : & mut RegionResolutionVisitor < ' tcx > , blk : & ' tcx hir:: Block < ' tcx > ) {
85+ fn resolve_block < ' tcx > ( visitor : & mut ScopeResolutionVisitor < ' tcx > , blk : & ' tcx hir:: Block < ' tcx > ) {
8686 debug ! ( "resolve_block(blk.hir_id={:?})" , blk. hir_id) ;
8787
8888 let prev_cx = visitor. cx ;
@@ -193,7 +193,7 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
193193 visitor. cx = prev_cx;
194194}
195195
196- fn resolve_arm < ' tcx > ( visitor : & mut RegionResolutionVisitor < ' tcx > , arm : & ' tcx hir:: Arm < ' tcx > ) {
196+ fn resolve_arm < ' tcx > ( visitor : & mut ScopeResolutionVisitor < ' tcx > , arm : & ' tcx hir:: Arm < ' tcx > ) {
197197 fn has_let_expr ( expr : & Expr < ' _ > ) -> bool {
198198 match & expr. kind {
199199 hir:: ExprKind :: Binary ( _, lhs, rhs) => has_let_expr ( lhs) || has_let_expr ( rhs) ,
@@ -220,7 +220,7 @@ fn resolve_arm<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, arm: &'tcx hir
220220 visitor. cx = prev_cx;
221221}
222222
223- fn resolve_pat < ' tcx > ( visitor : & mut RegionResolutionVisitor < ' tcx > , pat : & ' tcx hir:: Pat < ' tcx > ) {
223+ fn resolve_pat < ' tcx > ( visitor : & mut ScopeResolutionVisitor < ' tcx > , pat : & ' tcx hir:: Pat < ' tcx > ) {
224224 visitor. record_child_scope ( Scope { local_id : pat. hir_id . local_id , data : ScopeData :: Node } ) ;
225225
226226 // If this is a binding then record the lifetime of that binding.
@@ -237,7 +237,7 @@ fn resolve_pat<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, pat: &'tcx hir
237237 debug ! ( "resolve_pat - post-increment {} pat = {:?}" , visitor. expr_and_pat_count, pat) ;
238238}
239239
240- fn resolve_stmt < ' tcx > ( visitor : & mut RegionResolutionVisitor < ' tcx > , stmt : & ' tcx hir:: Stmt < ' tcx > ) {
240+ fn resolve_stmt < ' tcx > ( visitor : & mut ScopeResolutionVisitor < ' tcx > , stmt : & ' tcx hir:: Stmt < ' tcx > ) {
241241 let stmt_id = stmt. hir_id . local_id ;
242242 debug ! ( "resolve_stmt(stmt.id={:?})" , stmt_id) ;
243243
@@ -256,7 +256,7 @@ fn resolve_stmt<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, stmt: &'tcx h
256256 visitor. cx . parent = prev_parent;
257257}
258258
259- fn resolve_expr < ' tcx > ( visitor : & mut RegionResolutionVisitor < ' tcx > , expr : & ' tcx hir:: Expr < ' tcx > ) {
259+ fn resolve_expr < ' tcx > ( visitor : & mut ScopeResolutionVisitor < ' tcx > , expr : & ' tcx hir:: Expr < ' tcx > ) {
260260 debug ! ( "resolve_expr - pre-increment {} expr = {:?}" , visitor. expr_and_pat_count, expr) ;
261261
262262 let prev_cx = visitor. cx ;
@@ -420,10 +420,10 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
420420 // properly, we can't miss any types.
421421
422422 match expr. kind {
423- // Manually recurse over closures and inline consts , because they are the only
424- // case of nested bodies that share the parent environment.
425- hir :: ExprKind :: Closure ( & hir :: Closure { body , .. } )
426- | hir:: ExprKind :: ConstBlock ( hir:: ConstBlock { body, .. } ) => {
423+ // Manually recurse over closures, because they are nested bodies
424+ // that share the parent environment. We handle const blocks in
425+ // `visit_inline_const`.
426+ hir:: ExprKind :: Closure ( & hir:: Closure { body, .. } ) => {
427427 let body = visitor. tcx . hir ( ) . body ( body) ;
428428 visitor. visit_body ( body) ;
429429 }
@@ -554,7 +554,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
554554}
555555
556556fn resolve_local < ' tcx > (
557- visitor : & mut RegionResolutionVisitor < ' tcx > ,
557+ visitor : & mut ScopeResolutionVisitor < ' tcx > ,
558558 pat : Option < & ' tcx hir:: Pat < ' tcx > > ,
559559 init : Option < & ' tcx hir:: Expr < ' tcx > > ,
560560) {
@@ -725,7 +725,7 @@ fn resolve_local<'tcx>(
725725 /// | ( E& )
726726 /// ```
727727 fn record_rvalue_scope_if_borrow_expr < ' tcx > (
728- visitor : & mut RegionResolutionVisitor < ' tcx > ,
728+ visitor : & mut ScopeResolutionVisitor < ' tcx > ,
729729 expr : & hir:: Expr < ' _ > ,
730730 blk_id : Option < Scope > ,
731731 ) {
@@ -782,7 +782,7 @@ fn resolve_local<'tcx>(
782782 }
783783}
784784
785- impl < ' tcx > RegionResolutionVisitor < ' tcx > {
785+ impl < ' tcx > ScopeResolutionVisitor < ' tcx > {
786786 /// Records the current parent (if any) as the parent of `child_scope`.
787787 /// Returns the depth of `child_scope`.
788788 fn record_child_scope ( & mut self , child_scope : Scope ) -> ScopeDepth {
@@ -838,7 +838,7 @@ impl<'tcx> RegionResolutionVisitor<'tcx> {
838838 }
839839}
840840
841- impl < ' tcx > Visitor < ' tcx > for RegionResolutionVisitor < ' tcx > {
841+ impl < ' tcx > Visitor < ' tcx > for ScopeResolutionVisitor < ' tcx > {
842842 fn visit_block ( & mut self , b : & ' tcx Block < ' tcx > ) {
843843 resolve_block ( self , b) ;
844844 }
@@ -906,6 +906,10 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
906906 fn visit_local ( & mut self , l : & ' tcx LetStmt < ' tcx > ) {
907907 resolve_local ( self , Some ( l. pat ) , l. init )
908908 }
909+ fn visit_inline_const ( & mut self , c : & ' tcx hir:: ConstBlock ) {
910+ let body = self . tcx . hir ( ) . body ( c. body ) ;
911+ self . visit_body ( body) ;
912+ }
909913}
910914
911915/// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
@@ -922,7 +926,7 @@ pub(crate) fn region_scope_tree(tcx: TyCtxt<'_>, def_id: DefId) -> &ScopeTree {
922926 }
923927
924928 let scope_tree = if let Some ( body) = tcx. hir ( ) . maybe_body_owned_by ( def_id. expect_local ( ) ) {
925- let mut visitor = RegionResolutionVisitor {
929+ let mut visitor = ScopeResolutionVisitor {
926930 tcx,
927931 scope_tree : ScopeTree :: default ( ) ,
928932 expr_and_pat_count : 0 ,
0 commit comments