@@ -288,6 +288,7 @@ impl HirNode for hir::Pat {
288288#[ derive( Clone ) ]
289289pub struct MemCategorizationContext < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
290290 pub tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
291+ pub body_owner : DefId ,
291292 pub region_scope_tree : & ' a region:: ScopeTree ,
292293 pub tables : & ' a ty:: TypeckTables < ' tcx > ,
293294 rvalue_promotable_map : Option < & ' tcx ItemLocalSet > ,
@@ -398,12 +399,14 @@ impl MutabilityCategory {
398399
399400impl < ' a , ' tcx > MemCategorizationContext < ' a , ' tcx , ' tcx > {
400401 pub fn new ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
402+ body_owner : DefId ,
401403 region_scope_tree : & ' a region:: ScopeTree ,
402404 tables : & ' a ty:: TypeckTables < ' tcx > ,
403405 rvalue_promotable_map : Option < & ' tcx ItemLocalSet > )
404406 -> MemCategorizationContext < ' a , ' tcx , ' tcx > {
405407 MemCategorizationContext {
406408 tcx,
409+ body_owner,
407410 region_scope_tree,
408411 tables,
409412 rvalue_promotable_map,
@@ -423,6 +426,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
423426 /// - similarly, as the results of upvar analysis are not yet
424427 /// known, the results around upvar accesses may be incorrect.
425428 pub fn with_infer ( infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
429+ body_owner : DefId ,
426430 region_scope_tree : & ' a region:: ScopeTree ,
427431 tables : & ' a ty:: TypeckTables < ' tcx > )
428432 -> MemCategorizationContext < ' a , ' gcx , ' tcx > {
@@ -436,6 +440,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
436440
437441 MemCategorizationContext {
438442 tcx,
443+ body_owner,
439444 region_scope_tree,
440445 tables,
441446 rvalue_promotable_map,
@@ -739,8 +744,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
739744
740745 Res :: Upvar ( var_id, closure_node_id) => {
741746 let var_nid = self . tcx . hir ( ) . hir_to_node_id ( var_id) ;
742- let closure_expr_def_id = self . tcx . hir ( ) . local_def_id ( closure_node_id) ;
743- self . cat_upvar ( hir_id, span, var_nid, closure_expr_def_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+
750+ self . cat_upvar ( hir_id, span, var_nid)
744751 }
745752
746753 Res :: Local ( vid) => {
@@ -766,7 +773,6 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
766773 hir_id : hir:: HirId ,
767774 span : Span ,
768775 var_id : ast:: NodeId ,
769- closure_expr_def_id : DefId ,
770776 ) -> McResult < cmt_ < ' tcx > > {
771777 // An upvar can have up to 3 components. We translate first to a
772778 // `Categorization::Upvar`, which is itself a fiction -- it represents the reference to the
@@ -791,6 +797,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
791797 // FnMut | copied -> &'env mut | upvar -> &'env mut -> &'up bk
792798 // FnOnce | copied | upvar -> &'up bk
793799
800+ let closure_expr_def_id = self . body_owner ;
794801 let fn_hir_id = self . tcx . hir ( ) . local_def_id_to_hir_id (
795802 LocalDefId :: from_def_id ( closure_expr_def_id) ,
796803 ) ;
0 commit comments