@@ -36,7 +36,7 @@ use crate::{
36
36
item_scope:: { GlobId , ImportId , ImportOrExternCrate , PerNsGlobImports } ,
37
37
item_tree:: {
38
38
self , FieldsShape , ImportAlias , ImportKind , ItemTree , ItemTreeAstId , Macro2 , MacroCall ,
39
- MacroRules , Mod , ModItemId , ModKind , TreeId , UseTreeKind ,
39
+ MacroRules , Mod , ModItemId , ModKind , TreeId ,
40
40
} ,
41
41
macro_call_as_call_id,
42
42
nameres:: {
@@ -140,8 +140,6 @@ struct ImportSource {
140
140
id : UseId ,
141
141
is_prelude : bool ,
142
142
kind : ImportKind ,
143
- tree : TreeId ,
144
- item : FileAstId < ast:: Use > ,
145
143
}
146
144
147
145
#[ derive( Debug , Eq , PartialEq ) ]
@@ -155,7 +153,6 @@ struct Import {
155
153
impl Import {
156
154
fn from_use (
157
155
tree : & ItemTree ,
158
- tree_id : TreeId ,
159
156
item : FileAstId < ast:: Use > ,
160
157
id : UseId ,
161
158
is_prelude : bool ,
@@ -168,7 +165,7 @@ impl Import {
168
165
path,
169
166
alias,
170
167
visibility : visibility. clone ( ) ,
171
- source : ImportSource { use_tree : idx, id, is_prelude, kind, tree : tree_id , item } ,
168
+ source : ImportSource { use_tree : idx, id, is_prelude, kind } ,
172
169
} ) ;
173
170
} ) ;
174
171
}
@@ -183,15 +180,15 @@ struct ImportDirective {
183
180
}
184
181
185
182
#[ derive( Clone , Debug , Eq , PartialEq ) ]
186
- struct MacroDirective {
183
+ struct MacroDirective < ' db > {
187
184
module_id : LocalModuleId ,
188
185
depth : usize ,
189
- kind : MacroDirectiveKind ,
186
+ kind : MacroDirectiveKind < ' db > ,
190
187
container : ItemContainerId ,
191
188
}
192
189
193
190
#[ derive( Clone , Debug , Eq , PartialEq ) ]
194
- enum MacroDirectiveKind {
191
+ enum MacroDirectiveKind < ' db > {
195
192
FnLike {
196
193
ast_id : AstIdWithPath < ast:: MacroCall > ,
197
194
expand_to : ExpandTo ,
@@ -210,28 +207,29 @@ enum MacroDirectiveKind {
210
207
attr : Attr ,
211
208
mod_item : ModItemId ,
212
209
/* is this needed? */ tree : TreeId ,
210
+ item_tree : & ' db ItemTree ,
213
211
} ,
214
212
}
215
213
216
214
/// Walks the tree of module recursively
217
- struct DefCollector < ' a > {
218
- db : & ' a dyn DefDatabase ,
215
+ struct DefCollector < ' db > {
216
+ db : & ' db dyn DefDatabase ,
219
217
def_map : DefMap ,
220
218
local_def_map : LocalDefMap ,
221
219
/// Set only in case of blocks.
222
- crate_local_def_map : Option < & ' a LocalDefMap > ,
220
+ crate_local_def_map : Option < & ' db LocalDefMap > ,
223
221
// The dependencies of the current crate, including optional deps like `test`.
224
222
deps : FxHashMap < Name , BuiltDependency > ,
225
223
glob_imports : FxHashMap < LocalModuleId , Vec < ( LocalModuleId , Visibility , GlobId ) > > ,
226
224
unresolved_imports : Vec < ImportDirective > ,
227
225
indeterminate_imports : Vec < ( ImportDirective , PerNs ) > ,
228
- unresolved_macros : Vec < MacroDirective > ,
226
+ unresolved_macros : Vec < MacroDirective < ' db > > ,
229
227
// We'd like to avoid emitting a diagnostics avalanche when some `extern crate` doesn't
230
228
// resolve. When we emit diagnostics for unresolved imports, we only do so if the import
231
229
// doesn't start with an unresolved crate's name.
232
230
unresolved_extern_crates : FxHashSet < Name > ,
233
231
mod_dirs : FxHashMap < LocalModuleId , ModDir > ,
234
- cfg_options : & ' a CfgOptions ,
232
+ cfg_options : & ' db CfgOptions ,
235
233
/// List of procedural macros defined by this crate. This is read from the dynamic library
236
234
/// built by the build system, and is the list of proc-macros we can actually expand. It is
237
235
/// empty when proc-macro support is disabled (in which case we still do name resolution for
@@ -249,7 +247,7 @@ struct DefCollector<'a> {
249
247
skip_attrs : FxHashMap < InFile < FileAstId < ast:: Item > > , AttrId > ,
250
248
}
251
249
252
- impl DefCollector < ' _ > {
250
+ impl < ' db > DefCollector < ' db > {
253
251
fn seed_with_top_level ( & mut self ) {
254
252
let _p = tracing:: info_span!( "seed_with_top_level" ) . entered ( ) ;
255
253
@@ -461,7 +459,7 @@ impl DefCollector<'_> {
461
459
self . unresolved_macros . iter ( ) . enumerate ( ) . find_map ( |( idx, directive) | match & directive
462
460
. kind
463
461
{
464
- MacroDirectiveKind :: Attr { ast_id, mod_item, attr, tree } => {
462
+ MacroDirectiveKind :: Attr { ast_id, mod_item, attr, tree, item_tree } => {
465
463
self . def_map . diagnostics . push ( DefDiagnostic :: unresolved_macro_call (
466
464
directive. module_id ,
467
465
MacroCallKind :: Attr {
@@ -474,14 +472,20 @@ impl DefCollector<'_> {
474
472
475
473
self . skip_attrs . insert ( ast_id. ast_id . with_value ( mod_item. ast_id ( ) ) , attr. id ) ;
476
474
477
- Some ( ( idx, directive, * mod_item, * tree) )
475
+ Some ( ( idx, directive, * mod_item, * tree, * item_tree ) )
478
476
}
479
477
_ => None ,
480
478
} ) ;
481
479
482
480
match unresolved_attr {
483
- Some ( ( pos, & MacroDirective { module_id, depth, container, .. } , mod_item, tree_id) ) => {
484
- let item_tree = & tree_id. item_tree ( self . db ) ;
481
+ Some ( (
482
+ pos,
483
+ & MacroDirective { module_id, depth, container, .. } ,
484
+ mod_item,
485
+ tree_id,
486
+ item_tree,
487
+ ) ) => {
488
+ // FIXME: Remove this clone
485
489
let mod_dir = self . mod_dirs [ & module_id] . clone ( ) ;
486
490
ModCollector {
487
491
def_collector : self ,
@@ -862,8 +866,6 @@ impl DefCollector<'_> {
862
866
kind : kind @ ( ImportKind :: Plain | ImportKind :: TypeOnly ) ,
863
867
id,
864
868
use_tree,
865
- tree,
866
- item,
867
869
..
868
870
} => {
869
871
let name = match & import. alias {
@@ -896,13 +898,11 @@ impl DefCollector<'_> {
896
898
let Some ( ImportOrExternCrate :: ExternCrate ( _) ) = def. import else {
897
899
return false ;
898
900
} ;
899
- let item_tree = tree. item_tree ( self . db ) ;
900
- let use_kind = item_tree[ item] . use_tree . kind ( ) ;
901
- let UseTreeKind :: Single { path, .. } = use_kind else {
901
+ if kind == ImportKind :: Glob {
902
902
return false ;
903
- } ;
904
- matches ! ( path. kind, PathKind :: Plain | PathKind :: SELF )
905
- && path. segments ( ) . len ( ) < 2
903
+ }
904
+ matches ! ( import . path. kind, PathKind :: Plain | PathKind :: SELF )
905
+ && import . path . segments ( ) . len ( ) < 2
906
906
} ;
907
907
if is_extern_crate_reimport_without_prefix ( ) {
908
908
def. vis = vis;
@@ -1256,7 +1256,7 @@ impl DefCollector<'_> {
1256
1256
fn resolve_macros ( & mut self ) -> ReachedFixedPoint {
1257
1257
let mut macros = mem:: take ( & mut self . unresolved_macros ) ;
1258
1258
let mut resolved = Vec :: new ( ) ;
1259
- let mut push_resolved = |directive : & MacroDirective , call_id| {
1259
+ let mut push_resolved = |directive : & MacroDirective < ' _ > , call_id| {
1260
1260
resolved. push ( ( directive. module_id , directive. depth , directive. container , call_id) ) ;
1261
1261
} ;
1262
1262
@@ -1269,7 +1269,7 @@ impl DefCollector<'_> {
1269
1269
let mut eager_callback_buffer = vec ! [ ] ;
1270
1270
let mut res = ReachedFixedPoint :: Yes ;
1271
1271
// Retain unresolved macros after this round of resolution.
1272
- let mut retain = |directive : & MacroDirective | {
1272
+ let mut retain = |directive : & MacroDirective < ' db > | {
1273
1273
let subns = match & directive. kind {
1274
1274
MacroDirectiveKind :: FnLike { .. } => MacroSubNs :: Bang ,
1275
1275
MacroDirectiveKind :: Attr { .. } | MacroDirectiveKind :: Derive { .. } => {
@@ -1364,7 +1364,13 @@ impl DefCollector<'_> {
1364
1364
return Resolved :: Yes ;
1365
1365
}
1366
1366
}
1367
- MacroDirectiveKind :: Attr { ast_id : file_ast_id, mod_item, attr, tree } => {
1367
+ MacroDirectiveKind :: Attr {
1368
+ ast_id : file_ast_id,
1369
+ mod_item,
1370
+ attr,
1371
+ tree,
1372
+ item_tree,
1373
+ } => {
1368
1374
let & AstIdWithPath { ast_id, ref path } = file_ast_id;
1369
1375
let file_id = ast_id. file_id ;
1370
1376
@@ -1375,7 +1381,6 @@ impl DefCollector<'_> {
1375
1381
. skip_attrs
1376
1382
. insert ( InFile :: new ( file_id, mod_item. ast_id ( ) ) , attr. id ) ;
1377
1383
1378
- let item_tree = tree. item_tree ( self . db ) ;
1379
1384
ModCollector {
1380
1385
def_collector : collector,
1381
1386
macro_depth : directive. depth ,
@@ -1646,8 +1651,7 @@ impl DefCollector<'_> {
1646
1651
import :
1647
1652
Import {
1648
1653
ref path,
1649
- source :
1650
- ImportSource { use_tree, id, is_prelude : _, kind : _, tree : _, item : _ } ,
1654
+ source : ImportSource { use_tree, id, is_prelude : _, kind : _ } ,
1651
1655
..
1652
1656
} ,
1653
1657
..
@@ -1671,12 +1675,12 @@ impl DefCollector<'_> {
1671
1675
}
1672
1676
1673
1677
/// Walks a single module, populating defs, imports and macros
1674
- struct ModCollector < ' a , ' b > {
1675
- def_collector : & ' a mut DefCollector < ' b > ,
1678
+ struct ModCollector < ' a , ' db > {
1679
+ def_collector : & ' a mut DefCollector < ' db > ,
1676
1680
macro_depth : usize ,
1677
1681
module_id : LocalModuleId ,
1678
1682
tree_id : TreeId ,
1679
- item_tree : & ' a ItemTree ,
1683
+ item_tree : & ' db ItemTree ,
1680
1684
mod_dir : ModDir ,
1681
1685
}
1682
1686
@@ -1753,20 +1757,13 @@ impl ModCollector<'_, '_> {
1753
1757
UseLoc { container : module, id : InFile :: new ( self . file_id ( ) , item_tree_id) }
1754
1758
. intern ( db) ;
1755
1759
let is_prelude = attrs. by_key ( sym:: prelude_import) . exists ( ) ;
1756
- Import :: from_use (
1757
- self . item_tree ,
1758
- self . tree_id ,
1759
- item_tree_id,
1760
- id,
1761
- is_prelude,
1762
- |import| {
1763
- self . def_collector . unresolved_imports . push ( ImportDirective {
1764
- module_id : self . module_id ,
1765
- import,
1766
- status : PartialResolvedImport :: Unresolved ,
1767
- } ) ;
1768
- } ,
1769
- )
1760
+ Import :: from_use ( self . item_tree , item_tree_id, id, is_prelude, |import| {
1761
+ self . def_collector . unresolved_imports . push ( ImportDirective {
1762
+ module_id : self . module_id ,
1763
+ import,
1764
+ status : PartialResolvedImport :: Unresolved ,
1765
+ } ) ;
1766
+ } )
1770
1767
}
1771
1768
ModItemId :: ExternCrate ( item_tree_id) => {
1772
1769
let item_tree:: ExternCrate { name, visibility, alias } =
@@ -2268,6 +2265,7 @@ impl ModCollector<'_, '_> {
2268
2265
attr : attr. clone ( ) ,
2269
2266
mod_item,
2270
2267
tree : self . tree_id ,
2268
+ item_tree : self . item_tree ,
2271
2269
} ,
2272
2270
container,
2273
2271
} ) ;
0 commit comments