@@ -78,6 +78,7 @@ use syntax_pos::Span;
7878use std:: borrow:: Cow ;
7979use std:: fmt;
8080use std:: hash:: { Hash , Hasher } ;
81+ use rustc_data_structures:: fx:: FxIndexMap ;
8182use rustc_data_structures:: indexed_vec:: Idx ;
8283use std:: rc:: Rc ;
8384use crate :: util:: nodemap:: ItemLocalSet ;
@@ -289,6 +290,7 @@ impl HirNode for hir::Pat {
289290pub struct MemCategorizationContext < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
290291 pub tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
291292 pub body_owner : DefId ,
293+ pub upvars : Option < & ' tcx FxIndexMap < hir:: HirId , hir:: Upvar > > ,
292294 pub region_scope_tree : & ' a region:: ScopeTree ,
293295 pub tables : & ' a ty:: TypeckTables < ' tcx > ,
294296 rvalue_promotable_map : Option < & ' tcx ItemLocalSet > ,
@@ -407,6 +409,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
407409 MemCategorizationContext {
408410 tcx,
409411 body_owner,
412+ upvars : tcx. upvars ( body_owner) ,
410413 region_scope_tree,
411414 tables,
412415 rvalue_promotable_map,
@@ -441,6 +444,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
441444 MemCategorizationContext {
442445 tcx,
443446 body_owner,
447+ upvars : tcx. upvars ( body_owner) ,
444448 region_scope_tree,
445449 tables,
446450 rvalue_promotable_map,
@@ -742,21 +746,20 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
742746 } )
743747 }
744748
745- Res :: Upvar ( var_id, closure_node_id) => {
749+ Res :: Upvar ( var_id) => {
750+ assert ! ( self . upvars. map_or( false , |upvars| upvars. contains_key( & var_id) ) ) ;
746751 let var_nid = self . tcx . hir ( ) . hir_to_node_id ( var_id) ;
747- let closure_def_id = self . tcx . hir ( ) . local_def_id ( closure_node_id) ;
748- assert_eq ! ( self . body_owner, closure_def_id) ;
749-
750752 self . cat_upvar ( hir_id, span, var_nid)
751753 }
752754
753- Res :: Local ( vid) => {
754- let vnid = self . tcx . hir ( ) . hir_to_node_id ( vid) ;
755+ Res :: Local ( var_id) => {
756+ assert ! ( !self . upvars. map_or( false , |upvars| upvars. contains_key( & var_id) ) ) ;
757+ let var_nid = self . tcx . hir ( ) . hir_to_node_id ( var_id) ;
755758 Ok ( cmt_ {
756759 hir_id,
757760 span,
758- cat : Categorization :: Local ( vid ) ,
759- mutbl : MutabilityCategory :: from_local ( self . tcx , self . tables , vnid ) ,
761+ cat : Categorization :: Local ( var_id ) ,
762+ mutbl : MutabilityCategory :: from_local ( self . tcx , self . tables , var_nid ) ,
760763 ty : expr_ty,
761764 note : NoteNone
762765 } )
@@ -768,7 +771,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
768771
769772 // Categorize an upvar, complete with invisible derefs of closure
770773 // environment and upvar reference as appropriate.
771- pub fn cat_upvar (
774+ fn cat_upvar (
772775 & self ,
773776 hir_id : hir:: HirId ,
774777 span : Span ,
0 commit comments