@@ -33,7 +33,6 @@ pub struct DefCollector<'a> {
3333pub struct MacroInvocationData {
3434 pub mark : Mark ,
3535 pub def_index : DefIndex ,
36- pub const_expr : bool ,
3736}
3837
3938impl < ' a > DefCollector < ' a > {
@@ -74,25 +73,10 @@ impl<'a> DefCollector<'a> {
7473 self . parent_def = parent;
7574 }
7675
77- pub fn visit_const_expr ( & mut self , expr : & Expr ) {
78- match expr. node {
79- // Find the node which will be used after lowering.
80- ExprKind :: Paren ( ref inner) => return self . visit_const_expr ( inner) ,
81- ExprKind :: Mac ( ..) => return self . visit_macro_invoc ( expr. id , true ) ,
82- // FIXME(eddyb) Closures should have separate
83- // function definition IDs and expression IDs.
84- ExprKind :: Closure ( ..) => return ,
85- _ => { }
86- }
87-
88- self . create_def ( expr. id , DefPathData :: Initializer , REGULAR_SPACE , expr. span ) ;
89- }
90-
91- fn visit_macro_invoc ( & mut self , id : NodeId , const_expr : bool ) {
76+ fn visit_macro_invoc ( & mut self , id : NodeId ) {
9277 if let Some ( ref mut visit) = self . visit_macro_invoc {
9378 visit ( MacroInvocationData {
9479 mark : id. placeholder_to_mark ( ) ,
95- const_expr,
9680 def_index : self . parent_def . unwrap ( ) ,
9781 } )
9882 }
@@ -119,7 +103,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
119103 ItemKind :: Static ( ..) | ItemKind :: Const ( ..) | ItemKind :: Fn ( ..) =>
120104 DefPathData :: ValueNs ( i. ident . name . as_interned_str ( ) ) ,
121105 ItemKind :: MacroDef ( ..) => DefPathData :: MacroDef ( i. ident . name . as_interned_str ( ) ) ,
122- ItemKind :: Mac ( ..) => return self . visit_macro_invoc ( i. id , false ) ,
106+ ItemKind :: Mac ( ..) => return self . visit_macro_invoc ( i. id ) ,
123107 ItemKind :: GlobalAsm ( ..) => DefPathData :: Misc ,
124108 ItemKind :: Use ( ..) => {
125109 return visit:: walk_item ( self , i) ;
@@ -129,30 +113,6 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
129113
130114 self . with_parent ( def, |this| {
131115 match i. node {
132- ItemKind :: Enum ( ref enum_definition, _) => {
133- for v in & enum_definition. variants {
134- let variant_def_index =
135- this. create_def ( v. node . data . id ( ) ,
136- DefPathData :: EnumVariant ( v. node . ident
137- . name . as_interned_str ( ) ) ,
138- REGULAR_SPACE ,
139- v. span ) ;
140- this. with_parent ( variant_def_index, |this| {
141- for ( index, field) in v. node . data . fields ( ) . iter ( ) . enumerate ( ) {
142- let name = field. ident . map ( |ident| ident. name )
143- . unwrap_or_else ( || Symbol :: intern ( & index. to_string ( ) ) ) ;
144- this. create_def ( field. id ,
145- DefPathData :: Field ( name. as_interned_str ( ) ) ,
146- REGULAR_SPACE ,
147- field. span ) ;
148- }
149-
150- if let Some ( ref expr) = v. node . disr_expr {
151- this. visit_const_expr ( expr) ;
152- }
153- } ) ;
154- }
155- }
156116 ItemKind :: Struct ( ref struct_def, _) | ItemKind :: Union ( ref struct_def, _) => {
157117 // If this is a tuple-like struct, register the constructor.
158118 if !struct_def. is_struct ( ) {
@@ -161,15 +121,6 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
161121 REGULAR_SPACE ,
162122 i. span ) ;
163123 }
164-
165- for ( index, field) in struct_def. fields ( ) . iter ( ) . enumerate ( ) {
166- let name = field. ident . map ( |ident| ident. name )
167- . unwrap_or_else ( || Symbol :: intern ( & index. to_string ( ) ) ) ;
168- this. create_def ( field. id ,
169- DefPathData :: Field ( name. as_interned_str ( ) ) ,
170- REGULAR_SPACE ,
171- field. span ) ;
172- }
173124 }
174125 _ => { }
175126 }
@@ -184,7 +135,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
184135
185136 fn visit_foreign_item ( & mut self , foreign_item : & ' a ForeignItem ) {
186137 if let ForeignItemKind :: Macro ( _) = foreign_item. node {
187- return self . visit_macro_invoc ( foreign_item. id , false ) ;
138+ return self . visit_macro_invoc ( foreign_item. id ) ;
188139 }
189140
190141 let def = self . create_def ( foreign_item. id ,
@@ -197,6 +148,28 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
197148 } ) ;
198149 }
199150
151+ fn visit_variant ( & mut self , v : & ' a Variant , g : & ' a Generics , item_id : NodeId ) {
152+ let def = self . create_def ( v. node . data . id ( ) ,
153+ DefPathData :: EnumVariant ( v. node . ident
154+ . name . as_interned_str ( ) ) ,
155+ REGULAR_SPACE ,
156+ v. span ) ;
157+ self . with_parent ( def, |this| visit:: walk_variant ( this, v, g, item_id) ) ;
158+ }
159+
160+ fn visit_variant_data ( & mut self , data : & ' a VariantData , _: Ident ,
161+ _: & ' a Generics , _: NodeId , _: Span ) {
162+ for ( index, field) in data. fields ( ) . iter ( ) . enumerate ( ) {
163+ let name = field. ident . map ( |ident| ident. name )
164+ . unwrap_or_else ( || Symbol :: intern ( & index. to_string ( ) ) ) ;
165+ let def = self . create_def ( field. id ,
166+ DefPathData :: Field ( name. as_interned_str ( ) ) ,
167+ REGULAR_SPACE ,
168+ field. span ) ;
169+ self . with_parent ( def, |this| this. visit_struct_field ( field) ) ;
170+ }
171+ }
172+
200173 fn visit_generic_param ( & mut self , param : & ' a GenericParam ) {
201174 match * param {
202175 GenericParam :: Lifetime ( ref lifetime_def) => {
@@ -227,50 +200,45 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
227200 TraitItemKind :: Type ( ..) => {
228201 DefPathData :: AssocTypeInTrait ( ti. ident . name . as_interned_str ( ) )
229202 } ,
230- TraitItemKind :: Macro ( ..) => return self . visit_macro_invoc ( ti. id , false ) ,
203+ TraitItemKind :: Macro ( ..) => return self . visit_macro_invoc ( ti. id ) ,
231204 } ;
232205
233206 let def = self . create_def ( ti. id , def_data, ITEM_LIKE_SPACE , ti. span ) ;
234- self . with_parent ( def, |this| {
235- if let TraitItemKind :: Const ( _, Some ( ref expr) ) = ti. node {
236- this. visit_const_expr ( expr) ;
237- }
238-
239- visit:: walk_trait_item ( this, ti) ;
240- } ) ;
207+ self . with_parent ( def, |this| visit:: walk_trait_item ( this, ti) ) ;
241208 }
242209
243210 fn visit_impl_item ( & mut self , ii : & ' a ImplItem ) {
244211 let def_data = match ii. node {
245212 ImplItemKind :: Method ( ..) | ImplItemKind :: Const ( ..) =>
246213 DefPathData :: ValueNs ( ii. ident . name . as_interned_str ( ) ) ,
247214 ImplItemKind :: Type ( ..) => DefPathData :: AssocTypeInImpl ( ii. ident . name . as_interned_str ( ) ) ,
248- ImplItemKind :: Macro ( ..) => return self . visit_macro_invoc ( ii. id , false ) ,
215+ ImplItemKind :: Macro ( ..) => return self . visit_macro_invoc ( ii. id ) ,
249216 } ;
250217
251218 let def = self . create_def ( ii. id , def_data, ITEM_LIKE_SPACE , ii. span ) ;
252- self . with_parent ( def, |this| {
253- if let ImplItemKind :: Const ( _, ref expr) = ii. node {
254- this. visit_const_expr ( expr) ;
255- }
256-
257- visit:: walk_impl_item ( this, ii) ;
258- } ) ;
219+ self . with_parent ( def, |this| visit:: walk_impl_item ( this, ii) ) ;
259220 }
260221
261222 fn visit_pat ( & mut self , pat : & ' a Pat ) {
262223 match pat. node {
263- PatKind :: Mac ( ..) => return self . visit_macro_invoc ( pat. id , false ) ,
224+ PatKind :: Mac ( ..) => return self . visit_macro_invoc ( pat. id ) ,
264225 _ => visit:: walk_pat ( self , pat) ,
265226 }
266227 }
267228
229+ fn visit_anon_const ( & mut self , constant : & ' a AnonConst ) {
230+ let def = self . create_def ( constant. id ,
231+ DefPathData :: AnonConst ,
232+ REGULAR_SPACE ,
233+ constant. value . span ) ;
234+ self . with_parent ( def, |this| visit:: walk_anon_const ( this, constant) ) ;
235+ }
236+
268237 fn visit_expr ( & mut self , expr : & ' a Expr ) {
269238 let parent_def = self . parent_def ;
270239
271240 match expr. node {
272- ExprKind :: Mac ( ..) => return self . visit_macro_invoc ( expr. id , false ) ,
273- ExprKind :: Repeat ( _, ref count) => self . visit_const_expr ( count) ,
241+ ExprKind :: Mac ( ..) => return self . visit_macro_invoc ( expr. id ) ,
274242 ExprKind :: Closure ( ..) => {
275243 let def = self . create_def ( expr. id ,
276244 DefPathData :: ClosureExpr ,
@@ -287,20 +255,18 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
287255
288256 fn visit_ty ( & mut self , ty : & ' a Ty ) {
289257 match ty. node {
290- TyKind :: Mac ( ..) => return self . visit_macro_invoc ( ty. id , false ) ,
291- TyKind :: Array ( _, ref length) => self . visit_const_expr ( length) ,
258+ TyKind :: Mac ( ..) => return self . visit_macro_invoc ( ty. id ) ,
292259 TyKind :: ImplTrait ( ..) => {
293260 self . create_def ( ty. id , DefPathData :: ImplTrait , REGULAR_SPACE , ty. span ) ;
294261 }
295- TyKind :: Typeof ( ref expr) => self . visit_const_expr ( expr) ,
296262 _ => { }
297263 }
298264 visit:: walk_ty ( self , ty) ;
299265 }
300266
301267 fn visit_stmt ( & mut self , stmt : & ' a Stmt ) {
302268 match stmt. node {
303- StmtKind :: Mac ( ..) => self . visit_macro_invoc ( stmt. id , false ) ,
269+ StmtKind :: Mac ( ..) => self . visit_macro_invoc ( stmt. id ) ,
304270 _ => visit:: walk_stmt ( self , stmt) ,
305271 }
306272 }
@@ -310,7 +276,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
310276 match nt. 0 {
311277 token:: NtExpr ( ref expr) => {
312278 if let ExprKind :: Mac ( ..) = expr. node {
313- self . visit_macro_invoc ( expr. id , false ) ;
279+ self . visit_macro_invoc ( expr. id ) ;
314280 }
315281 }
316282 _ => { }
0 commit comments