@@ -52,10 +52,10 @@ use crate::{
5252 tt,
5353 visibility:: { RawVisibility , Visibility } ,
5454 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 ,
55+ ExternBlockLoc , ExternCrateLoc , FunctionId , FunctionLoc , ImplLoc , ImportLoc , Intern ,
56+ ItemContainerId , LocalModuleId , Macro2Id , Macro2Loc , MacroExpander , MacroId , MacroRulesId ,
57+ MacroRulesLoc , ModuleDefId , ModuleId , ProcMacroId , ProcMacroLoc , StaticLoc , StructLoc ,
58+ TraitAliasLoc , TraitLoc , TypeAliasLoc , UnionLoc , UnresolvedMacro ,
5959} ;
6060
6161static GLOB_RECURSION_LIMIT : Limit = Limit :: new ( 100 ) ;
@@ -156,10 +156,9 @@ struct Import {
156156 alias : Option < ImportAlias > ,
157157 visibility : RawVisibility ,
158158 kind : ImportKind ,
159+ source : ImportSource ,
159160 is_prelude : bool ,
160- is_extern_crate : bool ,
161161 is_macro_use : bool ,
162- source : ImportSource ,
163162}
164163
165164impl Import {
@@ -168,26 +167,23 @@ impl Import {
168167 krate : CrateId ,
169168 tree : & ItemTree ,
170169 id : ItemTreeId < item_tree:: Import > ,
171- ) -> Vec < Self > {
170+ mut cb : impl FnMut ( Self ) ,
171+ ) {
172172 let it = & tree[ id. value ] ;
173173 let attrs = & tree. attrs ( db, krate, ModItem :: from ( id. value ) . into ( ) ) ;
174174 let visibility = & tree[ it. visibility ] ;
175175 let is_prelude = attrs. by_key ( "prelude_import" ) . exists ( ) ;
176-
177- let mut res = Vec :: new ( ) ;
178176 it. use_tree . expand ( |idx, path, kind, alias| {
179- res . push ( Self {
177+ cb ( Self {
180178 path,
181179 alias,
182180 visibility : visibility. clone ( ) ,
183181 kind,
184182 is_prelude,
185- is_extern_crate : false ,
186183 is_macro_use : false ,
187184 source : ImportSource :: Import { id, use_tree : idx } ,
188185 } ) ;
189186 } ) ;
190- res
191187 }
192188
193189 fn from_extern_crate (
@@ -205,7 +201,6 @@ impl Import {
205201 visibility : visibility. clone ( ) ,
206202 kind : ImportKind :: Plain ,
207203 is_prelude : false ,
208- is_extern_crate : true ,
209204 is_macro_use : attrs. by_key ( "macro_use" ) . exists ( ) ,
210205 source : ImportSource :: ExternCrate ( id) ,
211206 }
@@ -776,7 +771,7 @@ impl DefCollector<'_> {
776771 let _p = profile:: span ( "resolve_import" )
777772 . detail ( || format ! ( "{}" , import. path. display( self . db. upcast( ) ) ) ) ;
778773 tracing:: debug!( "resolving import: {:?} ({:?})" , import, self . def_map. data. edition) ;
779- if import. is_extern_crate {
774+ if matches ! ( import. source , ImportSource :: ExternCrate { .. } ) {
780775 let name = import
781776 . path
782777 . as_ident ( )
@@ -867,7 +862,7 @@ impl DefCollector<'_> {
867862 tracing:: debug!( "resolved import {:?} ({:?}) to {:?}" , name, import, def) ;
868863
869864 // extern crates in the crate root are special-cased to insert entries into the extern prelude: rust-lang/rust#54658
870- if import. is_extern_crate
865+ if matches ! ( import. source , ImportSource :: ExternCrate { .. } )
871866 && self . def_map . block . is_none ( )
872867 && module_id == DefMap :: ROOT
873868 {
@@ -1585,21 +1580,34 @@ impl ModCollector<'_, '_> {
15851580 match item {
15861581 ModItem :: Mod ( m) => self . collect_module ( m, & attrs) ,
15871582 ModItem :: Import ( import_id) => {
1588- let imports = Import :: from_use (
1583+ let _import_id = ImportLoc {
1584+ container : module,
1585+ id : ItemTreeId :: new ( self . tree_id , import_id) ,
1586+ }
1587+ . intern ( db) ;
1588+ Import :: from_use (
15891589 db,
15901590 krate,
15911591 self . item_tree ,
15921592 ItemTreeId :: new ( self . tree_id , import_id) ,
1593- ) ;
1594- self . def_collector . unresolved_imports . extend ( imports . into_iter ( ) . map (
1595- |import| ImportDirective {
1596- module_id : self . module_id ,
1597- import ,
1598- status : PartialResolvedImport :: Unresolved ,
1593+ |import| {
1594+ self . def_collector . unresolved_imports . push ( ImportDirective {
1595+ module_id : self . module_id ,
1596+ import ,
1597+ status : PartialResolvedImport :: Unresolved ,
1598+ } ) ;
15991599 } ,
1600- ) ) ;
1600+ )
16011601 }
16021602 ModItem :: ExternCrate ( import_id) => {
1603+ let extern_crate_id = ExternCrateLoc {
1604+ container : module,
1605+ id : ItemTreeId :: new ( self . tree_id , import_id) ,
1606+ }
1607+ . intern ( db) ;
1608+ self . def_collector . def_map . modules [ self . module_id ]
1609+ . scope
1610+ . define_extern_crate_decl ( extern_crate_id) ;
16031611 self . def_collector . unresolved_imports . push ( ImportDirective {
16041612 module_id : self . module_id ,
16051613 import : Import :: from_extern_crate (
0 commit comments