@@ -27,7 +27,13 @@ pub struct DefCollector<'a> {
27
27
hir_crate : Option < & ' a hir:: Crate > ,
28
28
definitions : & ' a mut Definitions ,
29
29
parent_def : Option < DefIndex > ,
30
- pub visit_macro_invoc : Option < & ' a mut FnMut ( NodeId , DefIndex ) > ,
30
+ pub visit_macro_invoc : Option < & ' a mut FnMut ( MacroInvocationData ) > ,
31
+ }
32
+
33
+ pub struct MacroInvocationData {
34
+ pub id : NodeId ,
35
+ pub def_index : DefIndex ,
36
+ pub const_integer : bool ,
31
37
}
32
38
33
39
impl < ' a > DefCollector < ' a > {
@@ -93,16 +99,15 @@ impl<'a> DefCollector<'a> {
93
99
self . parent_def = parent;
94
100
}
95
101
96
- fn visit_ast_const_integer ( & mut self , expr : & Expr ) {
97
- // Find the node which will be used after lowering.
98
- if let ExprKind :: Paren ( ref inner) = expr. node {
99
- return self . visit_ast_const_integer ( inner) ;
100
- }
101
-
102
- // FIXME(eddyb) Closures should have separate
103
- // function definition IDs and expression IDs.
104
- if let ExprKind :: Closure ( ..) = expr. node {
105
- return ;
102
+ pub fn visit_ast_const_integer ( & mut self , expr : & Expr ) {
103
+ match expr. node {
104
+ // Find the node which will be used after lowering.
105
+ ExprKind :: Paren ( ref inner) => return self . visit_ast_const_integer ( inner) ,
106
+ ExprKind :: Mac ( ..) => return self . visit_macro_invoc ( expr. id , true ) ,
107
+ // FIXME(eddyb) Closures should have separate
108
+ // function definition IDs and expression IDs.
109
+ ExprKind :: Closure ( ..) => return ,
110
+ _ => { }
106
111
}
107
112
108
113
self . create_def ( expr. id , DefPathData :: Initializer ) ;
@@ -118,9 +123,13 @@ impl<'a> DefCollector<'a> {
118
123
self . create_def ( expr. id , DefPathData :: Initializer ) ;
119
124
}
120
125
121
- fn visit_macro_invoc ( & mut self , id : NodeId ) {
126
+ fn visit_macro_invoc ( & mut self , id : NodeId , const_integer : bool ) {
122
127
if let Some ( ref mut visit) = self . visit_macro_invoc {
123
- visit ( id, self . parent_def . unwrap ( ) ) ;
128
+ visit ( MacroInvocationData {
129
+ id : id,
130
+ const_integer : const_integer,
131
+ def_index : self . parent_def . unwrap ( ) ,
132
+ } )
124
133
}
125
134
}
126
135
}
@@ -144,7 +153,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
144
153
ItemKind :: Static ( ..) | ItemKind :: Const ( ..) | ItemKind :: Fn ( ..) =>
145
154
DefPathData :: ValueNs ( i. ident . name . as_str ( ) ) ,
146
155
ItemKind :: Mac ( ..) if i. id == DUMMY_NODE_ID => return , // Scope placeholder
147
- ItemKind :: Mac ( ..) => return self . visit_macro_invoc ( i. id ) ,
156
+ ItemKind :: Mac ( ..) => return self . visit_macro_invoc ( i. id , false ) ,
148
157
ItemKind :: Use ( ..) => DefPathData :: Misc ,
149
158
} ;
150
159
let def = self . create_def ( i. id , def_data) ;
@@ -210,7 +219,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
210
219
TraitItemKind :: Method ( ..) | TraitItemKind :: Const ( ..) =>
211
220
DefPathData :: ValueNs ( ti. ident . name . as_str ( ) ) ,
212
221
TraitItemKind :: Type ( ..) => DefPathData :: TypeNs ( ti. ident . name . as_str ( ) ) ,
213
- TraitItemKind :: Macro ( ..) => return self . visit_macro_invoc ( ti. id ) ,
222
+ TraitItemKind :: Macro ( ..) => return self . visit_macro_invoc ( ti. id , false ) ,
214
223
} ;
215
224
216
225
let def = self . create_def ( ti. id , def_data) ;
@@ -228,7 +237,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
228
237
ImplItemKind :: Method ( ..) | ImplItemKind :: Const ( ..) =>
229
238
DefPathData :: ValueNs ( ii. ident . name . as_str ( ) ) ,
230
239
ImplItemKind :: Type ( ..) => DefPathData :: TypeNs ( ii. ident . name . as_str ( ) ) ,
231
- ImplItemKind :: Macro ( ..) => return self . visit_macro_invoc ( ii. id ) ,
240
+ ImplItemKind :: Macro ( ..) => return self . visit_macro_invoc ( ii. id , false ) ,
232
241
} ;
233
242
234
243
let def = self . create_def ( ii. id , def_data) ;
@@ -245,7 +254,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
245
254
let parent_def = self . parent_def ;
246
255
247
256
match pat. node {
248
- PatKind :: Mac ( ..) => return self . visit_macro_invoc ( pat. id ) ,
257
+ PatKind :: Mac ( ..) => return self . visit_macro_invoc ( pat. id , false ) ,
249
258
PatKind :: Ident ( _, id, _) => {
250
259
let def = self . create_def ( pat. id , DefPathData :: Binding ( id. node . name . as_str ( ) ) ) ;
251
260
self . parent_def = Some ( def) ;
@@ -261,7 +270,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
261
270
let parent_def = self . parent_def ;
262
271
263
272
match expr. node {
264
- ExprKind :: Mac ( ..) => return self . visit_macro_invoc ( expr. id ) ,
273
+ ExprKind :: Mac ( ..) => return self . visit_macro_invoc ( expr. id , false ) ,
265
274
ExprKind :: Repeat ( _, ref count) => self . visit_ast_const_integer ( count) ,
266
275
ExprKind :: Closure ( ..) => {
267
276
let def = self . create_def ( expr. id , DefPathData :: ClosureExpr ) ;
@@ -276,7 +285,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
276
285
277
286
fn visit_ty ( & mut self , ty : & Ty ) {
278
287
match ty. node {
279
- TyKind :: Mac ( ..) => return self . visit_macro_invoc ( ty. id ) ,
288
+ TyKind :: Mac ( ..) => return self . visit_macro_invoc ( ty. id , false ) ,
280
289
TyKind :: FixedLengthVec ( _, ref length) => self . visit_ast_const_integer ( length) ,
281
290
TyKind :: ImplTrait ( ..) => {
282
291
self . create_def ( ty. id , DefPathData :: ImplTrait ) ;
@@ -296,7 +305,7 @@ impl<'a> visit::Visitor for DefCollector<'a> {
296
305
297
306
fn visit_stmt ( & mut self , stmt : & Stmt ) {
298
307
match stmt. node {
299
- StmtKind :: Mac ( ..) => self . visit_macro_invoc ( stmt. id ) ,
308
+ StmtKind :: Mac ( ..) => self . visit_macro_invoc ( stmt. id , false ) ,
300
309
_ => visit:: walk_stmt ( self , stmt) ,
301
310
}
302
311
}
0 commit comments