@@ -35,8 +35,8 @@ use crate::{
35
35
db:: DefDatabase ,
36
36
item_scope:: { GlobId , ImportId , ImportOrExternCrate , PerNsGlobImports } ,
37
37
item_tree:: {
38
- self , FieldsShape , ImportAlias , ImportKind , ItemTree , ItemTreeAstId , ItemTreeNode , Macro2 ,
39
- MacroCall , MacroRules , Mod , ModItem , ModKind , TreeId , UseTreeKind ,
38
+ self , AttrOwner , FieldsShape , ImportAlias , ImportKind , ItemTree , ItemTreeAstId ,
39
+ ItemTreeNode , Macro2 , MacroCall , MacroRules , Mod , ModItem , ModKind , TreeId , UseTreeKind ,
40
40
} ,
41
41
macro_call_as_call_id,
42
42
nameres:: {
@@ -246,7 +246,7 @@ struct DefCollector<'a> {
246
246
/// This also stores the attributes to skip when we resolve derive helpers and non-macro
247
247
/// non-builtin attributes in general.
248
248
// FIXME: There has to be a better way to do this
249
- skip_attrs : FxHashMap < InFile < ModItem > , AttrId > ,
249
+ skip_attrs : FxHashMap < InFile < FileAstId < ast :: Item > > , AttrId > ,
250
250
}
251
251
252
252
impl DefCollector < ' _ > {
@@ -472,7 +472,7 @@ impl DefCollector<'_> {
472
472
attr. path ( ) . clone ( ) ,
473
473
) ) ;
474
474
475
- self . skip_attrs . insert ( ast_id. ast_id . with_value ( * mod_item) , attr. id ) ;
475
+ self . skip_attrs . insert ( ast_id. ast_id . with_value ( mod_item. ast_id ( ) ) , attr. id ) ;
476
476
477
477
Some ( ( idx, directive, * mod_item, * tree) )
478
478
}
@@ -1371,7 +1371,9 @@ impl DefCollector<'_> {
1371
1371
let mut recollect_without = |collector : & mut Self | {
1372
1372
// Remove the original directive since we resolved it.
1373
1373
let mod_dir = collector. mod_dirs [ & directive. module_id ] . clone ( ) ;
1374
- collector. skip_attrs . insert ( InFile :: new ( file_id, * mod_item) , attr. id ) ;
1374
+ collector
1375
+ . skip_attrs
1376
+ . insert ( InFile :: new ( file_id, mod_item. ast_id ( ) ) , attr. id ) ;
1375
1377
1376
1378
let item_tree = tree. item_tree ( self . db ) ;
1377
1379
ModCollector {
@@ -1728,25 +1730,7 @@ impl ModCollector<'_, '_> {
1728
1730
let attrs = self . item_tree . attrs ( db, krate, item. into ( ) ) ;
1729
1731
if let Some ( cfg) = attrs. cfg ( ) {
1730
1732
if !self . is_cfg_enabled ( & cfg) {
1731
- let ast_id = match item {
1732
- ModItem :: Use ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1733
- ModItem :: ExternCrate ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1734
- ModItem :: ExternBlock ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1735
- ModItem :: Function ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1736
- ModItem :: Struct ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1737
- ModItem :: Union ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1738
- ModItem :: Enum ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1739
- ModItem :: Const ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1740
- ModItem :: Static ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1741
- ModItem :: Trait ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1742
- ModItem :: TraitAlias ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1743
- ModItem :: Impl ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1744
- ModItem :: TypeAlias ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1745
- ModItem :: Mod ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1746
- ModItem :: MacroCall ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1747
- ModItem :: MacroRules ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1748
- ModItem :: Macro2 ( it) => self . item_tree [ it] . ast_id . erase ( ) ,
1749
- } ;
1733
+ let ast_id = item. ast_id ( ) . erase ( ) ;
1750
1734
self . emit_unconfigured_diagnostic ( InFile :: new ( self . file_id ( ) , ast_id) , & cfg) ;
1751
1735
return ;
1752
1736
}
@@ -2256,8 +2240,11 @@ impl ModCollector<'_, '_> {
2256
2240
mod_item : ModItem ,
2257
2241
container : ItemContainerId ,
2258
2242
) -> Result < ( ) , ( ) > {
2259
- let mut ignore_up_to =
2260
- self . def_collector . skip_attrs . get ( & InFile :: new ( self . file_id ( ) , mod_item) ) . copied ( ) ;
2243
+ let mut ignore_up_to = self
2244
+ . def_collector
2245
+ . skip_attrs
2246
+ . get ( & InFile :: new ( self . file_id ( ) , mod_item. ast_id ( ) ) )
2247
+ . copied ( ) ;
2261
2248
let iter = attrs
2262
2249
. iter ( )
2263
2250
. dedup_by ( |a, b| {
@@ -2309,7 +2296,7 @@ impl ModCollector<'_, '_> {
2309
2296
fn collect_macro_rules ( & mut self , id : ItemTreeAstId < MacroRules > , module : ModuleId ) {
2310
2297
let krate = self . def_collector . def_map . krate ;
2311
2298
let mac = & self . item_tree [ id] ;
2312
- let attrs = self . item_tree . attrs ( self . def_collector . db , krate, ModItem :: from ( id) . into ( ) ) ;
2299
+ let attrs = self . item_tree . attrs ( self . def_collector . db , krate, AttrOwner :: Item ( id. erase ( ) ) ) ;
2313
2300
let ast_id = InFile :: new ( self . file_id ( ) , mac. ast_id . upcast ( ) ) ;
2314
2301
2315
2302
let export_attr = || attrs. by_key ( sym:: macro_export) ;
@@ -2398,7 +2385,7 @@ impl ModCollector<'_, '_> {
2398
2385
2399
2386
// Case 1: builtin macros
2400
2387
let mut helpers_opt = None ;
2401
- let attrs = self . item_tree . attrs ( self . def_collector . db , krate, ModItem :: from ( id) . into ( ) ) ;
2388
+ let attrs = self . item_tree . attrs ( self . def_collector . db , krate, AttrOwner :: Item ( id. erase ( ) ) ) ;
2402
2389
let expander = if attrs. by_key ( sym:: rustc_builtin_macro) . exists ( ) {
2403
2390
if let Some ( expander) = find_builtin_macro ( & mac. name ) {
2404
2391
match expander {
0 commit comments