@@ -74,18 +74,19 @@ impl<'a> DefCollector<'a> {
74
74
self . parent_def = parent;
75
75
}
76
76
77
- pub fn visit_const_expr ( & mut self , expr : & Expr ) {
77
+ pub fn visit_const_expr ( & mut self , expr : & Expr ) -> Option < DefIndex > {
78
78
match expr. node {
79
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 ) ,
80
+ ExprKind :: Paren ( ref inner) => self . visit_const_expr ( inner) ,
81
+ ExprKind :: Mac ( ..) => {
82
+ self . visit_macro_invoc ( expr. id , true ) ;
83
+ None
84
+ }
82
85
// FIXME(eddyb) Closures should have separate
83
86
// function definition IDs and expression IDs.
84
- ExprKind :: Closure ( ..) => return ,
85
- _ => { }
87
+ ExprKind :: Closure ( ..) => None ,
88
+ _ => Some ( self . create_def ( expr . id , DefPathData :: Initializer , REGULAR_SPACE , expr . span ) )
86
89
}
87
-
88
- self . create_def ( expr. id , DefPathData :: Initializer , REGULAR_SPACE , expr. span ) ;
89
90
}
90
91
91
92
fn visit_macro_invoc ( & mut self , id : NodeId , const_expr : bool ) {
@@ -268,18 +269,17 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
268
269
fn visit_expr ( & mut self , expr : & ' a Expr ) {
269
270
let parent_def = self . parent_def ;
270
271
271
- match expr. node {
272
+ self . parent_def = match expr. node {
272
273
ExprKind :: Mac ( ..) => return self . visit_macro_invoc ( expr. id , false ) ,
273
274
ExprKind :: Repeat ( _, ref count) => self . visit_const_expr ( count) ,
274
275
ExprKind :: Closure ( ..) => {
275
- let def = self . create_def ( expr. id ,
276
- DefPathData :: ClosureExpr ,
277
- REGULAR_SPACE ,
278
- expr. span ) ;
279
- self . parent_def = Some ( def) ;
276
+ Some ( self . create_def ( expr. id ,
277
+ DefPathData :: ClosureExpr ,
278
+ REGULAR_SPACE ,
279
+ expr. span ) )
280
280
}
281
- _ => { }
282
- }
281
+ _ => None
282
+ } . or ( self . parent_def ) ;
283
283
284
284
visit:: walk_expr ( self , expr) ;
285
285
self . parent_def = parent_def;
@@ -288,11 +288,15 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
288
288
fn visit_ty ( & mut self , ty : & ' a Ty ) {
289
289
match ty. node {
290
290
TyKind :: Mac ( ..) => return self . visit_macro_invoc ( ty. id , false ) ,
291
- TyKind :: Array ( _, ref length) => self . visit_const_expr ( length) ,
291
+ TyKind :: Array ( _, ref length) => {
292
+ self . visit_const_expr ( length) ;
293
+ }
292
294
TyKind :: ImplTrait ( ..) => {
293
295
self . create_def ( ty. id , DefPathData :: ImplTrait , REGULAR_SPACE , ty. span ) ;
294
296
}
295
- TyKind :: Typeof ( ref expr) => self . visit_const_expr ( expr) ,
297
+ TyKind :: Typeof ( ref expr) => {
298
+ self . visit_const_expr ( expr) ;
299
+ }
296
300
_ => { }
297
301
}
298
302
visit:: walk_ty ( self , ty) ;
0 commit comments