@@ -1275,8 +1275,10 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod
12751275 opaques,
12761276 nested_bodies,
12771277 eiis,
1278+ proc_macro_decls,
12781279 ..
12791280 } = collector;
1281+
12801282 ModuleItems {
12811283 add_root : false ,
12821284 submodules : submodules. into_boxed_slice ( ) ,
@@ -1288,6 +1290,7 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod
12881290 opaques : opaques. into_boxed_slice ( ) ,
12891291 nested_bodies : nested_bodies. into_boxed_slice ( ) ,
12901292 eiis : eiis. into_boxed_slice ( ) ,
1293+ proc_macro_decls,
12911294 }
12921295}
12931296
@@ -1310,6 +1313,7 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
13101313 opaques,
13111314 nested_bodies,
13121315 eiis,
1316+ proc_macro_decls,
13131317 ..
13141318 } = collector;
13151319
@@ -1324,40 +1328,32 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
13241328 opaques : opaques. into_boxed_slice ( ) ,
13251329 nested_bodies : nested_bodies. into_boxed_slice ( ) ,
13261330 eiis : eiis. into_boxed_slice ( ) ,
1331+ proc_macro_decls,
13271332 }
13281333}
13291334
13301335struct ItemCollector < ' tcx > {
13311336 // When true, it collects all items in the create,
13321337 // otherwise it collects items in some module.
1338+ // Converting this to generic const didn't lead to significant perf improvements
1339+ // (see <https://github.com/rust-lang/rust/pull/158119#issuecomment-4751513679>).
13331340 crate_collector : bool ,
13341341 tcx : TyCtxt < ' tcx > ,
1335- submodules : Vec < OwnerId > ,
1336- items : Vec < ItemId > ,
1337- trait_items : Vec < TraitItemId > ,
1338- impl_items : Vec < ImplItemId > ,
1339- foreign_items : Vec < ForeignItemId > ,
1340- body_owners : Vec < LocalDefId > ,
1341- opaques : Vec < LocalDefId > ,
1342- nested_bodies : Vec < LocalDefId > ,
1343- eiis : Vec < LocalDefId > ,
1342+ submodules : Vec < OwnerId > = vec ! [ ] ,
1343+ items : Vec < ItemId > = vec ! [ ] ,
1344+ trait_items : Vec < TraitItemId > = vec ! [ ] ,
1345+ impl_items : Vec < ImplItemId > = vec ! [ ] ,
1346+ foreign_items : Vec < ForeignItemId > = vec ! [ ] ,
1347+ body_owners : Vec < LocalDefId > = vec ! [ ] ,
1348+ opaques : Vec < LocalDefId > = vec ! [ ] ,
1349+ nested_bodies : Vec < LocalDefId > = vec ! [ ] ,
1350+ eiis : Vec < LocalDefId > = vec ! [ ] ,
1351+ proc_macro_decls : Option < LocalDefId > = None ,
13441352}
13451353
13461354impl < ' tcx > ItemCollector < ' tcx > {
13471355 fn new ( tcx : TyCtxt < ' tcx > , crate_collector : bool ) -> ItemCollector < ' tcx > {
1348- ItemCollector {
1349- crate_collector,
1350- tcx,
1351- submodules : Vec :: default ( ) ,
1352- items : Vec :: default ( ) ,
1353- trait_items : Vec :: default ( ) ,
1354- impl_items : Vec :: default ( ) ,
1355- foreign_items : Vec :: default ( ) ,
1356- body_owners : Vec :: default ( ) ,
1357- opaques : Vec :: default ( ) ,
1358- nested_bodies : Vec :: default ( ) ,
1359- eiis : Vec :: default ( ) ,
1360- }
1356+ ItemCollector { crate_collector, tcx, .. }
13611357 }
13621358}
13631359
@@ -1373,7 +1369,16 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
13731369 self . body_owners . push ( item. owner_id . def_id ) ;
13741370 }
13751371
1376- self . items . push ( item. item_id ( ) ) ;
1372+ let item_id = item. item_id ( ) ;
1373+
1374+ if self . crate_collector
1375+ && self . proc_macro_decls . is_none ( )
1376+ && find_attr ! ( self . tcx, item_id. hir_id( ) , RustcProcMacroDecls )
1377+ {
1378+ self . proc_macro_decls = Some ( item_id. owner_id . def_id ) ;
1379+ }
1380+
1381+ self . items . push ( item_id) ;
13771382
13781383 if let ItemKind :: Static ( ..) | ItemKind :: Fn { .. } | ItemKind :: Macro ( ..) = & item. kind
13791384 && item. eii
0 commit comments