@@ -32,7 +32,6 @@ pub(crate) fn collect_definitions<'ra>(
3232 with_owner ( resolver, invocation_parent. owner , |r| {
3333 let mut visitor = DefCollector { r, invocation_parent, parent_scope } ;
3434 fragment. visit_with ( & mut visitor) ;
35-
3635 visitor. parent_scope . macro_rules
3736 } )
3837}
@@ -64,6 +63,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
6463 def_kind,
6564 self . parent_scope . expansion . to_expn_id ( ) ,
6665 span. with_parent ( None ) ,
66+ false ,
6767 )
6868 }
6969
@@ -73,23 +73,33 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
7373 self . invocation_parent . parent_def = orig_parent_def;
7474 }
7575
76- pub ( super ) fn with_owner < F : FnOnce ( & mut Self ) > ( & mut self , owner : NodeId , f : F ) {
76+ pub ( super ) fn with_owner < F : FnOnce ( & mut Self , TyCtxtFeed < ' tcx , LocalDefId > ) > (
77+ & mut self ,
78+ owner : NodeId ,
79+ name : Option < Symbol > ,
80+ def_kind : DefKind ,
81+ span : Span ,
82+ f : F ,
83+ ) {
7784 debug_assert_ne ! ( owner, DUMMY_NODE_ID ) ;
78- if owner == CRATE_NODE_ID {
79- // Special case: we always have an invocation parent (set in `collect_definitions`)
80- // of at least the crate root, even for visiting the crate root,
81- // which would then remove the crate root from the tables
82- // list twice and try to insert it twice afterwards.
83- debug_assert_eq ! ( self . r. current_owner. id, CRATE_NODE_ID ) ;
84- return f ( self ) ;
85- }
85+ debug_assert_ne ! ( owner, CRATE_NODE_ID ) ;
8686 // We only get here if the owner didn't exist yet. After the owner has been created,
8787 // future invocations of `collect_definitions` will get the owner out of the `owners`
8888 // table.
89- let tables = PerOwnerResolverData :: new ( owner) ;
89+ let parent_def = self . invocation_parent . parent_def ;
90+ let feed = self . r . create_def (
91+ parent_def,
92+ owner,
93+ name,
94+ def_kind,
95+ self . parent_scope . expansion . to_expn_id ( ) ,
96+ span. with_parent ( None ) ,
97+ true ,
98+ ) ;
99+ let tables = PerOwnerResolverData :: new ( owner, feed. key ( ) ) ;
90100
91101 let orig_invoc_owner = mem:: replace ( & mut self . invocation_parent . owner , owner) ;
92- with_owner_tables ( self , owner, tables, f ) ;
102+ with_owner_tables ( self , owner, tables, |this| f ( this , feed ) ) ;
93103 let old = mem:: replace ( & mut self . invocation_parent . owner , orig_invoc_owner) ;
94104 assert_eq ! ( old, owner) ;
95105 }
@@ -200,8 +210,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
200210 }
201211 ItemKind :: GlobalAsm ( ..) => DefKind :: GlobalAsm ,
202212 ItemKind :: Use ( _) => {
203- return self . with_owner ( i. id , |this| {
204- let feed = this. create_def ( i. id , None , DefKind :: Use , i. span ) ;
213+ return self . with_owner ( i. id , None , DefKind :: Use , i. span , |this, feed| {
205214 this. brg_visit_item ( i, feed) ;
206215 } ) ;
207216 }
@@ -212,20 +221,23 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
212221 }
213222 ItemKind :: DelegationMac ( ..) => unreachable ! ( ) ,
214223 } ;
215- self . with_owner ( i. id , |this| {
216- let feed =
217- this. create_def ( i. id , i. kind . ident ( ) . map ( |ident| ident. name ) , def_kind, i. span ) ;
218-
219- if let Some ( ext) = opt_syn_ext {
220- this. r . local_macro_map . insert ( feed. def_id ( ) , self . r . arenas . alloc_macro ( ext) ) ;
221- }
224+ self . with_owner (
225+ i. id ,
226+ i. kind . ident ( ) . map ( |ident| ident. name ) ,
227+ def_kind,
228+ i. span ,
229+ |this, feed| {
230+ if let Some ( ext) = opt_syn_ext {
231+ this. r . local_macro_map . insert ( feed. def_id ( ) , self . r . arenas . alloc_macro ( ext) ) ;
232+ }
222233
223- this. with_parent ( feed. def_id ( ) , |this| {
224- this. with_impl_trait ( ImplTraitContext :: Existential , |this| {
225- this. brg_visit_item ( i, feed)
226- } )
227- } ) ;
228- } ) ;
234+ this. with_parent ( feed. def_id ( ) , |this| {
235+ this. with_impl_trait ( ImplTraitContext :: Existential , |this| {
236+ this. brg_visit_item ( i, feed)
237+ } )
238+ } ) ;
239+ } ,
240+ ) ;
229241 }
230242
231243 fn visit_block ( & mut self , block : & ' a Block ) {
@@ -316,9 +328,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
316328 }
317329 } ;
318330
319- self . with_owner ( fi. id , |this| {
320- let def = this. create_def ( fi. id , Some ( ident. name ) , def_kind, fi. span ) ;
321-
331+ self . with_owner ( fi. id , Some ( ident. name ) , def_kind, fi. span , |this, def| {
322332 this. with_parent ( def. def_id ( ) , |this| {
323333 this. build_reduced_graph_for_foreign_item ( fi, ident, def) ;
324334 visit:: walk_item ( this, fi)
@@ -402,8 +412,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
402412 }
403413 } ;
404414
405- self . with_owner ( i. id , |this| {
406- let feed = this. create_def ( i. id , Some ( ident. name ) , def_kind, i. span ) ;
415+ self . with_owner ( i. id , Some ( ident. name ) , def_kind, i. span , |this, feed| {
407416 this. with_parent ( feed. def_id ( ) , |this| {
408417 this. brg_visit_assoc_item ( i, ctxt, ident, ns, feed)
409418 } ) ;
@@ -604,11 +613,16 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
604613 } else {
605614 // Visit attributes after items for backward compatibility.
606615 // This way they can use `macro_rules` defined later.
607- self . with_owner ( CRATE_NODE_ID , |this| {
608- visit:: walk_list!( this, visit_item, & krate. items) ;
609- visit:: walk_list!( this, visit_attribute, & krate. attrs) ;
610- this. contains_macro_use ( & krate. attrs ) ;
611- } )
616+
617+ // We always have an invocation parent (set in `collect_definitions`)
618+ // of at least the crate root, even for visiting the crate root,
619+ // which would then remove the crate root from the tables
620+ // list twice and try to insert it twice afterwards.
621+ debug_assert_eq ! ( self . r. current_owner. id, CRATE_NODE_ID ) ;
622+
623+ visit:: walk_list!( self , visit_item, & krate. items) ;
624+ visit:: walk_list!( self , visit_attribute, & krate. attrs) ;
625+ self . contains_macro_use ( & krate. attrs ) ;
612626 }
613627 }
614628
0 commit comments