@@ -194,7 +194,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
194
194
qualname : qualname,
195
195
declaration : None ,
196
196
span : sub_span. unwrap ( ) ,
197
- scope : self . tcx . map . get_enclosing_scope ( item. id ) . unwrap_or ( 0 ) ,
197
+ scope : self . enclosing_scope ( item. id ) ,
198
198
} )
199
199
}
200
200
ast:: ItemStatic ( ref typ, mt, ref expr) => {
@@ -213,7 +213,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
213
213
name : get_ident ( item. ident ) . to_string ( ) ,
214
214
qualname : qualname,
215
215
span : sub_span. unwrap ( ) ,
216
- scope : self . tcx . map . get_enclosing_scope ( item. id ) . unwrap_or ( 0 ) ,
216
+ scope : self . enclosing_scope ( item. id ) ,
217
217
value : value,
218
218
type_value : ty_to_string ( & typ) ,
219
219
} )
@@ -227,7 +227,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
227
227
name : get_ident ( item. ident ) . to_string ( ) ,
228
228
qualname : qualname,
229
229
span : sub_span. unwrap ( ) ,
230
- scope : self . tcx . map . get_enclosing_scope ( item. id ) . unwrap_or ( 0 ) ,
230
+ scope : selfenclosing_scope ( item. id ) ,
231
231
value : self . span_utils . snippet ( expr. span ) ,
232
232
type_value : ty_to_string ( & typ) ,
233
233
} )
@@ -245,7 +245,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
245
245
name : get_ident ( item. ident ) . to_string ( ) ,
246
246
qualname : qualname,
247
247
span : sub_span. unwrap ( ) ,
248
- scope : self . tcx . map . get_enclosing_scope ( item. id ) . unwrap_or ( 0 ) ,
248
+ scope : self . enclosing_scope ( item. id ) ,
249
249
filename : filename,
250
250
} )
251
251
} ,
@@ -259,14 +259,14 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
259
259
value : val,
260
260
span : sub_span. unwrap ( ) ,
261
261
qualname : enum_name,
262
- scope : self . tcx . map . get_enclosing_scope ( item. id ) . unwrap_or ( 0 ) ,
262
+ scope : self . enclosing_scope ( item. id ) ,
263
263
} )
264
264
} ,
265
265
ast:: ItemImpl ( _, _, _, ref trait_ref, ref typ, _) => {
266
266
let mut type_data = None ;
267
267
let sub_span;
268
268
269
- let parent = self . tcx . map . get_enclosing_scope ( item. id ) . unwrap_or ( 0 ) ;
269
+ let parent = self . enclosing_scope ( item. id ) ;
270
270
271
271
match typ. node {
272
272
// Common case impl for a struct or something basic.
@@ -303,14 +303,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
303
303
}
304
304
}
305
305
306
- // FIXME: we ought to be able to get the parent id ourselves, but we can't
307
- // for now.
308
- pub fn get_field_data ( & self , field : & ast:: StructField , parent : NodeId ) -> Option < Data > {
306
+ pub fn get_field_data ( & self , field : & ast:: StructField , scope : NodeId ) -> Option < Data > {
309
307
match field. node . kind {
310
308
ast:: NamedField ( ident, _) => {
311
309
let name = get_ident ( ident) ;
312
310
let qualname = format ! ( "::{}::{}" ,
313
- self . tcx. map. path_to_string( parent ) ,
311
+ self . tcx. map. path_to_string( scope ) ,
314
312
name) ;
315
313
let typ = self . tcx . node_types ( ) . get ( & field. node . id ) . unwrap ( )
316
314
. to_string ( ) ;
@@ -320,7 +318,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
320
318
name : get_ident ( ident) . to_string ( ) ,
321
319
qualname : qualname,
322
320
span : sub_span. unwrap ( ) ,
323
- scope : parent ,
321
+ scope : scope ,
324
322
value : "" . to_owned ( ) ,
325
323
type_value : typ,
326
324
} ) )
@@ -329,8 +327,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
329
327
}
330
328
}
331
329
332
- // FIXME: we ought to be able to get the parent id ourselves, but we can't
333
- // for now.
334
330
pub fn get_trait_ref_data ( & self ,
335
331
trait_ref : & ast:: TraitRef ,
336
332
parent : NodeId )
@@ -359,7 +355,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
359
355
return Some ( Data :: VariableRefData ( VariableRefData {
360
356
name : get_ident ( ident. node ) . to_string ( ) ,
361
357
span : sub_span. unwrap ( ) ,
362
- scope : self . tcx . map . get_enclosing_scope ( expr. id ) . unwrap_or ( 0 ) ,
358
+ scope : self . enclosing_scope ( expr. id ) ,
363
359
ref_id : f. id ,
364
360
} ) ) ;
365
361
}
@@ -382,7 +378,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
382
378
let sub_span = self . span_utils . span_for_last_ident ( path. span ) ;
383
379
Some ( Data :: TypeRefData ( TypeRefData {
384
380
span : sub_span. unwrap ( ) ,
385
- scope : self . tcx . map . get_enclosing_scope ( expr. id ) . unwrap_or ( 0 ) ,
381
+ scope : self . enclosing_scope ( expr. id ) ,
386
382
ref_id : def_id,
387
383
} ) )
388
384
}
@@ -402,7 +398,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
402
398
ty:: TraitContainer ( _) => ( None , Some ( method_id) )
403
399
} ;
404
400
let sub_span = self . span_utils . sub_span_for_meth_name ( expr. span ) ;
405
- let parent = self . tcx . map . get_enclosing_scope ( expr. id ) . unwrap_or ( 0 ) ;
401
+ let parent = self . enclosing_scope ( expr. id ) ;
406
402
Some ( Data :: MethodCallData ( MethodCallData {
407
403
span : sub_span. unwrap ( ) ,
408
404
scope : parent,
@@ -441,15 +437,15 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
441
437
Data :: VariableRefData ( VariableRefData {
442
438
name : self . span_utils . snippet ( sub_span. unwrap ( ) ) ,
443
439
span : sub_span. unwrap ( ) ,
444
- scope : self . tcx . map . get_enclosing_scope ( id) . unwrap_or ( 0 ) ,
440
+ scope : self . enclosing_scope ( id) ,
445
441
ref_id : def. def_id ( ) ,
446
442
} )
447
443
}
448
444
def:: DefStruct ( def_id) | def:: DefTy ( def_id, _) => {
449
445
Data :: TypeRefData ( TypeRefData {
450
446
span : sub_span. unwrap ( ) ,
451
447
ref_id : def_id,
452
- scope : self . tcx . map . get_enclosing_scope ( id) . unwrap_or ( 0 ) ,
448
+ scope : self . enclosing_scope ( id) ,
453
449
} )
454
450
}
455
451
def:: DefMethod ( decl_id, provenence) => {
@@ -484,7 +480,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
484
480
} ;
485
481
Data :: MethodCallData ( MethodCallData {
486
482
span : sub_span. unwrap ( ) ,
487
- scope : self . tcx . map . get_enclosing_scope ( id) . unwrap_or ( 0 ) ,
483
+ scope : self . enclosing_scope ( id) ,
488
484
ref_id : def_id,
489
485
decl_id : Some ( decl_id) ,
490
486
} )
@@ -493,7 +489,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
493
489
Data :: FunctionCallData ( FunctionCallData {
494
490
ref_id : def_id,
495
491
span : sub_span. unwrap ( ) ,
496
- scope : self . tcx . map . get_enclosing_scope ( id) . unwrap_or ( 0 ) ,
492
+ scope : self . enclosing_scope ( id) ,
497
493
} )
498
494
}
499
495
_ => self . tcx . sess . span_bug ( path. span ,
@@ -545,6 +541,10 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
545
541
}
546
542
}
547
543
544
+ #[ inline]
545
+ fn enclosing_scope ( & self , id : NodeId ) -> NodeId {
546
+ self . tcx . map . get_enclosing_scope ( id) . unwrap_or ( 0 )
547
+ }
548
548
}
549
549
550
550
// An AST visitor for collecting paths from patterns.
0 commit comments