@@ -51,11 +51,11 @@ use crate::{
5151 per_ns:: PerNs ,
5252 tt,
5353 visibility:: { RawVisibility , Visibility } ,
54- AdtId , AstId , AstIdWithPath , ConstLoc , EnumLoc , EnumVariantId , ExternBlockLoc , FunctionId ,
55- FunctionLoc , ImplLoc , Intern , ItemContainerId , LocalModuleId , Macro2Id , Macro2Loc ,
56- MacroExpander , MacroId , MacroRulesId , MacroRulesLoc , ModuleDefId , ModuleId , ProcMacroId ,
57- ProcMacroLoc , StaticLoc , StructLoc , TraitAliasLoc , TraitLoc , TypeAliasLoc , UnionLoc ,
58- UnresolvedMacro ,
54+ AdtId , AstId , AstIdWithPath , ConstLoc , CrateRootModuleId , EnumLoc , EnumVariantId ,
55+ ExternBlockLoc , FunctionId , FunctionLoc , ImplLoc , Intern , ItemContainerId , LocalModuleId ,
56+ Macro2Id , Macro2Loc , MacroExpander , MacroId , MacroRulesId , MacroRulesLoc , ModuleDefId ,
57+ ModuleId , ProcMacroId , ProcMacroLoc , StaticLoc , StructLoc , TraitAliasLoc , TraitLoc ,
58+ TypeAliasLoc , UnionLoc , UnresolvedMacro ,
5959} ;
6060
6161static GLOB_RECURSION_LIMIT : Limit = Limit :: new ( 100 ) ;
@@ -274,8 +274,6 @@ impl DefCollector<'_> {
274274
275275 let file_id = self . db . crate_graph ( ) [ self . def_map . krate ] . root_file_id ;
276276 let item_tree = self . db . file_item_tree ( file_id. into ( ) ) ;
277- let module_id = DefMap :: ROOT ;
278-
279277 let attrs = item_tree. top_level_attrs ( self . db , self . def_map . krate ) ;
280278 let crate_data = Arc :: get_mut ( & mut self . def_map . data ) . unwrap ( ) ;
281279
@@ -285,10 +283,9 @@ impl DefCollector<'_> {
285283
286284 for ( name, dep) in & self . deps {
287285 if dep. is_prelude ( ) {
288- crate_data. extern_prelude . insert (
289- name. clone ( ) ,
290- ModuleId { krate : dep. crate_id , block : None , local_id : DefMap :: ROOT } ,
291- ) ;
286+ crate_data
287+ . extern_prelude
288+ . insert ( name. clone ( ) , CrateRootModuleId { krate : dep. crate_id } ) ;
292289 }
293290 }
294291
@@ -374,7 +371,7 @@ impl DefCollector<'_> {
374371 ModCollector {
375372 def_collector : self ,
376373 macro_depth : 0 ,
377- module_id,
374+ module_id : DefMap :: ROOT ,
378375 tree_id : TreeId :: new ( file_id. into ( ) , None ) ,
379376 item_tree : & item_tree,
380377 mod_dir : ModDir :: root ( ) ,
@@ -384,8 +381,6 @@ impl DefCollector<'_> {
384381
385382 fn seed_with_inner ( & mut self , tree_id : TreeId ) {
386383 let item_tree = tree_id. item_tree ( self . db ) ;
387- let module_id = DefMap :: ROOT ;
388-
389384 let is_cfg_enabled = item_tree
390385 . top_level_attrs ( self . db , self . def_map . krate )
391386 . cfg ( )
@@ -394,7 +389,7 @@ impl DefCollector<'_> {
394389 ModCollector {
395390 def_collector : self ,
396391 macro_depth : 0 ,
397- module_id,
392+ module_id : DefMap :: ROOT ,
398393 tree_id,
399394 item_tree : & item_tree,
400395 mod_dir : ModDir :: root ( ) ,
@@ -604,8 +599,6 @@ impl DefCollector<'_> {
604599 if self . def_map . block . is_some ( ) {
605600 return ;
606601 }
607- let crate_root = self . def_map . module_id ( DefMap :: ROOT ) ;
608-
609602 let kind = def. kind . to_basedb_kind ( ) ;
610603 let ( expander, kind) =
611604 match self . proc_macros . as_ref ( ) . map ( |it| it. iter ( ) . find ( |( n, _) | n == & def. name ) ) {
@@ -614,7 +607,8 @@ impl DefCollector<'_> {
614607 } ;
615608
616609 let proc_macro_id =
617- ProcMacroLoc { container : crate_root, id, expander, kind } . intern ( self . db ) ;
610+ ProcMacroLoc { container : self . def_map . crate_root ( ) , id, expander, kind }
611+ . intern ( self . db ) ;
618612 self . define_proc_macro ( def. name . clone ( ) , proc_macro_id) ;
619613 let crate_data = Arc :: get_mut ( & mut self . def_map . data ) . unwrap ( ) ;
620614 if let ProcMacroKind :: CustomDerive { helpers } = def. kind {
@@ -831,16 +825,12 @@ impl DefCollector<'_> {
831825 }
832826 }
833827
834- fn resolve_extern_crate ( & self , name : & Name ) -> Option < ModuleId > {
828+ fn resolve_extern_crate ( & self , name : & Name ) -> Option < CrateRootModuleId > {
835829 if * name == name ! ( self ) {
836830 cov_mark:: hit!( extern_crate_self_as) ;
837831 Some ( self . def_map . crate_root ( ) )
838832 } else {
839- self . deps . get ( name) . map ( |dep| ModuleId {
840- krate : dep. crate_id ,
841- block : None ,
842- local_id : DefMap :: ROOT ,
843- } )
833+ self . deps . get ( name) . map ( |dep| CrateRootModuleId { krate : dep. crate_id } )
844834 }
845835 }
846836
@@ -883,10 +873,12 @@ impl DefCollector<'_> {
883873 {
884874 if let ( Some ( ModuleDefId :: ModuleId ( def) ) , Some ( name) ) = ( def. take_types ( ) , name)
885875 {
886- Arc :: get_mut ( & mut self . def_map . data )
887- . unwrap ( )
888- . extern_prelude
889- . insert ( name. clone ( ) , def) ;
876+ if let Ok ( def) = def. try_into ( ) {
877+ Arc :: get_mut ( & mut self . def_map . data )
878+ . unwrap ( )
879+ . extern_prelude
880+ . insert ( name. clone ( ) , def) ;
881+ }
890882 }
891883 }
892884
@@ -1791,13 +1783,11 @@ impl ModCollector<'_, '_> {
17911783
17921784 let target_crate =
17931785 match self . def_collector . resolve_extern_crate ( & self . item_tree [ extern_crate] . name ) {
1794- Some ( m) => {
1795- if m == self . def_collector . def_map . module_id ( self . module_id ) {
1796- cov_mark:: hit!( ignore_macro_use_extern_crate_self) ;
1797- return ;
1798- }
1799- m. krate
1786+ Some ( m) if m. krate == self . def_collector . def_map . krate => {
1787+ cov_mark:: hit!( ignore_macro_use_extern_crate_self) ;
1788+ return ;
18001789 }
1790+ Some ( m) => m. krate ,
18011791 None => return ,
18021792 } ;
18031793
0 commit comments