@@ -52,10 +52,10 @@ use crate::{
52
52
tt,
53
53
visibility:: { RawVisibility , Visibility } ,
54
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 ,
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 ,
59
59
} ;
60
60
61
61
static GLOB_RECURSION_LIMIT : Limit = Limit :: new ( 100 ) ;
@@ -156,10 +156,9 @@ struct Import {
156
156
alias : Option < ImportAlias > ,
157
157
visibility : RawVisibility ,
158
158
kind : ImportKind ,
159
+ source : ImportSource ,
159
160
is_prelude : bool ,
160
- is_extern_crate : bool ,
161
161
is_macro_use : bool ,
162
- source : ImportSource ,
163
162
}
164
163
165
164
impl Import {
@@ -168,26 +167,23 @@ impl Import {
168
167
krate : CrateId ,
169
168
tree : & ItemTree ,
170
169
id : ItemTreeId < item_tree:: Import > ,
171
- ) -> Vec < Self > {
170
+ mut cb : impl FnMut ( Self ) ,
171
+ ) {
172
172
let it = & tree[ id. value ] ;
173
173
let attrs = & tree. attrs ( db, krate, ModItem :: from ( id. value ) . into ( ) ) ;
174
174
let visibility = & tree[ it. visibility ] ;
175
175
let is_prelude = attrs. by_key ( "prelude_import" ) . exists ( ) ;
176
-
177
- let mut res = Vec :: new ( ) ;
178
176
it. use_tree . expand ( |idx, path, kind, alias| {
179
- res . push ( Self {
177
+ cb ( Self {
180
178
path,
181
179
alias,
182
180
visibility : visibility. clone ( ) ,
183
181
kind,
184
182
is_prelude,
185
- is_extern_crate : false ,
186
183
is_macro_use : false ,
187
184
source : ImportSource :: Import { id, use_tree : idx } ,
188
185
} ) ;
189
186
} ) ;
190
- res
191
187
}
192
188
193
189
fn from_extern_crate (
@@ -205,7 +201,6 @@ impl Import {
205
201
visibility : visibility. clone ( ) ,
206
202
kind : ImportKind :: Plain ,
207
203
is_prelude : false ,
208
- is_extern_crate : true ,
209
204
is_macro_use : attrs. by_key ( "macro_use" ) . exists ( ) ,
210
205
source : ImportSource :: ExternCrate ( id) ,
211
206
}
@@ -776,7 +771,7 @@ impl DefCollector<'_> {
776
771
let _p = profile:: span ( "resolve_import" )
777
772
. detail ( || format ! ( "{}" , import. path. display( self . db. upcast( ) ) ) ) ;
778
773
tracing:: debug!( "resolving import: {:?} ({:?})" , import, self . def_map. data. edition) ;
779
- if import. is_extern_crate {
774
+ if matches ! ( import. source , ImportSource :: ExternCrate { .. } ) {
780
775
let name = import
781
776
. path
782
777
. as_ident ( )
@@ -867,7 +862,7 @@ impl DefCollector<'_> {
867
862
tracing:: debug!( "resolved import {:?} ({:?}) to {:?}" , name, import, def) ;
868
863
869
864
// 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 { .. } )
871
866
&& self . def_map . block . is_none ( )
872
867
&& module_id == DefMap :: ROOT
873
868
{
@@ -1585,21 +1580,31 @@ impl ModCollector<'_, '_> {
1585
1580
match item {
1586
1581
ModItem :: Mod ( m) => self . collect_module ( m, & attrs) ,
1587
1582
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 (
1589
1589
db,
1590
1590
krate,
1591
1591
self . item_tree ,
1592
1592
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
+ } ) ;
1599
1599
} ,
1600
- ) ) ;
1600
+ )
1601
1601
}
1602
1602
ModItem :: ExternCrate ( import_id) => {
1603
+ let _import_id = ExternCrateLoc {
1604
+ container : module,
1605
+ id : ItemTreeId :: new ( self . tree_id , import_id) ,
1606
+ }
1607
+ . intern ( db) ;
1603
1608
self . def_collector . unresolved_imports . push ( ImportDirective {
1604
1609
module_id : self . module_id ,
1605
1610
import : Import :: from_extern_crate (
0 commit comments