@@ -219,7 +219,7 @@ struct MacroDirective {
219
219
enum MacroDirectiveKind {
220
220
FnLike { ast_id : AstIdWithPath < ast:: MacroCall > , expand_to : ExpandTo } ,
221
221
Derive { ast_id : AstIdWithPath < ast:: Item > , derive_attr : AttrId } ,
222
- Attr { ast_id : AstIdWithPath < ast:: Item > , attr : Attr , mod_item : ModItem } ,
222
+ Attr { ast_id : AstIdWithPath < ast:: Item > , attr : Attr , mod_item : ModItem , tree : TreeId } ,
223
223
}
224
224
225
225
/// Walks the tree of module recursively
@@ -420,17 +420,16 @@ impl DefCollector<'_> {
420
420
421
421
let mut unresolved_macros = std:: mem:: take ( & mut self . unresolved_macros ) ;
422
422
let pos = unresolved_macros. iter ( ) . position ( |directive| {
423
- if let MacroDirectiveKind :: Attr { ast_id, mod_item, attr } = & directive. kind {
423
+ if let MacroDirectiveKind :: Attr { ast_id, mod_item, attr, tree } = & directive. kind {
424
424
self . skip_attrs . insert ( ast_id. ast_id . with_value ( * mod_item) , attr. id ) ;
425
425
426
- let file_id = ast_id. ast_id . file_id ;
427
- let item_tree = self . db . file_item_tree ( file_id) ;
426
+ let item_tree = tree. item_tree ( self . db ) ;
428
427
let mod_dir = self . mod_dirs [ & directive. module_id ] . clone ( ) ;
429
428
ModCollector {
430
429
def_collector : self ,
431
430
macro_depth : directive. depth ,
432
431
module_id : directive. module_id ,
433
- tree_id : TreeId :: new ( file_id , None ) ,
432
+ tree_id : * tree ,
434
433
item_tree : & item_tree,
435
434
mod_dir,
436
435
}
@@ -1076,20 +1075,22 @@ impl DefCollector<'_> {
1076
1075
return false ;
1077
1076
}
1078
1077
}
1079
- MacroDirectiveKind :: Attr { ast_id : file_ast_id, mod_item, attr } => {
1078
+ MacroDirectiveKind :: Attr { ast_id : file_ast_id, mod_item, attr, tree } => {
1080
1079
let & AstIdWithPath { ast_id, ref path } = file_ast_id;
1081
1080
let file_id = ast_id. file_id ;
1082
1081
1083
- let mut recollect_without = |collector : & mut Self , item_tree | {
1082
+ let mut recollect_without = |collector : & mut Self | {
1084
1083
// Remove the original directive since we resolved it.
1085
1084
let mod_dir = collector. mod_dirs [ & directive. module_id ] . clone ( ) ;
1086
1085
collector. skip_attrs . insert ( InFile :: new ( file_id, * mod_item) , attr. id ) ;
1086
+
1087
+ let item_tree = tree. item_tree ( self . db ) ;
1087
1088
ModCollector {
1088
1089
def_collector : collector,
1089
1090
macro_depth : directive. depth ,
1090
1091
module_id : directive. module_id ,
1091
- tree_id : TreeId :: new ( file_id , None ) ,
1092
- item_tree,
1092
+ tree_id : * tree ,
1093
+ item_tree : & item_tree ,
1093
1094
mod_dir,
1094
1095
}
1095
1096
. collect ( & [ * mod_item] ) ;
@@ -1103,8 +1104,7 @@ impl DefCollector<'_> {
1103
1104
cov_mark:: hit!( resolved_derive_helper) ;
1104
1105
// Resolved to derive helper. Collect the item's attributes again,
1105
1106
// starting after the derive helper.
1106
- let item_tree = self . db . file_item_tree ( file_id) ;
1107
- return recollect_without ( self , & item_tree) ;
1107
+ return recollect_without ( self ) ;
1108
1108
}
1109
1109
}
1110
1110
}
@@ -1116,7 +1116,6 @@ impl DefCollector<'_> {
1116
1116
if expander. is_derive( )
1117
1117
) {
1118
1118
// Resolved to `#[derive]`
1119
- let item_tree = self . db . file_item_tree ( file_id) ;
1120
1119
1121
1120
match mod_item {
1122
1121
ModItem :: Struct ( _) | ModItem :: Union ( _) | ModItem :: Enum ( _) => ( ) ,
@@ -1127,7 +1126,7 @@ impl DefCollector<'_> {
1127
1126
attr. id ,
1128
1127
) ;
1129
1128
self . def_map . diagnostics . push ( diag) ;
1130
- return recollect_without ( self , & item_tree ) ;
1129
+ return recollect_without ( self ) ;
1131
1130
}
1132
1131
}
1133
1132
@@ -1155,7 +1154,7 @@ impl DefCollector<'_> {
1155
1154
}
1156
1155
}
1157
1156
1158
- return recollect_without ( self , & item_tree ) ;
1157
+ return recollect_without ( self ) ;
1159
1158
}
1160
1159
1161
1160
if !self . db . enable_proc_attr_macros ( ) {
@@ -1175,8 +1174,7 @@ impl DefCollector<'_> {
1175
1174
MacroDefKind :: BuiltInAttr ( expander, _)
1176
1175
if expander. is_test( ) || expander. is_bench( )
1177
1176
) {
1178
- let item_tree = self . db . file_item_tree ( file_id) ;
1179
- return recollect_without ( self , & item_tree) ;
1177
+ return recollect_without ( self ) ;
1180
1178
}
1181
1179
1182
1180
if let MacroDefKind :: ProcMacro ( exp, ..) = loc. def . kind {
@@ -1190,8 +1188,7 @@ impl DefCollector<'_> {
1190
1188
) ,
1191
1189
) ;
1192
1190
1193
- let item_tree = self . db . file_item_tree ( file_id) ;
1194
- return recollect_without ( self , & item_tree) ;
1191
+ return recollect_without ( self ) ;
1195
1192
}
1196
1193
}
1197
1194
@@ -1771,7 +1768,12 @@ impl ModCollector<'_, '_> {
1771
1768
self . def_collector . unresolved_macros . push ( MacroDirective {
1772
1769
module_id : self . module_id ,
1773
1770
depth : self . macro_depth + 1 ,
1774
- kind : MacroDirectiveKind :: Attr { ast_id, attr : attr. clone ( ) , mod_item } ,
1771
+ kind : MacroDirectiveKind :: Attr {
1772
+ ast_id,
1773
+ attr : attr. clone ( ) ,
1774
+ mod_item,
1775
+ tree : self . tree_id ,
1776
+ } ,
1775
1777
} ) ;
1776
1778
1777
1779
return Err ( ( ) ) ;
0 commit comments