@@ -51,11 +51,11 @@ use crate::{
51
51
per_ns:: PerNs ,
52
52
tt,
53
53
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 ,
59
59
} ;
60
60
61
61
static GLOB_RECURSION_LIMIT : Limit = Limit :: new ( 100 ) ;
@@ -274,8 +274,6 @@ impl DefCollector<'_> {
274
274
275
275
let file_id = self . db . crate_graph ( ) [ self . def_map . krate ] . root_file_id ;
276
276
let item_tree = self . db . file_item_tree ( file_id. into ( ) ) ;
277
- let module_id = DefMap :: ROOT ;
278
-
279
277
let attrs = item_tree. top_level_attrs ( self . db , self . def_map . krate ) ;
280
278
let crate_data = Arc :: get_mut ( & mut self . def_map . data ) . unwrap ( ) ;
281
279
@@ -285,10 +283,9 @@ impl DefCollector<'_> {
285
283
286
284
for ( name, dep) in & self . deps {
287
285
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 } ) ;
292
289
}
293
290
}
294
291
@@ -374,7 +371,7 @@ impl DefCollector<'_> {
374
371
ModCollector {
375
372
def_collector : self ,
376
373
macro_depth : 0 ,
377
- module_id,
374
+ module_id : DefMap :: ROOT ,
378
375
tree_id : TreeId :: new ( file_id. into ( ) , None ) ,
379
376
item_tree : & item_tree,
380
377
mod_dir : ModDir :: root ( ) ,
@@ -384,8 +381,6 @@ impl DefCollector<'_> {
384
381
385
382
fn seed_with_inner ( & mut self , tree_id : TreeId ) {
386
383
let item_tree = tree_id. item_tree ( self . db ) ;
387
- let module_id = DefMap :: ROOT ;
388
-
389
384
let is_cfg_enabled = item_tree
390
385
. top_level_attrs ( self . db , self . def_map . krate )
391
386
. cfg ( )
@@ -394,7 +389,7 @@ impl DefCollector<'_> {
394
389
ModCollector {
395
390
def_collector : self ,
396
391
macro_depth : 0 ,
397
- module_id,
392
+ module_id : DefMap :: ROOT ,
398
393
tree_id,
399
394
item_tree : & item_tree,
400
395
mod_dir : ModDir :: root ( ) ,
@@ -604,8 +599,6 @@ impl DefCollector<'_> {
604
599
if self . def_map . block . is_some ( ) {
605
600
return ;
606
601
}
607
- let crate_root = self . def_map . module_id ( DefMap :: ROOT ) ;
608
-
609
602
let kind = def. kind . to_basedb_kind ( ) ;
610
603
let ( expander, kind) =
611
604
match self . proc_macros . as_ref ( ) . map ( |it| it. iter ( ) . find ( |( n, _) | n == & def. name ) ) {
@@ -614,7 +607,8 @@ impl DefCollector<'_> {
614
607
} ;
615
608
616
609
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 ) ;
618
612
self . define_proc_macro ( def. name . clone ( ) , proc_macro_id) ;
619
613
let crate_data = Arc :: get_mut ( & mut self . def_map . data ) . unwrap ( ) ;
620
614
if let ProcMacroKind :: CustomDerive { helpers } = def. kind {
@@ -831,16 +825,12 @@ impl DefCollector<'_> {
831
825
}
832
826
}
833
827
834
- fn resolve_extern_crate ( & self , name : & Name ) -> Option < ModuleId > {
828
+ fn resolve_extern_crate ( & self , name : & Name ) -> Option < CrateRootModuleId > {
835
829
if * name == name ! ( self ) {
836
830
cov_mark:: hit!( extern_crate_self_as) ;
837
831
Some ( self . def_map . crate_root ( ) )
838
832
} 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 } )
844
834
}
845
835
}
846
836
@@ -883,10 +873,12 @@ impl DefCollector<'_> {
883
873
{
884
874
if let ( Some ( ModuleDefId :: ModuleId ( def) ) , Some ( name) ) = ( def. take_types ( ) , name)
885
875
{
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
+ }
890
882
}
891
883
}
892
884
@@ -1791,13 +1783,11 @@ impl ModCollector<'_, '_> {
1791
1783
1792
1784
let target_crate =
1793
1785
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 ;
1800
1789
}
1790
+ Some ( m) => m. krate ,
1801
1791
None => return ,
1802
1792
} ;
1803
1793
0 commit comments